public ActionResult Edit(DataTruck model) { if (ModelState.IsValid) { if (RepoDataTruck.IsExist(model.VehicleNo, model.Id)) { ModelState.AddModelError("VehicleNo", "Vehicle No sudah terdaftar."); return(View("Form", model)); } Context.DataTruck dbitem = RepoDataTruck.FindByPK(model.Id); model.SetDb(dbitem); RepoDataTruck.save(dbitem, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public ActionResult Add(DataTruck model) { if (ModelState.IsValid) { if (RepoDataTruck.IsExist(model.VehicleNo)) { ModelState.AddModelError("VehicleNo", "Vehicle No sudah terdaftar."); return(View("Form", model)); } Context.DataTruck dbitem = new Context.DataTruck(); model.SetDb(dbitem); //generate code dbitem.urutan = RepoDataTruck.getUrutan() + 1; dbitem.NoTruck = RepoDataTruck.generateCode(dbitem.urutan); RepoDataTruck.save(dbitem, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }