Пример #1
0
        public ActionResult Create(SupplierViewModels supplier)
        {
            if (ModelState.IsValid)
            {
                //API Akses
                string json        = JsonConvert.SerializeObject(supplier);
                var    buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                var    byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                string              ApiEndPoint = ApiUrl + "api/SupplierApi/post/";
                HttpClient          client      = new HttpClient();
                HttpResponseMessage response    = client.PostAsync(ApiEndPoint, byteContent).Result;

                string result  = response.Content.ReadAsStringAsync().Result.ToString();
                int    success = int.Parse(result);

                if (success == 1)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(supplier));
                }
            }

            return(View(supplier));
        }
Пример #2
0
        public ActionResult Create(SupplierViewModels model)
        {
            var data = new ResponseModels();

            try
            {
                // TODO: Add insert logic here
                EasyBuyEntities db            = new EasyBuyEntities();
                var             checkSupplier = db.Suppliers.Where(p => p.Name == model.Name).FirstOrDefault();
                if (checkSupplier == null)
                {
                    Models.Supplier supplier = new Models.Supplier
                    {
                        Name    = model.Name,
                        Phone   = model.Phone,
                        City    = model.City,
                        Area    = model.Area,
                        Address = model.Address
                    };
                    db.Suppliers.Add(supplier);
                    db.SaveChanges();
                    data.result = 1;
                }
                else
                {
                    data.msg = "該廠商已存在,請重新建立。";
                }
            }
            catch (Exception e)
            {
                data.msg = e.Message;
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
 public ActionResult Search(SupplierViewModels model)
 {
     try
     {
         if (lstCompany != null && lstCompany.Count > 0)
         {
             model.CompanyId = lstCompany[0].Value;
         }
         if (model.CompanyId != null)
         {
             var data = _factory.GetData(model.CompanyId, CurrentUser.ListOrganizationId);
             data.ForEach(x =>
             {
                 if (!string.IsNullOrEmpty(x.CompanyId))
                 {
                     x.CompanyName = lstCompany.Where(z => z.Value.Equals(x.CompanyId)).FirstOrDefault().Text;
                 }
             });
             model.ListItem = data;
         }
     }
     catch (Exception e)
     {
         _logger.Error("SupplierSearch: " + e);
         return(new HttpStatusCodeResult(400, e.Message));
     }
     return(PartialView("_ListData", model));
 }
 public int put(SupplierViewModels supplier)
 {
     try
     {
         service.UpdateSupplier(supplier);
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
 public int post(SupplierViewModels supplier)
 {
     try
     {
         service.AddNewSupplier(supplier);
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Пример #6
0
        // GET: Suppliers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            int idx = id ?? 0;
            SupplierViewModels result = service.GetSupplierById(idx);

            if (result == null)
            {
                return(HttpNotFound());
            }
            return(View(result));
        }
Пример #7
0
 //create supplier
 public void AddNewSupplier(SupplierViewModels supplier)
 {
     using (ShopDBEntities db = new ShopDBEntities())
     {
         Supplier model = new Supplier();
         model.Id           = supplier.Id;
         model.CompanyName  = supplier.CompanyName;
         model.ContactName  = supplier.ContactName;
         model.ContactTitle = supplier.ContactTitle;
         model.City         = supplier.City;
         model.Country      = supplier.Country;
         model.Phone        = supplier.Phone;
         model.Fax          = supplier.Fax;
         db.Supplier.Add(model);
         db.SaveChanges();
     }
 }
Пример #8
0
        //update costumer
        public void UpdateSupplier(SupplierViewModels supplier)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                Supplier model = new Supplier();
                model.Id           = supplier.Id;
                model.CompanyName  = supplier.CompanyName;
                model.ContactName  = supplier.ContactName;
                model.ContactTitle = supplier.ContactTitle;
                model.City         = supplier.City;
                model.Country      = supplier.Country;
                model.Phone        = supplier.Phone;

                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Пример #9
0
 public ActionResult Index()
 {
     try
     {
         SupplierViewModels model = new SupplierViewModels();
         if (lstCompany != null && lstCompany.Count > 0)
         {
             model.CompanyId = lstCompany[0].Value;
         }
         return(View(model));
     }
     catch (Exception ex)
     {
         _logger.Error("SupplierIndex: " + ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
Пример #10
0
        //select * from supplier where id = "id"
        public SupplierViewModels GetSupplierById(int id)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                Supplier           supplier = db.Supplier.Find(id);
                SupplierViewModels suppVM   = new SupplierViewModels();
                suppVM.Id           = supplier.Id;
                suppVM.CompanyName  = supplier.CompanyName;
                suppVM.ContactName  = supplier.ContactName;
                suppVM.ContactTitle = supplier.ContactTitle;
                suppVM.City         = supplier.City;
                suppVM.Country      = supplier.Country;
                suppVM.Phone        = supplier.Phone;
                suppVM.Fax          = supplier.Fax;

                List <ProductViewModels> ListProduct = new List <ProductViewModels>();
                ListProduct = (from d in db.Product
                               where d.SupplierId == suppVM.Id
                               select new ProductViewModels
                {
                    Id = d.Id,
                    ProductName = d.ProductName,
                    SupplierId = d.SupplierId,
                    UnitPrice = d.UnitPrice,
                    Package = d.Package,
                    IsDiscontinued = d.IsDiscontinued
                }).ToList();

                if (ListProduct == null)
                {
                    suppVM.listproduk = null;
                }
                else
                {
                    suppVM.listproduk = ListProduct;
                }

                return(suppVM);
            }
        }
Пример #11
0
        //select * from supplier
        public List <SupplierViewModels> GetAllSupplier()
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                var list = db.Supplier.ToList();
                List <SupplierViewModels> listVM = new List <SupplierViewModels>();

                foreach (var item in list)
                {
                    SupplierViewModels viewModel = new SupplierViewModels();
                    viewModel.Id           = item.Id;
                    viewModel.CompanyName  = item.CompanyName;
                    viewModel.ContactName  = item.ContactName;
                    viewModel.ContactTitle = item.ContactTitle;
                    viewModel.City         = item.City;
                    viewModel.Country      = item.Country;
                    viewModel.Phone        = item.Phone;
                    viewModel.Fax          = item.Fax;
                    listVM.Add(viewModel);
                }
                return(listVM);
            }
        }
Пример #12
0
        // GET: Suppliers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            int idx = id ?? 0;

            string              ApiEndPoint = ApiUrl + "api/SupplierApi/Get/" + idx;
            HttpClient          client      = new HttpClient();
            HttpResponseMessage response    = client.GetAsync(ApiEndPoint).Result;

            string             result = response.Content.ReadAsStringAsync().Result.ToString();
            SupplierViewModels supVM  = JsonConvert.DeserializeObject <SupplierViewModels>(result);

            //SupplierViewModels result = service.GetSupplierById(idx);

            if (supVM == null)
            {
                return(HttpNotFound());
            }
            return(View(supVM));
        }