public void setDb(Context.JenisTrucks dbitem) { dbitem.Id = Id; dbitem.StrJenisTruck = StrJenisTruck; dbitem.GolTol = GolTol.Value; dbitem.Alias = Alias; dbitem.Biaya = Biaya.Value; dbitem.AcInterval = AcInterval.Value; }
public JenisTruck(Context.JenisTrucks dbitem) { Id = dbitem.Id; StrJenisTruck = dbitem.StrJenisTruck; GolTol = dbitem.GolTol; Alias = dbitem.Alias; Biaya = dbitem.Biaya; AcInterval = dbitem.AcInterval; }
public JsonResult Delete(int id) { ResponeModel response = new ResponeModel(true); Context.JenisTrucks dbItem = RepoJenisTruck.FindByPK(id); RepoJenisTruck.delete(dbItem, UserPrincipal.id); return(Json(response)); }
public ActionResult Edit(JenisTruck model) { if (ModelState.IsValid) { bool Isexist = RepoJenisTruck.IsExist(model.StrJenisTruck, model.Id); if (Isexist) { ModelState.AddModelError("StrJenisTruck", "Jenis Truck telah dipakai."); return(View("Form", model)); } Context.JenisTrucks dbitem = RepoJenisTruck.FindByPK(model.Id); model.setDb(dbitem); RepoJenisTruck.save(dbitem, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public ActionResult Add(JenisTruck model) { if (ModelState.IsValid) { bool Isexist = RepoJenisTruck.IsExist(model.StrJenisTruck); if (Isexist) { ModelState.AddModelError("StrJenisTruck", "Jenis Truck sudah ada."); return(View("Form", model)); } Context.JenisTrucks dbitem = new Context.JenisTrucks(); model.setDb(dbitem); RepoJenisTruck.save(dbitem, UserPrincipal.id); return(RedirectToAction("Index")); } return(View("Form", model)); }
public string UploadTruck(IEnumerable <HttpPostedFileBase> filesTruck) { ResponeModel response = new ResponeModel(); //algoritma if (filesTruck != null) { foreach (var file in filesTruck) { try { using (var package = new ExcelPackage(file.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++) { if (workSheet.Cells[rowIterator, 1].Value != null && workSheet.Cells[rowIterator, 2].Value != null && workSheet.Cells[rowIterator, 4].Value != null && workSheet.Cells[rowIterator, 5].Value != null) { int id = 0; int resId; if (workSheet.Cells[rowIterator, 6].Value != null) { if (int.TryParse(workSheet.Cells[rowIterator, 6].Value.ToString(), out resId)) { id = resId; } } Context.JenisTrucks dbitem = new Context.JenisTrucks(); try { if (id != 0) { dbitem = RepoJenisTruck.FindByPK(id); if (RepoJenisTruck.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString(), id)) { continue; } } else { if (RepoJenisTruck.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString())) { continue; } } dbitem.StrJenisTruck = workSheet.Cells[rowIterator, 1].Value.ToString(); dbitem.GolTol = int.Parse(workSheet.Cells[rowIterator, 2].Value.ToString()); dbitem.Alias = workSheet.Cells[rowIterator, 3].Value == null ? "" : workSheet.Cells[rowIterator, 3].Value.ToString(); dbitem.Biaya = decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString()); dbitem.AcInterval = int.Parse(workSheet.Cells[rowIterator, 5].Value.ToString()); RepoJenisTruck.save(dbitem, UserPrincipal.id); } catch (Exception) { } } } } response.Success = true; } catch (Exception e) { response.Success = false; response.Message = e.Message.ToString(); } } } return(new JavaScriptSerializer().Serialize(new { Response = response })); }