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