/// GET: Plaza/Edit/5 /// <author>Adonis Mora Angulo</author> /// <summary> /// Initialize the view to edit a plaza /// </summary> /// <param name="id">Plaza's id</param> /// <returns></returns> public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Plaza vPlaza = db.Plazas.Find(id); if (vPlaza == null) { return(HttpNotFound()); } var viewModel = new PlazaEditViewModel() { ID = vPlaza.ID, Code = vPlaza.Code, PlazaType = vPlaza.PlazaType, PlazaTypeList = new SelectList(new List <string>() { "Interna", "Externa" }), TimeType = vPlaza.TimeType, TimeTypeList = new SelectList(new List <string>() { "Completo", "Parcial" }), TotalHours = vPlaza.TotalHours.GetValueOrDefault(), EffectiveTime = vPlaza.EffectiveTime.GetValueOrDefault() }; return(View(viewModel)); }
public ActionResult Edit(PlazaEditViewModel viewModel) { if (ModelState.IsValid) { var vPlaza = db.Plazas.Find(viewModel.ID); vPlaza.Code = viewModel.Code; vPlaza.PlazaType = viewModel.PlazaType; vPlaza.TimeType = viewModel.TimeType; vPlaza.TotalHours = viewModel.TotalHours; vPlaza.EffectiveTime = viewModel.EffectiveTime; db.Entry(vPlaza).State = EntityState.Modified; db.SaveChanges(); TempData[TempDataMessageKeySuccess] = "Plaza editada exitosamente"; return(RedirectToAction("Index")); } return(View(viewModel)); }