Пример #1
0
        public void setDb(Context.VendorGps dbitem)
        {
            dbitem.Id     = Id;
            dbitem.Merk   = Merk;
            dbitem.Nama   = Nama;
            dbitem.Alamat = Alamat;
            dbitem.Email  = Email;
            dbitem.Telp   = Telp;
            dbitem.Web    = Web;

            dbitem.ListKontak.Clear();

            Kontak[] result = JsonConvert.DeserializeObject <Kontak[]>(strVendor);

            foreach (Kontak item in result)
            {
                dbitem.ListKontak.Add(new Context.Kontak()
                {
                    Nama      = item.Nama,
                    IdJabatan = item.IdJabatan,
                    Hp        = item.Hp,
                    Email     = item.Email
                });
            }
        }
Пример #2
0
        public ActionResult Edit(int id)
        {
            Context.VendorGps dbitem = RepoVendor.FindByPK(id);
            VendorGps         model  = new VendorGps(dbitem);

            ViewBag.name = model.Nama;
            return(View("Form", model));
        }
Пример #3
0
        public JsonResult Delete(int id)
        {
            ResponeModel response = new ResponeModel(true);

            Context.VendorGps dbItem = RepoVendor.FindByPK(id);

            RepoVendor.delete(dbItem, UserPrincipal.id);

            return(Json(response));
        }
Пример #4
0
        public ActionResult Edit(VendorGps model)
        {
            if (ModelState.IsValid)
            {
                Context.VendorGps dbitem = RepoVendor.FindByPK(model.Id);
                model.setDb(dbitem);
                RepoVendor.save(dbitem, UserPrincipal.id);

                return(RedirectToAction("Index"));
            }
            Kontak[] result = JsonConvert.DeserializeObject <Kontak[]>(model.strVendor);
            model.ListKontak = result.ToList();
            return(View("Form", model));
        }
Пример #5
0
 public VendorGps(Context.VendorGps dbitem)
 {
     Id         = dbitem.Id;
     Merk       = dbitem.Merk;
     Nama       = dbitem.Nama;
     Alamat     = dbitem.Alamat;
     Email      = dbitem.Email;
     Telp       = dbitem.Telp;
     Web        = dbitem.Web;
     ListKontak = new List <Kontak>();
     foreach (Context.Kontak item in dbitem.ListKontak.ToList())
     {
         ListKontak.Add(new Kontak(item));
     }
 }
Пример #6
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;

                            //sheet 1
                            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)
                                {
                                    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;
                                        }
                                    }
                                    //cara gancang ngarah teu kudu aya pengecekan tiap field
                                    Context.VendorGps dbitem = new Context.VendorGps();
                                    try
                                    {
                                        if (id != 0)
                                        {
                                            dbitem = RepoVendor.FindByPK(id);
                                        }

                                        dbitem.Nama   = workSheet.Cells[rowIterator, 1].Value.ToString();
                                        dbitem.Alamat = workSheet.Cells[rowIterator, 2].Value.ToString();
                                        dbitem.Telp   = workSheet.Cells[rowIterator, 3].Value.ToString();
                                        dbitem.Email  = workSheet.Cells[rowIterator, 4].Value.ToString();
                                        dbitem.Web    = workSheet.Cells[rowIterator, 5].Value.ToString();

                                        RepoVendor.save(dbitem, UserPrincipal.id);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                }
                            }

                            //sheet 2
                            workSheet = currentSheet.Where(s => s.Index == 2).FirstOrDefault();
                            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)
                                {
                                    if (workSheet.Cells[rowIterator, 6].Value.ToString() != null && workSheet.Cells[rowIterator, 7].Value.ToString() != null)
                                    {
                                        //edit
                                        try
                                        {
                                            Context.VendorGps db  = RepoVendor.FindByPK(int.Parse(workSheet.Cells[rowIterator, 6].Value.ToString()));
                                            int            iditem = int.Parse(workSheet.Cells[rowIterator, 7].Value.ToString());
                                            Context.Kontak dbitem = db.ListKontak.Where(d => d.Id == iditem).FirstOrDefault();
                                            dbitem.Nama      = workSheet.Cells[rowIterator, 2].Value.ToString();
                                            dbitem.IdJabatan = RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                            dbitem.Hp        = workSheet.Cells[rowIterator, 4].Value.ToString();
                                            dbitem.Email     = workSheet.Cells[rowIterator, 5].Value.ToString();
                                            RepoVendor.save(db, UserPrincipal.id);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }
                                    else
                                    {
                                        //add
                                        try
                                        {
                                            Context.VendorGps db     = RepoVendor.FindByPK(int.Parse(workSheet.Cells[rowIterator, 6].Value.ToString()));
                                            Context.Kontak    dbitem = new Context.Kontak();
                                            dbitem.Nama      = workSheet.Cells[rowIterator, 2].Value.ToString();
                                            dbitem.IdJabatan = RepoLookup.FindByName(workSheet.Cells[rowIterator, 3].Value.ToString()).Id;
                                            dbitem.Hp        = workSheet.Cells[rowIterator, 4].Value.ToString();
                                            dbitem.Email     = workSheet.Cells[rowIterator, 5].Value.ToString();
                                            db.ListKontak.Add(dbitem);
                                            RepoVendor.save(db, 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 }));
        }