public void setDb(Context.JnsTols dbitem) { dbitem.Id = Id; dbitem.NamaTol = NamaTol; dbitem.GolonganTol1 = GolonganTol1.Value; dbitem.GolonganTol2 = GolonganTol2.Value; dbitem.GolonganTol3 = GolonganTol3.Value; dbitem.GolonganTol4 = GolonganTol4.Value; dbitem.Keterangan = Keterangan; }
public JnsTol(Context.JnsTols dbitem) { Id = dbitem.Id; NamaTol = dbitem.NamaTol; GolonganTol1 = dbitem.GolonganTol1; GolonganTol2 = dbitem.GolonganTol2; GolonganTol3 = dbitem.GolonganTol3; GolonganTol4 = dbitem.GolonganTol4; Keterangan = dbitem.Keterangan; }
public JsonResult Delete(int id) { ResponeModel response = new ResponeModel(true); Context.JnsTols dbItem = RepoJnsTol.FindByPK(id); RepoJnsTol.delete(dbItem, UserPrincipal.id); return(Json(response)); }
public string BindingHistory(int IdTol) { Context.JnsTols items = RepoJnsTol.FindByPK(IdTol); return(new JavaScriptSerializer().Serialize(new { data = items.ListHistoryJnsTols.OrderByDescending(d => d.Id).Select(d => new { Tanggal = d.Tanggal.ToLongDateString(), NamaTol = d.NamaTol, GolonganTol1 = d.GolonganTol1, GolonganTol2 = d.GolonganTol2, GolonganTol3 = d.GolonganTol3, GolonganTol4 = d.GolonganTol4, Keterangan = d.Keterangan, User = d.ForUser.Username }) })); }
public ActionResult Add(JnsTol model) { if (ModelState.IsValid) { bool Isexist = RepoJnsTol.IsExist(model.NamaTol); if (Isexist) { ModelState.AddModelError("NamaTol", "Nama Tol telah dipakai."); return(View("Form", model)); } Context.JnsTols dbitem = new Context.JnsTols(); model.setDb(dbitem); Context.HistoryJnsTols dbitemhistory = new Context.HistoryJnsTols(); model.setDbHistory(dbitemhistory, UserPrincipal.id); dbitem.ListHistoryJnsTols.Add(dbitemhistory); RepoJnsTol.save(dbitem, UserPrincipal.id, dbitemhistory); return(RedirectToAction("Index")); } return(View("Form", model)); }
public string UploadTol(IEnumerable <HttpPostedFileBase> filesTol) { ResponeModel response = new ResponeModel(); //algoritma if (filesTol != null) { foreach (var file in filesTol) { 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, 3].Value != null && workSheet.Cells[rowIterator, 4].Value != null && workSheet.Cells[rowIterator, 5].Value != null) { try { int id = 0; int resId; if (workSheet.Cells[rowIterator, 7].Value != null) { if (int.TryParse(workSheet.Cells[rowIterator, 7].Value.ToString(), out resId)) { id = resId; } } if (id == 0) { bool Isexist = RepoJnsTol.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString()); if (Isexist) { continue; } } else { bool Isexist = RepoJnsTol.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString(), id); if (Isexist) { continue; } } Context.JnsTols dbitem = new Context.JnsTols(); if (id != 0) { dbitem = RepoJnsTol.FindByPK(id); } dbitem.NamaTol = workSheet.Cells[rowIterator, 1].Value.ToString(); dbitem.GolonganTol1 = decimal.Parse(workSheet.Cells[rowIterator, 2].Value.ToString()); dbitem.GolonganTol2 = decimal.Parse(workSheet.Cells[rowIterator, 3].Value.ToString()); dbitem.GolonganTol3 = decimal.Parse(workSheet.Cells[rowIterator, 4].Value.ToString()); dbitem.GolonganTol4 = decimal.Parse(workSheet.Cells[rowIterator, 5].Value.ToString()); dbitem.Keterangan = workSheet.Cells[rowIterator, 6].Value == null ? "" : workSheet.Cells[rowIterator, 6].Value.ToString(); RepoJnsTol.save(dbitem, UserPrincipal.id, new Context.HistoryJnsTols()); } catch (Exception) { } } } } response.Success = true; } catch (Exception e) { response.Success = false; response.Message = e.Message.ToString(); } } } return(new JavaScriptSerializer().Serialize(new { Response = response })); }