예제 #1
0
        public ActionResult Edit(int id)
        {
            Context.MasterArea dbitem = RepoArea.FindByPK(id);
            MasterArea         model  = new MasterArea(dbitem);

            ViewBag.name = model.Kode;
            return(View("Form", model));
        }
예제 #2
0
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.MasterArea dbItem = RepoArea.FindByPK(id);

            RepoArea.delete(dbItem);

            return(Json(response));
        }
예제 #3
0
 public MasterArea(Context.MasterArea dbitem)
 {
     Id       = dbitem.Id;
     Kode     = dbitem.Kode;
     Nama     = dbitem.Nama;
     listArea = new List <LocationArea>();
     foreach (Context.ListLocationArea item in dbitem.ListLocationArea.ToList())
     {
         listArea.Add(new LocationArea(item));
     }
 }
예제 #4
0
        public ActionResult Edit(MasterArea model)
        {
            if (ModelState.IsValid)
            {
                Context.MasterArea dbitem = RepoArea.FindByPK(model.Id);
                model.setDb(dbitem);
                RepoArea.save(dbitem);

                return(RedirectToAction("Index"));
            }
            LocationArea[] result = JsonConvert.DeserializeObject <LocationArea[]>(model.strArea);
            model.listArea = result.ToList();
            return(View("Form", model));
        }
예제 #5
0
        public void setDb(Context.MasterArea dbitem)
        {
            dbitem.Kode = Kode;
            dbitem.Nama = Nama;

            dbitem.ListLocationArea.Clear();

            LocationArea[] result = JsonConvert.DeserializeObject <LocationArea[]>(strArea);

            foreach (LocationArea item in result)
            {
                dbitem.ListLocationArea.Add(new Context.ListLocationArea()
                {
                    LocationId = item.idLoc
                });
            }
        }
예제 #6
0
        public ActionResult Add(MasterArea model)
        {
            if (ModelState.IsValid)
            {
                Context.MasterArea dbitem = new Context.MasterArea();
                model.setDb(dbitem);
                //generate code
                dbitem.Urutan = RepoArea.getUrutan() + 1;
                dbitem.Kode   = RepoArea.generateCode(dbitem.Urutan);

                RepoArea.save(dbitem);

                return(RedirectToAction("Index"));
            }
            LocationArea[] result = JsonConvert.DeserializeObject <LocationArea[]>(model.strArea);
            model.listArea = result.ToList();
            return(View("Form", model));
        }
예제 #7
0
        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 }));
        }