annotate Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorApiController.cs @ 293:2cf7143586fe v1.1.0

Versión 1.1.0
author nelopauselli
date Fri, 17 Feb 2012 14:27:56 -0300
parents 1408ac17cb64
children 9bc60d166c8a
rev   line source
292
1408ac17cb64 Patrocinadores: Faltaba aplicar seguridad a la Api de Patrocinadores.
juanjose.montesdeocaarbos
parents: 285
diff changeset
1 using System.Web;
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
2 using System.Web.Mvc;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
3 using System.IO;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
4 using AltNetHispano.Agendas.Domain;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
5 using AltNetHispano.Agendas.Factories;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
6 using AltNetHispano.Agendas.Web.Models;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
7
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
8 namespace AltNetHispano.Agendas.Web.Controllers
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
9 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
10 public class PatrocinadorApiController : Controller
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
11 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
12 private HttpServerUtilityBase _server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
13
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
14 public HttpServerUtilityBase HttpServer
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
15 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
16 get
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
17 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
18 if (_server == null)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
19 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
20 var httpServer = HttpContext.Server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
21 _server = httpServer;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
22 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
23
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
24 return _server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
25 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
26 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
27
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
28 public PatrocinadorApiController()
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
29 { }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
30
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
31 public PatrocinadorApiController(HttpServerUtilityBase server)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
32 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
33 _server = server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
34 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
35
292
1408ac17cb64 Patrocinadores: Faltaba aplicar seguridad a la Api de Patrocinadores.
juanjose.montesdeocaarbos
parents: 285
diff changeset
36 [CustomAuthorize(Roles = Roles.Administrador)]
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
37 public PartialViewResult Nuevo()
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
38 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
39 var model = new PatrocinadorNewModel();
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
40 return PartialView(model);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
41 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
42
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
43 [HttpPost]
292
1408ac17cb64 Patrocinadores: Faltaba aplicar seguridad a la Api de Patrocinadores.
juanjose.montesdeocaarbos
parents: 285
diff changeset
44 [CustomAuthorize(Roles = Roles.Administrador)]
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
45 public JsonResult Nuevo(PatrocinadorNewModel model)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
46 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
47 if (ModelState.IsValid)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
48 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
49 var patrocinadores = AgendaFactory.GetPatrocinadorRepository();
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
50 if (patrocinadores.GetByNombre(model.Nombre) == null)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
51 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
52 var tempLogoFile = Path.Combine(HttpServer.MapPath("~/App_Data"),
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
53 model.Nombre +
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
54 model.Logo.FileName.Substring(model.Logo.FileName.LastIndexOf(".")));
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
55 model.Logo.SaveAs(tempLogoFile);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
56 var patrocinador = new Patrocinador(model.Nombre);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
57 patrocinador.LoadLogo(tempLogoFile);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
58
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
59 patrocinadores.Save(patrocinador);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
60
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
61 return Json(new Resultado(true, string.Empty));
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
62 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
63 return Json(new Resultado(false, "El patrocinador ya existe."));
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
64 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
65
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
66 return Json(new Resultado(false, string.Join(",", ModelState.Values)));
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
67 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
68 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
69 }