Пример #1
0
 public ActionResult UpdateOrCreateCustomer(MyCustomer model)
 {
     try
     {
         Onboard2DbContext db = new Onboard2DbContext();
         if (model.Id > 0)
         {
             //update
             Customer cust = db.Customers.FirstOrDefault(x => x.Id == model.Id);
             if (cust != null)
             {
                 cust.Id      = model.Id;
                 cust.Name    = model.Name;
                 cust.Address = model.Address;
             }
             db.SaveChanges();
         }
         else
         {
             //Insert
             Customer cust = new Customer();
             cust.Name    = model.Name;
             cust.Address = model.Address;
             db.Customers.Add(cust);
             db.SaveChanges();
         }
         return(RedirectToAction("GetCustomerList"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
        public ActionResult UpdateOrCreateProduct(MyProduk model)
        {
            try
            {
                Onboard2DbContext db = new Onboard2DbContext();
                if (model.Id > 0)
                {
                    //update
                    Product prod = db.Products.SingleOrDefault(x => x.Id == model.Id);
                    prod.Id    = model.Id;
                    prod.Name  = model.Name;
                    prod.Price = model.Price;
                    db.SaveChanges();
                }
                else
                {
                    //Insert
                    Product prod = new Product();
                    prod.Name  = model.Name;
                    prod.Price = model.Price;
                    db.Products.Add(prod);
                    db.SaveChanges();
                }

                return(RedirectToAction("GetProductList"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public ActionResult UpdateOrCreateProductSold(ProductSold model)
        {
            var db = new Onboard2DbContext();

            if (model.Id > 0)
            {
                // UPDATE
                var prodsold = db.ProductSolds.SingleOrDefault(x => x.Id == model.Id);

                prodsold.ProductId  = model.ProductId;
                prodsold.CustomerId = model.CustomerId;
                prodsold.StoreId    = model.StoreId;
                prodsold.DateSold   = model.DateSold;
                db.SaveChanges();
            }

            else
            {
                // INSERT
                ProductSold prodsold = new ProductSold();
                prodsold.ProductId  = model.ProductId;
                prodsold.CustomerId = model.CustomerId;
                prodsold.StoreId    = model.StoreId;
                prodsold.DateSold   = model.DateSold;

                db.ProductSolds.Add(prodsold);
                db.SaveChanges();
            }
            return(Json(model));
        }
 public ActionResult UpdateOrCreateStore(MyStore model)
 {
     try
     {
         Onboard2DbContext db = new Onboard2DbContext();
         if (model.Id > 0)
         {
             //update
             Store stor = db.Stores.FirstOrDefault(x => x.Id == model.Id);
             if (stor != null)
             {
                 stor.Id      = model.Id;
                 stor.Name    = model.Name;
                 stor.Address = model.Address;
             }
             db.SaveChanges();
         }
         else
         {
             //Insert
             Store stor = new Store();
             stor.Name    = model.Name;
             stor.Address = model.Address;
             db.Stores.Add(stor);
             db.SaveChanges();
         }
         return(RedirectToAction("GetStoreList"));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #5
0
        // DELETE
        public JsonResult DeleteProduct(int Id)
        {
            using (var db = new Onboard2DbContext())
            {
                var prod     = db.Products.FirstOrDefault(x => x.Id == Id);
                var prodsold = db.ProductSolds.FirstOrDefault(x => x.Id == Id);
                var prodid   = db.ProductSolds.FirstOrDefault(x => x.ProductId == Id);

                if (prod != null)
                {
                    db.Products.Remove(prod);
                }
                if (prodsold != null)
                {
                    db.ProductSolds.Remove(prodsold);
                }
                if (prodid != null)
                {
                    db.ProductSolds.Remove(prodid);
                }
                db.SaveChanges();

                return(Json(JsonRequestBehavior.AllowGet));
            }
        }
        // SHOW DETAILS
        public ActionResult ShowStore(int Id)
        {
            Onboard2DbContext db       = new Onboard2DbContext();
            List <MyStore>    listStor = db.Stores.Where(x => x.Id == Id).Select(x => new MyStore()
            {
                Name    = x.Name,
                Address = x.Address
            }).ToList();

            ViewBag.StoreList = listStor;
            return(PartialView("ShowStore"));
        }
Пример #7
0
 public ActionResult GetStoreList()
 {
     using (var db = new Onboard2DbContext())
     {
         var allStor = db.Stores.Select(x => new MyStore
         {
             Id   = x.Id,
             Name = x.Name
         }).ToList();
         return(Json(allStor, JsonRequestBehavior.AllowGet));
     }
 }
Пример #8
0
        // SHOW DETAILS
        public ActionResult ShowCustomer(int Id)
        {
            Onboard2DbContext db       = new Onboard2DbContext();
            List <MyCustomer> listCust = db.Customers.Where(x => x.Id == Id).Select(x => new MyCustomer()
            {
                Name    = x.Name,
                Address = x.Address
            }).ToList();

            ViewBag.CustomerList = listCust;
            return(PartialView("ShowCustomer"));
        }
Пример #9
0
        // SHOW DETAILS
        public ActionResult ShowProduct(int Id)
        {
            Onboard2DbContext db       = new Onboard2DbContext();
            List <MyProduk>   listProd = db.Products.Where(x => x.Id == Id).Select(x => new MyProduk()
            {
                Name  = x.Name,
                Price = x.Price
            }).ToList();

            ViewBag.ProductList = listProd;
            return(PartialView("ShowProduct"));
        }
Пример #10
0
 public ActionResult GetProductList()
 {
     using (var db = new Onboard2DbContext())
     {
         var allProd = db.Products.Select(x => new MyProduk
         {
             Id   = x.Id,
             Name = x.Name
         }).ToList();
         return(Json(allProd, JsonRequestBehavior.AllowGet));
     }
 }
Пример #11
0
 // LOAD CONTROLLER FOR DROPDOWN SELECT
 public ActionResult GetCustomerList()
 {
     using (var db = new Onboard2DbContext())
     {
         var allCust = db.Customers.Select(x => new MyCustomer
         {
             Id      = x.Id,
             Name    = x.Name,
             Address = x.Address
         }).ToList();
         return(Json(allCust, JsonRequestBehavior.AllowGet));
     }
 }
Пример #12
0
 // GET: Customer List
 public ActionResult GetCustomerList()
 {
     using (var db = new Onboard2DbContext())
     {
         var cust = db.Customers.Select(x => new MyCustomer
         {
             Id      = x.Id,
             Name    = x.Name,
             Address = x.Address
         }).ToList();
         return(View(cust));
     }
 }
        // ADD OR EDIT
        public ActionResult AddOrEdit(int Id)
        {
            Onboard2DbContext db    = new Onboard2DbContext();
            MyStore           model = new MyStore();

            if (Id > 0)
            {
                Store stor = db.Stores.SingleOrDefault(x => x.Id == Id);
                model.Id      = stor.Id;
                model.Name    = stor.Name;
                model.Address = stor.Address;
            }
            return(PartialView("AddOrEdit", model));
        }
Пример #14
0
        // ADD OR EDIT
        public ActionResult AddOrEdit(int Id)
        {
            Onboard2DbContext db    = new Onboard2DbContext();
            MyCustomer        model = new MyCustomer();

            if (Id > 0)
            {
                Customer cust = db.Customers.SingleOrDefault(x => x.Id == Id);
                model.Id      = cust.Id;
                model.Name    = cust.Name;
                model.Address = cust.Address;
            }
            return(PartialView("AddOrEdit", model));
        }
Пример #15
0
        // PRODUCT LIST VIEW
        public ActionResult GetProductList()
        {
            using (var db = new Onboard2DbContext())
            {
                var product = db.Products.Select(x => new MyProduk
                {
                    Id    = x.Id,
                    Name  = x.Name,
                    Price = x.Price
                }).ToList();

                return(View(product));
            }
        }
        // GET: Store
        public ActionResult GetStoreList()
        {
            using (var db = new Onboard2DbContext())
            {
                var stor = db.Stores.Select(x => new MyStore
                {
                    Id      = x.Id,
                    Name    = x.Name,
                    Address = x.Address
                }).ToList();

                return(View(stor));
            }
        }
Пример #17
0
        // ADD OR EDIT
        public ActionResult AddOrEdit(int Id)
        {
            Onboard2DbContext db    = new Onboard2DbContext();
            MyProduk          model = new MyProduk();

            if (Id > 0)
            {
                Product prod = db.Products.SingleOrDefault(x => x.Id == Id);
                model.Id    = prod.Id;
                model.Name  = prod.Name;
                model.Price = prod.Price;
            }

            return(PartialView("AddOrEdit", model));
        }
Пример #18
0
        // GET: Sale
        public ActionResult GetSaleList()
        {
            using (var db = new Onboard2DbContext())
            {
                var saleList = db.ProductSolds.Select(x => new MySale
                {
                    Id           = x.Id,
                    ProductName  = x.Product.Name,
                    CustomerName = x.Customer.Name,
                    StoreName    = x.Store.Name,
                    DateSold     = x.DateSold
                }).ToList();

                return(View(saleList));
            }
        }
Пример #19
0
        // SHOW DETAILS
        public ActionResult ShowSale(int Id)
        {
            Onboard2DbContext db = new Onboard2DbContext();

            List <MySale> listSales = db.ProductSolds.Where(x => x.Id == Id).Select(x => new MySale()
            {
                Id           = x.Id,
                ProductName  = x.Product.Name,
                CustomerName = x.Customer.Name,
                StoreName    = x.Store.Name,
                DateSold     = x.DateSold
            }).ToList();

            ViewBag.SaleList = listSales;
            return(PartialView("ShowSale"));
        }
Пример #20
0
        // ADD OR EDIT CHECKING ID IF 0 OPEN PARTIAL VIEW CREATE MODAL
        public ActionResult AddEditProductSold(int Id)
        {
            var db    = new Onboard2DbContext();
            var model = new MySale();

            if (Id > 0)
            {
                var prodsold = db.ProductSolds.SingleOrDefault(x => x.Id == Id);
                var customer = db.Customers.SingleOrDefault(c => c.Id == prodsold.CustomerId);
                var store    = db.Stores.SingleOrDefault(s => s.Id == prodsold.StoreId);
                var product  = db.Products.SingleOrDefault(p => p.Id == prodsold.ProductId);

                model.Id           = prodsold.Id;
                model.ProductId    = product.Id;
                model.ProductName  = product.Name;
                model.CustomerId   = customer.Id;
                model.CustomerName = customer.Name;
                model.StoreId      = store.Id;
                model.StoreName    = store.Name;
                model.DateSold     = prodsold.DateSold;
            }
            return(PartialView("AddOrEdit", model));
        }