Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @model Dal.Paquete
- @{
- ViewBag.Title = "Editar";
- Layout = "~/Views/Shared/_AdministratorLayout.cshtml";
- }
- <div class="row">
- <div class="col-md-12 sub-contenedor">
- <div class="row">
- <div class="col-md-4 "></div>
- <div class="col-md-4 divOpaco">
- <div>
- <h1>Editar paquete</h1>
- @using (Html.BeginForm("Editar", "Paquete", FormMethod.Post, new { enctype = "multipart/form-data" }))
- {
- @Html.AntiForgeryToken()
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- @Html.HiddenFor(p => p.Id);
- <h4 class="fuenteBlanca">Nombre</h4>
- @Html.TextBoxFor(p => p.Nombre);
- @Html.ValidationMessageFor(p => p.Nombre, "", new { @class = "text-danger" })
- <br />
- <h4 class="fuenteBlanca">Descripción</h4>
- @Html.TextBoxFor(p => p.Descripcion);
- @Html.ValidationMessageFor(p => p.Descripcion, "", new { @class = "text-danger" })
- <br />
- <h4 class="fuenteBlanca">Foto</h4>
- @Html.TextBoxFor(p => p.Foto, new { type = "file", Value = Model.Foto, Class = "valid"});
- @Html.ValidationMessageFor(p => p.Foto, "", new { @class = "text-danger" })
- <br />
- <h4 class="fuenteBlanca">Fecha de inicio</h4>
- @Html.TextBoxFor(p => p.FechaInicio, new { type = "date", Value = Model.FechaInicio.ToString("yyyy-MM-dd") });
- @Html.ValidationMessageFor(p => p.FechaInicio, "", new { @class = "text-danger" })
- <br />
- <h4 class="fuenteBlanca">Fecha de fin</h4>
- @Html.TextBoxFor(p => p.FechaFin, new { type = "date", Value = Model.FechaFin.ToString("yyyy-MM-dd") });
- @Html.ValidationMessageFor(p => p.FechaFin, "", new { @class = "text-danger" })
- <br />
- <h4 class="fuenteBlanca">Lugares disponibles</h4>
- @Html.TextBoxFor(p => p.LugaresDisponibles);
- @Html.ValidationMessageFor(p => p.LugaresDisponibles, "", new { @class = "text-danger" })
- <br />
- <h4 class="fuenteBlanca">Precio por persona</h4>
- @Html.TextBoxFor(p => p.PrecioPorPersona);
- @Html.ValidationMessageFor(p => p.PrecioPorPersona, "", new { @class = "text-danger" })
- <br />
- <h4 class="fuenteBlanca">Destacado</h4>
- @Html.CheckBoxFor(p => p.Destacado);
- <br /> <br />
- <button type="submit" id="btnIngresar" name="btnIngresar" class="btn btn-success margenInf boton2">Crear</button>
- }
- </div>
- </div>
- </div>
- <div class="col-md-4 "></div>
- </div>
- </div>
- public ActionResult Editar(int id)
- {
- if (Convert.ToBoolean(Session["EsAdmin"]))
- {
- using (var db = new TurismoAEGLContext())
- {
- Paquete paq = db.Paquete.Find(id);
- return View(paq);
- }
- }
- return RedirectToAction("Login", "Home");
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Editar(PaqueteE p)
- {
- Paquete paqueteBD = LogicaPaquete.ObtenerPaquete().FirstOrDefault(pa => pa.Id == p.Id);
- if (!ModelState.IsValid)
- return View();
- if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
- {
- if (!string.IsNullOrEmpty(p.Foto))
- {
- if (!string.IsNullOrEmpty(paqueteBD.Foto))
- {
- ImagenesUtility.Borrar(p.Foto);
- }
- //creo un nombre significativo en este caso apellidonombre pero solo un caracter del nombre, ejemplo BatistutaG
- string nombreSignificativo = p.NombreSignificativoImagen;
- //Guardar Imagen
- string pathRelativoImagen = ImagenesUtility.Guardar(Request.Files[0], nombreSignificativo);
- p.Foto = pathRelativoImagen;
- }
- }
- LogicaPaquete.EditarPaquete(p);
- return RedirectToAction("Listar", "Paquete");
- }
- public partial class Paquete
- {
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
- public Paquete()
- {
- this.Reserva = new HashSet<Reserva>();
- }
- public int Id { get; set; }
- public string Nombre { get; set; }
- public string Descripcion { get; set; }
- public string Foto { get; set; }
- public System.DateTime FechaInicio { get; set; }
- public System.DateTime FechaFin { get; set; }
- public bool Destacado { get; set; }
- public Nullable<int> LugaresDisponibles { get; set; }
- public int PrecioPorPersona { get; set; }
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
- public virtual ICollection<Reserva> Reserva { get; set; }
- }
- public class PaqueteE
- {
- public int Id { get; set; }
- [Required(ErrorMessage = "El nombre es requerido")]
- [StringLength(100, ErrorMessage = "El nombre no debe superar los 100 caracteres")]
- public string Nombre { get; set; }
- [Required(ErrorMessage = "La descripcion es requerida")]
- public string Descripcion { get; set; }
- [Required(ErrorMessage = "La foto es requerida")]
- public string Foto { get; set; }
- [Required(ErrorMessage = "La fecha de inicio es requerida")]
- [DataType(DataType.DateTime, ErrorMessage = "Fecha invalida")]
- [Display(Name = "Fecha de inicio")]
- public System.DateTime FechaInicio { get; set; }
- [Required(ErrorMessage = "La fecha de fin es requerida")]
- [DataType(DataType.DateTime, ErrorMessage = "Fecha invalida")]
- [Display(Name = "Fecha de fin")]
- public System.DateTime FechaFin { get; set; }
- public bool Destacado { get; set; }
- [Required]
- [Range(0, int.MaxValue, ErrorMessage = "Solo se aceptan valores positivos")]
- public Nullable<int> LugaresDisponibles { get; set; }
- [Required]
- [Range(0, int.MaxValue, ErrorMessage = "Solo se aceptan valores positivos")]
- public int PrecioPorPersona { get; set; }
- public string NombreSignificativoImagen
- {
- get
- {
- //en caso de ambos null, devuelve "DescripcionNombre"
- return string.Format("{0}{1}", this.Descripcion ?? "Descripcion", this.Nombre ?? "Nombre");
- }
- }
- }
Add Comment
Please, Sign In to add comment