annotate Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorApiController.cs @ 286:a8f7c41e3b47

#196: Patrocinadores, en el histórico de eventos.
author juanjose.montesdeocaarbos
date Mon, 02 Jan 2012 15:51:19 -0300
parents c8f378272407
children 1408ac17cb64
rev   line source
285
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
1 using System;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
2 using System.Collections.Generic;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
3 using System.Linq;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
4 using System.Web;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
5 using System.Web.Mvc;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
6 using System.IO;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
7 using AltNetHispano.Agendas.Domain;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
8 using AltNetHispano.Agendas.Factories;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
9 using AltNetHispano.Agendas.Web.Models;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
10
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
11 namespace AltNetHispano.Agendas.Web.Controllers
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
12 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
13 public class PatrocinadorApiController : Controller
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
14 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
15 private HttpServerUtilityBase _server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
16
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
17 public HttpServerUtilityBase HttpServer
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
18 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
19 get
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
20 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
21 if (_server == null)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
22 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
23 var httpServer = HttpContext.Server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
24 _server = httpServer;
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 return _server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
28 }
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()
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
32 { }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
33
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
34 public PatrocinadorApiController(HttpServerUtilityBase server)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
35 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
36 _server = server;
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
37 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
38
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
39 //[CustomAuthorize(Roles = Roles.Administrador)]
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
40 public PartialViewResult Nuevo()
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
41 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
42 var model = new PatrocinadorNewModel();
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
43 return PartialView(model);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
44 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
45
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
46 [HttpPost]
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
47 //[CustomAuthorize(Roles = Roles.Administrador)]
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
48 public JsonResult Nuevo(PatrocinadorNewModel model)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
49 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
50 if (ModelState.IsValid)
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 patrocinadores = AgendaFactory.GetPatrocinadorRepository();
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
53 if (patrocinadores.GetByNombre(model.Nombre) == null)
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
54 {
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
55 var tempLogoFile = Path.Combine(HttpServer.MapPath("~/App_Data"),
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
56 model.Nombre +
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
57 model.Logo.FileName.Substring(model.Logo.FileName.LastIndexOf(".")));
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
58 model.Logo.SaveAs(tempLogoFile);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
59 var patrocinador = new Patrocinador(model.Nombre);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
60 patrocinador.LoadLogo(tempLogoFile);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
61
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
62 patrocinadores.Save(patrocinador);
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
63
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
64 return Json(new Resultado(true, string.Empty));
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, "El patrocinador ya existe."));
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 return Json(new Resultado(false, string.Join(",", ModelState.Values)));
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
70 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
71 }
c8f378272407 #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff changeset
72 }