Guest User

Untitled

a guest
Nov 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.99 KB | None | 0 0
  1. @model Dal.Paquete
  2.  
  3. @{
  4. ViewBag.Title = "Editar";
  5. Layout = "~/Views/Shared/_AdministratorLayout.cshtml";
  6. }
  7.  
  8.  
  9. <div class="row">
  10. <div class="col-md-12 sub-contenedor">
  11. <div class="row">
  12. <div class="col-md-4 "></div>
  13. <div class="col-md-4 divOpaco">
  14.  
  15. <div>
  16. <h1>Editar paquete</h1>
  17. @using (Html.BeginForm("Editar", "Paquete", FormMethod.Post, new { enctype = "multipart/form-data" }))
  18. {
  19. @Html.AntiForgeryToken()
  20. @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  21. @Html.HiddenFor(p => p.Id);
  22. <h4 class="fuenteBlanca">Nombre</h4>
  23.  
  24. @Html.TextBoxFor(p => p.Nombre);
  25. @Html.ValidationMessageFor(p => p.Nombre, "", new { @class = "text-danger" })
  26. <br />
  27. <h4 class="fuenteBlanca">Descripción</h4>
  28.  
  29. @Html.TextBoxFor(p => p.Descripcion);
  30. @Html.ValidationMessageFor(p => p.Descripcion, "", new { @class = "text-danger" })
  31. <br />
  32. <h4 class="fuenteBlanca">Foto</h4>
  33.  
  34. @Html.TextBoxFor(p => p.Foto, new { type = "file", Value = Model.Foto, Class = "valid"});
  35. @Html.ValidationMessageFor(p => p.Foto, "", new { @class = "text-danger" })
  36. <br />
  37. <h4 class="fuenteBlanca">Fecha de inicio</h4>
  38.  
  39. @Html.TextBoxFor(p => p.FechaInicio, new { type = "date", Value = Model.FechaInicio.ToString("yyyy-MM-dd") });
  40. @Html.ValidationMessageFor(p => p.FechaInicio, "", new { @class = "text-danger" })
  41. <br />
  42. <h4 class="fuenteBlanca">Fecha de fin</h4>
  43.  
  44. @Html.TextBoxFor(p => p.FechaFin, new { type = "date", Value = Model.FechaFin.ToString("yyyy-MM-dd") });
  45. @Html.ValidationMessageFor(p => p.FechaFin, "", new { @class = "text-danger" })
  46. <br />
  47. <h4 class="fuenteBlanca">Lugares disponibles</h4>
  48.  
  49. @Html.TextBoxFor(p => p.LugaresDisponibles);
  50. @Html.ValidationMessageFor(p => p.LugaresDisponibles, "", new { @class = "text-danger" })
  51. <br />
  52. <h4 class="fuenteBlanca">Precio por persona</h4>
  53.  
  54. @Html.TextBoxFor(p => p.PrecioPorPersona);
  55. @Html.ValidationMessageFor(p => p.PrecioPorPersona, "", new { @class = "text-danger" })
  56. <br />
  57. <h4 class="fuenteBlanca">Destacado</h4>
  58.  
  59. @Html.CheckBoxFor(p => p.Destacado);
  60. <br /> <br />
  61. <button type="submit" id="btnIngresar" name="btnIngresar" class="btn btn-success margenInf boton2">Crear</button>
  62. }
  63. </div>
  64. </div>
  65. </div>
  66. <div class="col-md-4 "></div>
  67. </div>
  68. </div>
  69.  
  70. public ActionResult Editar(int id)
  71. {
  72. if (Convert.ToBoolean(Session["EsAdmin"]))
  73. {
  74. using (var db = new TurismoAEGLContext())
  75. {
  76. Paquete paq = db.Paquete.Find(id);
  77. return View(paq);
  78. }
  79.  
  80. }
  81.  
  82. return RedirectToAction("Login", "Home");
  83. }
  84. [HttpPost]
  85. [ValidateAntiForgeryToken]
  86. public ActionResult Editar(PaqueteE p)
  87. {
  88. Paquete paqueteBD = LogicaPaquete.ObtenerPaquete().FirstOrDefault(pa => pa.Id == p.Id);
  89.  
  90. if (!ModelState.IsValid)
  91. return View();
  92. if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
  93. {
  94. if (!string.IsNullOrEmpty(p.Foto))
  95. {
  96. if (!string.IsNullOrEmpty(paqueteBD.Foto))
  97. {
  98. ImagenesUtility.Borrar(p.Foto);
  99. }
  100.  
  101. //creo un nombre significativo en este caso apellidonombre pero solo un caracter del nombre, ejemplo BatistutaG
  102. string nombreSignificativo = p.NombreSignificativoImagen;
  103. //Guardar Imagen
  104. string pathRelativoImagen = ImagenesUtility.Guardar(Request.Files[0], nombreSignificativo);
  105. p.Foto = pathRelativoImagen;
  106. }
  107. }
  108. LogicaPaquete.EditarPaquete(p);
  109.  
  110. return RedirectToAction("Listar", "Paquete");
  111. }
  112.  
  113. public partial class Paquete
  114. {
  115. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
  116. public Paquete()
  117. {
  118. this.Reserva = new HashSet<Reserva>();
  119. }
  120.  
  121. public int Id { get; set; }
  122. public string Nombre { get; set; }
  123. public string Descripcion { get; set; }
  124. public string Foto { get; set; }
  125. public System.DateTime FechaInicio { get; set; }
  126. public System.DateTime FechaFin { get; set; }
  127. public bool Destacado { get; set; }
  128. public Nullable<int> LugaresDisponibles { get; set; }
  129. public int PrecioPorPersona { get; set; }
  130.  
  131. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
  132. public virtual ICollection<Reserva> Reserva { get; set; }
  133. }
  134.  
  135. public class PaqueteE
  136. {
  137. public int Id { get; set; }
  138. [Required(ErrorMessage = "El nombre es requerido")]
  139. [StringLength(100, ErrorMessage = "El nombre no debe superar los 100 caracteres")]
  140. public string Nombre { get; set; }
  141. [Required(ErrorMessage = "La descripcion es requerida")]
  142. public string Descripcion { get; set; }
  143. [Required(ErrorMessage = "La foto es requerida")]
  144. public string Foto { get; set; }
  145. [Required(ErrorMessage = "La fecha de inicio es requerida")]
  146. [DataType(DataType.DateTime, ErrorMessage = "Fecha invalida")]
  147. [Display(Name = "Fecha de inicio")]
  148. public System.DateTime FechaInicio { get; set; }
  149. [Required(ErrorMessage = "La fecha de fin es requerida")]
  150. [DataType(DataType.DateTime, ErrorMessage = "Fecha invalida")]
  151. [Display(Name = "Fecha de fin")]
  152. public System.DateTime FechaFin { get; set; }
  153. public bool Destacado { get; set; }
  154. [Required]
  155. [Range(0, int.MaxValue, ErrorMessage = "Solo se aceptan valores positivos")]
  156. public Nullable<int> LugaresDisponibles { get; set; }
  157. [Required]
  158. [Range(0, int.MaxValue, ErrorMessage = "Solo se aceptan valores positivos")]
  159. public int PrecioPorPersona { get; set; }
  160.  
  161. public string NombreSignificativoImagen
  162. {
  163. get
  164. {
  165. //en caso de ambos null, devuelve "DescripcionNombre"
  166. return string.Format("{0}{1}", this.Descripcion ?? "Descripcion", this.Nombre ?? "Nombre");
  167. }
  168. }
  169. }
Add Comment
Please, Sign In to add comment