Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorApiController.cs @ 285:c8f378272407
#123: Patrocinadores de las vans.
author | juanjose.montesdeocaarbos |
---|---|
date | Sat, 31 Dec 2011 14:45:55 -0300 |
parents | |
children | 1408ac17cb64 |
comparison
equal
deleted
inserted
replaced
284:79942e030118 | 285:c8f378272407 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using System.Web; | |
5 using System.Web.Mvc; | |
6 using System.IO; | |
7 using AltNetHispano.Agendas.Domain; | |
8 using AltNetHispano.Agendas.Factories; | |
9 using AltNetHispano.Agendas.Web.Models; | |
10 | |
11 namespace AltNetHispano.Agendas.Web.Controllers | |
12 { | |
13 public class PatrocinadorApiController : Controller | |
14 { | |
15 private HttpServerUtilityBase _server; | |
16 | |
17 public HttpServerUtilityBase HttpServer | |
18 { | |
19 get | |
20 { | |
21 if (_server == null) | |
22 { | |
23 var httpServer = HttpContext.Server; | |
24 _server = httpServer; | |
25 } | |
26 | |
27 return _server; | |
28 } | |
29 } | |
30 | |
31 public PatrocinadorApiController() | |
32 { } | |
33 | |
34 public PatrocinadorApiController(HttpServerUtilityBase server) | |
35 { | |
36 _server = server; | |
37 } | |
38 | |
39 //[CustomAuthorize(Roles = Roles.Administrador)] | |
40 public PartialViewResult Nuevo() | |
41 { | |
42 var model = new PatrocinadorNewModel(); | |
43 return PartialView(model); | |
44 } | |
45 | |
46 [HttpPost] | |
47 //[CustomAuthorize(Roles = Roles.Administrador)] | |
48 public JsonResult Nuevo(PatrocinadorNewModel model) | |
49 { | |
50 if (ModelState.IsValid) | |
51 { | |
52 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); | |
53 if (patrocinadores.GetByNombre(model.Nombre) == null) | |
54 { | |
55 var tempLogoFile = Path.Combine(HttpServer.MapPath("~/App_Data"), | |
56 model.Nombre + | |
57 model.Logo.FileName.Substring(model.Logo.FileName.LastIndexOf("."))); | |
58 model.Logo.SaveAs(tempLogoFile); | |
59 var patrocinador = new Patrocinador(model.Nombre); | |
60 patrocinador.LoadLogo(tempLogoFile); | |
61 | |
62 patrocinadores.Save(patrocinador); | |
63 | |
64 return Json(new Resultado(true, string.Empty)); | |
65 } | |
66 return Json(new Resultado(false, "El patrocinador ya existe.")); | |
67 } | |
68 | |
69 return Json(new Resultado(false, string.Join(",", ModelState.Values))); | |
70 } | |
71 } | |
72 } |