public ActionResult Edit(DataBox model) { if (ModelState.IsValid) { if (RepoDataBox.IsBoxExist(model.IdDataTruck.Value, model.Id)) { ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang box, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataBox dbitem = RepoDataBox.FindByPK(model.Id); model.SetDb(dbitem); Context.DataBoxHistory dbitemHistory = new Context.DataBoxHistory(); model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbitem.DataBoxHistory.Add(dbitemHistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value); Context.DataTruckBoxHistory dbtruckHistory = new Context.DataTruckBoxHistory(); RepoDataBox.save(dbitem, UserPrincipal.id, dbitemHistory, dbtruckHistory); model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbtruck.DataTruckBoxHistory.Add(dbtruckHistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public ActionResult Add(DataBox model) { if (ModelState.IsValid) { if (RepoDataBox.IsBoxExist(model.IdDataTruck.Value)) { ModelState.AddModelError("IdDataTruck", "Truck sudah tepasang box, harap ganti dengan truck yang lain"); return(View("Form", model)); } Context.DataBox dbitem = new Context.DataBox(); model.SetDb(dbitem); //generate code dbitem.Urutan = RepoDataBox.getUrutan() + 1; dbitem.NoBox = RepoDataBox.generateCode(dbitem.Urutan); Context.DataBoxHistory dbitemHistory = new Context.DataBoxHistory(); model.SetDbHistory(dbitemHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); dbitemHistory.Vehicle = RepoDataTruck.FindByPK(model.IdDataTruck.Value).VehicleNo; dbitemHistory.NoBox = dbitem.NoBox; dbitemHistory.strKategori = model.IdKategori.HasValue ? RepoLookup.FindByPK(model.IdKategori.Value).Nama : ""; dbitemHistory.strType = model.IdType.HasValue ? RepoLookup.FindByPK(model.IdType.Value).Nama : ""; dbitem.DataBoxHistory.Add(dbitemHistory); Context.DataTruckBoxHistory dbtruckHistory = new Context.DataTruckBoxHistory(); model.SetDbTruckHistory(dbtruckHistory, UserPrincipal.firstname + " " + UserPrincipal.lastname); RepoDataBox.save(dbitem, UserPrincipal.id, dbitemHistory, dbtruckHistory); Context.DataTruck dbtruck = RepoDataTruck.FindByPK(model.IdDataTruck.Value); dbtruckHistory.Vehicle = dbtruck.VehicleNo; dbtruckHistory.NoBox = dbitem.NoBox; dbtruckHistory.strKategori = model.IdKategori.HasValue ? RepoLookup.FindByPK(model.IdKategori.Value).Nama : ""; dbtruckHistory.strType = model.IdType.HasValue ? RepoLookup.FindByPK(model.IdType.Value).Nama : ""; dbtruck.DataTruckBoxHistory.Add(dbtruckHistory); RepoDataTruck.save(dbtruck, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }