public LocationArea(Context.ListLocationArea dbitem) { idLoc = dbitem.LocationId.Value; code = dbitem.Location.Code; type = dbitem.Location.Type; name = dbitem.Location.Nama; if (dbitem.Location.LocationParent != null) { parentLoc = dbitem.Location.LocationParent.Nama; } }
public string Upload(IEnumerable <HttpPostedFileBase> files) { ResponeModel response = new ResponeModel(); //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 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) { int id = 0; int resId; if (workSheet.Cells[rowIterator, 3].Value != null) { if (int.TryParse(workSheet.Cells[rowIterator, 3].Value.ToString(), out resId)) { id = resId; } } Context.MasterArea dbitem = new Context.MasterArea(); try { if (id != 0) { dbitem = RepoArea.FindByPK(id); } else { dbitem.Urutan = RepoArea.getUrutan() + 1; dbitem.Kode = RepoArea.generateCode(dbitem.Urutan); } // parent if (RepoArea.IsExist(workSheet.Cells[rowIterator, 1].Value.ToString(), id)) { continue; } dbitem.Nama = workSheet.Cells[rowIterator, 1].Value.ToString(); //child int x = 0; List <int> listIdData = new List <int>(); List <Context.Rute> listRute = RepoRute.FindAll(); List <Context.ListLocationArea> listAreaAdd = new List <Context.ListLocationArea>(); //cek data existing dengan excell for (x = rowIterator; x <= noOfRow; x++) { if (workSheet.Cells[x, 1].Value == null || x == rowIterator) { try { Context.ListLocationArea listLocationArea = new Context.ListLocationArea(); int?idLoc = RepoLocation.FindByCode(workSheet.Cells[x, 2].Value.ToString()).Id; if (idLoc.HasValue) { if (id != 0) { if (dbitem.ListLocationArea.Any(d => d.LocationId == idLoc)) { listIdData.Add(idLoc.Value); } else { listLocationArea.LocationId = idLoc; listAreaAdd.Add(listLocationArea); } } else { listLocationArea.LocationId = idLoc; listAreaAdd.Add(listLocationArea); } } } catch (Exception) { } } else { rowIterator = x - 1; break; } } List <Context.ListLocationArea> dbremove = dbitem.ListLocationArea.Where(d => !listIdData.Contains(d.Id) && d.Id != 0).ToList(); //remove foreach (Context.ListLocationArea item in dbremove) { if (listRute.Any(r => r.IdAsal == item.LocationId && r.IdTujuan == item.LocationId)) { } else { dbitem.ListLocationArea.Remove(item); } } //add foreach (Context.ListLocationArea item in listAreaAdd) { dbitem.ListLocationArea.Add(item); } RepoArea.save(dbitem); } catch (Exception) { } } } } response.Success = true; } catch (Exception e) { response.Success = false; response.Message = e.Message.ToString(); } } } return(new JavaScriptSerializer().Serialize(new { Response = response })); }
public string Area(string area) { Context.ListLocationArea ar = context.ListLocationArea.Where(d => d.Location.Nama.ToLower().Replace("kecamatan", "").Replace(" ", "") == area.ToLower().Replace("kecamatan", "").Replace(" ", "")).FirstOrDefault(); return(ar == null ? area : ar.MasterArea.Nama); }