public ActionResult Edit(Location model) { if (ModelState.IsValid) { //more validation bool IsExist = RepoLocation.IsExist(model.Code, model.Id); if (IsExist) { ModelState.AddModelError("Code", "Code sudah terdaftar"); return(View("Form", model)); } if (model.Type != "Provinsi") { if (!model.ParentId.HasValue) { ModelState.AddModelError("ParentId", "Parent harus diisi"); return(View("Form", model)); } } Context.Location dbitem = RepoLocation.FindByPK(model.Id); model.setDb(dbitem); RepoLocation.save(dbitem); return(RedirectToAction("Index")); } return(View("Form", model)); }
public ActionResult Edit(int id) { Context.Location dbitem = RepoLocation.FindByPK(id); Location model = new Location(dbitem); ViewBag.name = model.Nama; return(View("Form", model)); }
public void setDb(Context.Location dbitem) { dbitem.Id = Id; dbitem.Code = Code; dbitem.Type = Type; dbitem.Nama = Nama; dbitem.ParentId = ParentId; }
public Location(Context.Location dbitem) { Id = dbitem.Id; Code = dbitem.Code; Type = dbitem.Type; Nama = dbitem.Nama; ParentId = dbitem.ParentId; strPArent = dbitem.ParentId == null ? "" : dbitem.LocationParent.Nama; }
public JsonResult Delete(int id) { ResponeModel response = new ResponeModel(true); Context.Location dbItem = RepoLocation.FindByPK(id); RepoLocation.delete(dbItem); return(Json(response)); }
public FileContentResult Export() { //bikin file baru ExcelPackage pck = new ExcelPackage(); //sumber data List <Context.Multidrop> dbMultidrop = RepoMultidrop.FindAll(); IList <String> listTujuan = new List <string>(); String dataTujuan = ""; //bikin worksheet worksheet ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Sheet 1"); //bikin header cell[baris,kolom] , nama kolom sesuaikan dengan template ws.Cells[1, 1].Value = "Jumlah Kota"; ws.Cells[1, 2].Value = "Tambahan Waktu Tempuh"; ws.Cells[1, 3].Value = "Tambahan Waktu Kerja"; ws.Cells[1, 4].Value = "Tujuan"; ws.Cells[1, 5].Value = "Id Database"; // Inserts Data int idx = 0; int nextRow = 0; for (int i = 0; i < dbMultidrop.Count(); i++) { ws.Cells[i + 2 + nextRow, 1].Value = dbMultidrop[i].JumlahKota; ws.Cells[i + 2 + nextRow, 2].Value = dbMultidrop[i].WaktuTempuh; ws.Cells[i + 2 + nextRow, 3].Value = dbMultidrop[i].WaktuKerja; ws.Cells[i + 2 + nextRow, 5].Value = dbMultidrop[i].Id; dataTujuan = dbMultidrop[i].tujuan; listTujuan = dataTujuan.Split(new String[] { " - " }, StringSplitOptions.None); for (idx = 0; idx <= listTujuan.Count - 1; idx++) { Context.Location loc = RepoLocation.FindByNama(listTujuan[idx]); ws.Cells[i + 2 + nextRow, 4].Value = loc.Code; nextRow++; } nextRow--; } var fsr = new FileContentResult(pck.GetAsByteArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); fsr.FileDownloadName = "Export Data Multidrop.xls"; return(fsr); }
public string UploadLokasi(IEnumerable <HttpPostedFileBase> files) { ResponeModel response = new ResponeModel(); string msgResult = ""; //algoritma if (files != null) { foreach (var file in files) { try { using (var package = new ExcelPackage(file.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++) { if (workSheet.Cells[rowIterator, 2].Value != null && workSheet.Cells[rowIterator, 3].Value != null && workSheet.Cells[rowIterator, 4].Value != null) { try { int id = 0; int resId; Context.Location dbitem = new Context.Location(); //if (workSheet.Cells[rowIterator, 5].Value != null) if (workSheet.Cells[rowIterator, 8].Value != null) { if (int.TryParse(workSheet.Cells[rowIterator, 8].Value.ToString(), out resId)) { id = resId; } } string code = workSheet.Cells[rowIterator, 3].Value.ToString().Replace(',', '.'); if (RepoLocation.IsExist(code, id)) { continue; } if (id != 0) { dbitem = RepoLocation.FindByCode(code); } //parent if (workSheet.Cells[rowIterator, 2].Value.ToString() != "PROV") { dbitem.ParentId = RepoLocation.FindByCode(workSheet.Cells[rowIterator, 1].Value.ToString()).Id; } //code dbitem.Code = code; //cek type (PROV, KOTA, KAB) //PROV if (workSheet.Cells[rowIterator, 2].Value.ToString() == "PROV") { dbitem.Type = "Provinsi"; dbitem.Nama = workSheet.Cells[rowIterator, 4].Value.ToString(); } else if (workSheet.Cells[rowIterator, 2].Value.ToString() == "KOTA") { dbitem.Type = "Kab/Kota"; dbitem.Nama = "Kota " + workSheet.Cells[rowIterator, 4].Value.ToString(); } else if (workSheet.Cells[rowIterator, 2].Value.ToString() == "KAB") { dbitem.Type = "Kab/Kota"; dbitem.Nama = "Kabupaten " + workSheet.Cells[rowIterator, 4].Value.ToString(); } else if (workSheet.Cells[rowIterator, 2].Value.ToString() == "KEC") { dbitem.Type = "Kecamatan"; dbitem.Nama = "Kecamatan " + workSheet.Cells[rowIterator, 4].Value.ToString(); } else if (workSheet.Cells[rowIterator, 2].Value.ToString() == "DES") { dbitem.Type = "Kelurahan"; dbitem.Nama = "Kelurahan " + workSheet.Cells[rowIterator, 4].Value.ToString(); } Task t = Task.Run(() => RepoLocation.save(dbitem)); t.Wait(); } catch (Exception e) { string msg = e.Message.ToString(); } } } } response.Success = true; } catch (Exception e) { response.Success = false; response.Message = e.Message.ToString(); } } } return(new JavaScriptSerializer().Serialize(new { Response = response })); }
public string GetLocationByName(string name) { Context.Location dbitems = RepoLocation.FindByNama(name); return(new JavaScriptSerializer().Serialize(dbitems)); }
public string GetLocationByCode(string code) { Context.Location dbitems = RepoLocation.FindAll().Where(d => d.Code == code).FirstOrDefault(); return(new JavaScriptSerializer().Serialize(dbitems)); }
public string Upload(IEnumerable <HttpPostedFileBase> filesMultidrop) { ResponeModel response = new ResponeModel(); if (filesMultidrop != null) { foreach (var file in filesMultidrop) { try { using (var package = new ExcelPackage(file.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; bool isSaved = true; 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) { int id = 0; int resId; if (workSheet.Cells[rowIterator, 5].Value != null) { if (int.TryParse(workSheet.Cells[rowIterator, 5].Value.ToString(), out resId)) { id = resId; } } List <String> listLocation = new List <string>(); Context.Multidrop dbMultiDrop = new Context.Multidrop(); try { if (id != 0) { dbMultiDrop = RepoMultidrop.FindByPK(id); } dbMultiDrop.JumlahKota = int.Parse(workSheet.Cells[rowIterator, 1].Value.ToString()); dbMultiDrop.WaktuTempuh = int.Parse(workSheet.Cells[rowIterator, 2].Value.ToString()); dbMultiDrop.WaktuKerja = int.Parse(workSheet.Cells[rowIterator, 3].Value.ToString()); Context.Location revLocation = RepoLocation.FindByCode(workSheet.Cells[rowIterator, 4].Value.ToString()); if (revLocation != null) { listLocation.Add(revLocation.Nama); } for (int x = rowIterator + 1; x <= noOfRow; x++) { if (workSheet.Cells[x, 4].Value != null && workSheet.Cells[x, 1].Value == null && workSheet.Cells[x, 2].Value == null && workSheet.Cells[x, 3].Value == null) { Context.Location loc = RepoLocation.FindByCode(workSheet.Cells[x, 4].Value.ToString()); if (loc != null) { listLocation.Add(loc.Nama); } else { isSaved = false; break; } } else { //isSaved = false; break; } } if (listLocation.Count > 1) { dbMultiDrop.tujuan = string.Join(" - ", listLocation); } if (RepoMultidrop.FindByTujuan(dbMultiDrop.tujuan.ToString()) != null) { continue; } if (isSaved) { RepoMultidrop.save(dbMultiDrop); } } catch (Exception) { } } } } response.Success = true; } catch (Exception e) { response.Success = false; response.Message = e.Message.ToString(); } } } return(new JavaScriptSerializer().Serialize(new { Response = response })); }
// Location Mapping public static Library.Location Map(Context.Location location) => new Library.Location { Id = location.Id, Name = location.Name, InventoryId = (int)location.InventoryId };