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 void SetDbTruckHistory(Context.DataTruckBoxHistory dbitem, string user) { dbitem.NoBox = NoBox; dbitem.Vehicle = VehicleNo; dbitem.Karoseri = Karoseri; dbitem.Tahun = Tahun; dbitem.strType = StrType; dbitem.strKategori = StrKategori; dbitem.Lantai = Lantai; dbitem.Dinding = Dinding; dbitem.PintuSamping = PintuSamping; dbitem.Sekat = Sekat; dbitem.garansiStr = garansiStr; dbitem.garansiEnd = garansiEnd; dbitem.asuransiStr = asuransiStr; dbitem.asuransiEnd = asuransiEnd; dbitem.tglPasang = tglPasang; dbitem.Tanggal = DateTime.Now; dbitem.username = user; if (ListLantai.Count() > 0) { foreach (LantaiModel item in ListLantai) { if (item.IsSelect) { dbitem.Lantai = dbitem.Lantai + ", " + item.StrLantai; } } } if (ListDinding.Count() > 0) { foreach (DindingModel item in ListDinding) { if (item.IsSelect) { dbitem.Dinding = dbitem.Dinding + ", " + item.StrDinding; } } } }
public DataBox(Context.DataTruckBoxHistory dbitem) { Id = dbitem.Id; NoBox = dbitem.NoBox; VehicleNo = dbitem.Vehicle; Karoseri = dbitem.Karoseri; Tahun = dbitem.Tahun; StrType = dbitem.strType; StrKategori = dbitem.strKategori; Lantai = dbitem.Lantai; Dinding = dbitem.Dinding; PintuSamping = dbitem.PintuSamping; Sekat = dbitem.Sekat; garansiStr = dbitem.garansiStr; garansiEnd = dbitem.garansiEnd; asuransiStr = dbitem.asuransiStr; asuransiEnd = dbitem.asuransiEnd; tglPasang = dbitem.tglPasang; Tanggal = dbitem.Tanggal; username = dbitem.username; }
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)); }