Mercurial > altnet-hispano
annotate Agendas/trunk/src/Agendas.Web/Controllers/PatrocinadorController.cs @ 302:11dddcc9a862 tip
Historico de Eventos, no muestra bien la Url del Patrocinador.
author | juanjose.montesdeocaarbos |
---|---|
date | Tue, 14 Aug 2012 21:54:30 -0300 |
parents | 48ab8788bd19 |
children |
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; |
295 | 3 using System.Drawing; |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
4 using System.IO; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
5 using System.Linq; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
6 using System.Web; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
7 using System.Web.Mvc; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
8 using AltNetHispano.Agendas.Domain; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
9 using AltNetHispano.Agendas.Factories; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
10 using AltNetHispano.Agendas.Web.Models; |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
11 using AltNetHispano.Agendas.Web.Services; |
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 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
14 namespace AltNetHispano.Agendas.Web.Controllers |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
15 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
16 public class PatrocinadorController : Controller |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
17 { |
278 | 18 private HttpServerUtilityBase _server; |
19 | |
20 public HttpServerUtilityBase HttpServer | |
21 { | |
22 get | |
23 { | |
24 if (_server == null) | |
25 { | |
26 var httpServer = HttpContext.Server; | |
27 _server = httpServer; | |
28 } | |
29 | |
30 return _server; | |
31 } | |
32 } | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
33 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
34 public PatrocinadorController() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
35 { |
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 |
278 | 38 public PatrocinadorController(HttpServerUtilityBase server) |
275
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 _server = server; |
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 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
43 public ActionResult GetLogo(string id) |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
44 { |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
45 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); |
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 var patrocinador = patrocinadores.Get(new Guid(id)); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
48 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
49 return File(patrocinador.Logo, "image/jpg"); |
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 public ActionResult Index() |
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 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
55 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
56 var model = new PatrocinadorIndexModel |
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 Items = from p in patrocinadores.GetAll() |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
59 select new PatrocinadorDto |
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 Id = p.Id, |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
296
diff
changeset
|
62 Nombre = p.Nombre, |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
296
diff
changeset
|
63 WebSite = p.WebSite |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
64 } |
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 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
67 return View(model); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
68 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
69 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
70 [CustomAuthorize(Roles = Roles.Administrador)] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
71 public ActionResult Nuevo() |
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 model = new PatrocinadorNewModel(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
74 return View("DefaultEditor", model); |
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 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
77 [HttpPost] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
78 [CustomAuthorize(Roles = Roles.Administrador)] |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
79 public ActionResult Nuevo(PatrocinadorNewModel model) |
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 if (ModelState.IsValid) |
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 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
84 |
278 | 85 if (patrocinadores.GetByNombre(model.Nombre) == null) |
86 { | |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
296
diff
changeset
|
87 var patrocinador = new Patrocinador(model.Nombre, model.WebSite); |
295 | 88 |
89 patrocinador.Logo = StreamToArray(model.Logo.InputStream); | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
90 |
278 | 91 patrocinadores.Save(patrocinador); |
92 | |
93 return RedirectToAction("Index"); | |
94 } | |
95 this.AddError("El patrocinador ya existe."); | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
96 } |
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 View("DefaultEditor", model); |
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 |
295 | 101 private static byte[] StreamToArray(Stream stream) |
102 { | |
103 var buffer = new byte[16*1024]; | |
104 using (var ms = new MemoryStream()) | |
105 { | |
106 int read; | |
107 while ((read = stream.Read(buffer, 0, buffer.Length)) > 0) | |
108 ms.Write(buffer, 0, read); | |
109 return ms.ToArray(); | |
110 } | |
111 } | |
112 | |
113 [CustomAuthorize(Roles = Roles.Administrador)] | |
278 | 114 public ActionResult Modificar(string id) |
115 { | |
116 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
117 |
278 | 118 var patrocinador = patrocinadores.GetById(id); |
119 if (patrocinador == null) | |
120 { | |
121 this.AddError("No se encontró el patrocinador que intenta modificar"); | |
122 return RedirectToAction("Index"); | |
123 } | |
279 | 124 var model = new PatrocinadorEditModel |
125 { | |
126 Id = new Guid(id).ToString(), | |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
296
diff
changeset
|
127 Nombre = patrocinador.Nombre, |
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
296
diff
changeset
|
128 WebSite = patrocinador.WebSite |
279 | 129 }; |
278 | 130 return View("DefaultEditor", model); |
131 } | |
132 | |
133 [HttpPost] | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
134 [CustomAuthorize(Roles = Roles.Administrador)] |
278 | 135 public ActionResult Modificar(PatrocinadorEditModel model) |
136 { | |
137 if (ModelState.IsValid) | |
138 { | |
139 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); | |
279 | 140 var patrocinador = patrocinadores.GetById(model.Id); |
141 if (patrocinador != null) | |
278 | 142 { |
279 | 143 patrocinador.Nombre = model.Nombre; |
300
48ab8788bd19
#200: Patrocinadores: Agregar link al sitio web.
juanjose.montesdeocaarbos
parents:
296
diff
changeset
|
144 patrocinador.WebSite = model.WebSite; |
296
1edd42d24711
Patrocinadores: Modificar sin persistir archivo en disco.
juanjose.montesdeocaarbos
parents:
295
diff
changeset
|
145 patrocinador.Logo = StreamToArray(model.Logo.InputStream); |
278 | 146 |
147 patrocinadores.Save(patrocinador); | |
148 | |
149 return RedirectToAction("Index"); | |
150 } | |
151 this.AddError("No se encuentra el patrocinador."); | |
152 } | |
153 return View("DefaultEditor", model); | |
154 } | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
155 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
156 [CustomAuthorize(Roles = Roles.Administrador)] |
279 | 157 public ActionResult Eliminar(string id) |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
158 { |
279 | 159 if (!string.IsNullOrWhiteSpace(id)) |
160 { | |
161 var patrocinadores = AgendaFactory.GetPatrocinadorRepository(); | |
162 var patrocinador = patrocinadores.GetById(id); | |
163 | |
164 patrocinadores.Delete(patrocinador); | |
165 } | |
166 return RedirectToAction("Index"); | |
167 } | |
275
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
168 |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
169 } |
bf993f99cee3
Ticket #123: Patrocinadores de las vans.
juanjose.montesdeocaarbos
parents:
diff
changeset
|
170 } |