public ActionResult Edit(Guid?id) { try { var pianoType = Db.PianoTypes.FirstOrDefault(x => x.Id == id); var model = new NewPianoTypeVm() { Id = pianoType.Id, Code = pianoType.Code, Type = pianoType.Type, }; return(PartialView("~/Views/PianoTypes/Add.cshtml", model)); } catch (Exception ex) { return(Json(new JsonResponse() { IsSucess = false, ErrorMessage = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Save(NewPianoTypeVm vm) { try { if (vm.Id == null) { PianoType pianoType = new PianoType() { Id = Guid.NewGuid(), Code = vm.Code, Type = vm.Type, CreatedAt = DateTime.Now, CreatedBy = LoggedInUser?.UserName }; Db.PianoTypes.Add(pianoType); } else { var pianoType = Db.PianoTypes.FirstOrDefault(x => x.Id == vm.Id); pianoType.Code = vm.Code; pianoType.Type = vm.Type; } Db.SaveChanges(); return(Json(new JsonResponse() { IsSucess = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new JsonResponse() { IsSucess = false, ErrorMessage = ex.Message }, JsonRequestBehavior.AllowGet)); } }