Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs @ 275:bf993f99cee3
Ticket #123: Patrocinadores de las vans.
author | juanjose.montesdeocaarbos |
---|---|
date | Wed, 14 Dec 2011 08:15:44 -0300 |
parents | |
children | 6f5ab71614d4 |
rev | line source |
---|---|
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
1 using System; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
2 using System.Collections.Generic; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
3 using System.IO; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
4 using System.Linq; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
5 using System.Web; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
6 using System.Web.Mvc; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
7 using AltNetHispano.Agendas.Domain; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
8 using AltNetHispano.Agendas.Factories; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
9 using AltNetHispano.Agendas.Web.Models; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
10 using AltNetHispano.Agendas.Web.Services; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
11 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
12 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
13 namespace AltNetHispano.Agendas.Web.Controllers |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
14 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
15 public class PatrocinadorController : Controller |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
16 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
17 private IHttpServer _server; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
18 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
19 public PatrocinadorController() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
20 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
21 _server = (IHttpServer)ControllerContext.HttpContext.Server; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
22 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
23 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
24 public PatrocinadorController(IHttpServer server) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
25 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
26 _server = server; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
27 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
28 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
29 public ActionResult GetLogo(string id) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
30 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
31 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
32 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
33 var patrocinador = patrocinadores.Get(new Guid(id)); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
34 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
35 return File(patrocinador.Logo, "image/jpg"); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
36 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
37 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
38 public ActionResult Index() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
39 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
40 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
41 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
42 var model = new PatrocinadorIndexModel |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
43 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
44 Items = from p in patrocinadores.GetAll() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
45 select new PatrocinadorDto |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
46 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
47 Id = p.Id, |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
48 Nombre = p.Nombre |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
49 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
50 }; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
51 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
52 return View(model); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
53 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
54 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
55 [CustomAuthorize(Roles = Roles.Administrador)] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
56 public ActionResult Nuevo() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
57 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
58 var model = new PatrocinadorNewModel(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
59 return View("DefaultEditor", model); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
60 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
61 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
62 [HttpPost] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
63 [CustomAuthorize(Roles = Roles.Administrador)] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
64 public ActionResult Nuevo(PatrocinadorNewModel model) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
65 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
66 if (ModelState.IsValid) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
67 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
68 var tempLogoFile = Path.Combine(_server.MapPath("~/App_Data"), model.Nombre + model.Logo.FileName.Substring(model.Logo.FileName.LastIndexOf("."))); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
69 model.Logo.SaveAs(tempLogoFile); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
70 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
71 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
72 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
73 var patrocinador = new Patrocinador(model.Nombre); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
74 patrocinador.LoadLogo(tempLogoFile); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
75 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
76 patrocinadores.Save(patrocinador); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
77 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
78 return RedirectToAction("Index"); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
79 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
80 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
81 return View("DefaultEditor", model); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
82 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
83 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
84 [CustomAuthorize(Roles = Roles.Administrador)] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
85 public ActionResult Modificar(int id) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
86 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
87 return View(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
88 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
89 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
90 [HttpPost] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
91 [CustomAuthorize(Roles = Roles.Administrador)] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
92 public ActionResult Modificar(int id, FormCollection collection) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
93 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
94 try |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
95 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
96 // TODO: Add update logic here |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
97 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
98 return RedirectToAction("Index"); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
99 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
100 catch |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
101 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
102 return View(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
103 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
104 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
105 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
106 [CustomAuthorize(Roles = Roles.Administrador)] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
107 public ActionResult Quitar(int id) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
108 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
109 return View(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
110 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
111 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
112 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
113 } |