コード例 #1
0
        public ActionResult Create(a_SupplierViewModel a_Supplier)
        {
            if (ModelState.IsValid)
            {
                string a_SupplierJSON = JsonConvert.SerializeObject(a_Supplier);
                var    buffer         = Encoding.UTF8.GetBytes(a_SupplierJSON);
                var    byteContent    = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                string     API_END_POINT = API_URL + "api/a_SupplierAPI/";
                HttpClient client        = new HttpClient();

                HttpResponseMessage response = client.PostAsync(API_END_POINT, byteContent).Result;

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

                if (success)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Something was happened.");
                    return(View(a_Supplier));
                }
            }
            return(View(a_Supplier));
        }
コード例 #2
0
 public bool Put(a_SupplierViewModel a_Supplier)
 {
     try
     {
         service.Updatea_Supplier(a_Supplier);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
コード例 #3
0
        public List <a_SupplierViewModel> GetAlla_Supplier(string Name, string City)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                List <Xsis_Shop_Models.a_Supplier> Lista_Supplier;

                bool NullName = string.IsNullOrWhiteSpace(Name);
                Name = NullName ? " " : Name.ToLower();

                bool NullCity = string.IsNullOrWhiteSpace(City);
                City = NullCity ? " " : City.ToLower();

                if (NullName && NullCity) // NULL
                {
                    Lista_Supplier = db.a_Supplier.ToList();
                }

                else if (NullCity)  // Hanya Name
                {
                    Lista_Supplier = db.a_Supplier.Where(p => (
                                                             p.Name == Name
                                                             )).ToList();
                }

                else if (NullName)  // Hanya City
                {
                    Lista_Supplier = db.a_Supplier.Where(p => (
                                                             p.City == City
                                                             )).ToList();
                }

                else // Semua Terisi
                {
                    Lista_Supplier = (
                        from p in db.a_Supplier where ((p.Name == Name) && (p.City == City))
                        select p
                        ).ToList();
                }
                List <a_SupplierViewModel> ListView = new List <a_SupplierViewModel>();

                foreach (var a_Supplier in Lista_Supplier)
                {
                    a_SupplierViewModel Model = new a_SupplierViewModel();
                    Model.ID   = a_Supplier.ID;
                    Model.Code = a_Supplier.Code;
                    Model.Name = a_Supplier.Name;
                    Model.City = a_Supplier.City;

                    ListView.Add(Model);
                }
                return(ListView);
            }
        }
コード例 #4
0
 public bool Post(a_SupplierViewModel a_Supplier)
 {
     try
     {
         service.CreateNewa_Supplier(a_Supplier);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
コード例 #5
0
        // INSERT INTO a_Supplier VALUE a_Supplier
        public void CreateNewa_Supplier(a_SupplierViewModel a_Supplier)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                Xsis_Shop_Models.a_Supplier Model = new Xsis_Shop_Models.a_Supplier();
                Model.Code = a_Supplier.Code;
                Model.Name = a_Supplier.Name;
                Model.City = a_Supplier.City;

                db.a_Supplier.Add(Model);
                db.SaveChanges();
            }
        }
コード例 #6
0
        public List <a_SupplierViewModel> Geta_SupplierList(string id)
        {
            var a_Suppliers  = service.Geta_SupplierList();
            var ListSupplier = new List <a_SupplierViewModel>();

            foreach (var a_Supplier in a_Suppliers)
            {
                var result = new a_SupplierViewModel();
                result.ID   = a_Supplier.ID;
                result.Name = a_Supplier.Name;
                ListSupplier.Add(result);
            }
            return(ListSupplier);
        }
コード例 #7
0
        // UPDATE
        public void Updatea_Supplier(a_SupplierViewModel a_Supplier)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                Xsis_Shop_Models.a_Supplier Model = new Xsis_Shop_Models.a_Supplier();
                Model.ID   = a_Supplier.ID;
                Model.Code = a_Supplier.Code;
                Model.Name = a_Supplier.Name;
                Model.City = a_Supplier.City;

                db.Entry(Model).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
コード例 #8
0
        // SELECT * FROM a_Supplier WHERE Id = Id
        public a_SupplierViewModel Geta_SupplierById(int id)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                a_Supplier a_Supplier = db.a_Supplier.Find(id);

                a_SupplierViewModel Model = new a_SupplierViewModel();
                Model.ID   = a_Supplier.ID;
                Model.Code = a_Supplier.Code;
                Model.Name = a_Supplier.Name;
                Model.City = a_Supplier.City;

                return(Model);
            }
        }
コード例 #9
0
        // SELECT * FROM a_Supplier
        public List <a_SupplierViewModel> GetAlla_Supplier()
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                var Lista_Supplier = db.a_Supplier.ToList();
                List <a_SupplierViewModel> ListView = new List <a_SupplierViewModel>();
                foreach (var a_Supplier in Lista_Supplier)
                {
                    a_SupplierViewModel Model = new a_SupplierViewModel();
                    Model.ID   = a_Supplier.ID;
                    Model.Code = a_Supplier.Code;
                    Model.Name = a_Supplier.Name;
                    Model.City = a_Supplier.City;

                    ListView.Add(Model);
                }
                return(ListView);
            }
        }
コード例 #10
0
        // GET: a_Suppliers/Details/{id}
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            string              API_END_POINT = API_URL + "api/a_SupplierAPI/Get/" + (id ?? 0);
            HttpClient          client        = new HttpClient();
            HttpResponseMessage response      = client.GetAsync(API_END_POINT).Result;

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

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