コード例 #1
0
        public JsonResult AddCustomerPurchase(CustomerAndPurchaseViewModel customerAndPurchaseViewModel)
        {
            bool status = false;

            var isValidModel = TryUpdateModel(customerAndPurchaseViewModel);

            if (isValidModel)
            {
                using (POS_WebEntities db = new POS_WebEntities())
                {
                    Customer customer = new Customer()
                    {
                        CustomerName = customerAndPurchaseViewModel.CustomerName,
                        OrderNumber  = customerAndPurchaseViewModel.OrderNumber,
                        Date         = customerAndPurchaseViewModel.Date,
                        Description  = customerAndPurchaseViewModel.Description
                    };
                    db.Customers.Add(customer);

                    if (db.SaveChanges() > 0)
                    {
                        int customerID = db.Customers.Max(c => c.ID);

                        foreach (var item in customerAndPurchaseViewModel.Items)
                        {
                            Purchase purchase = new Purchase()
                            {
                                CustomerID = customerID,
                                ProductID  = item.ProductID,
                                Price      = item.Price,
                                Quantity   = item.Quantity,
                                TotalPrice = item.TotalPrice
                            };
                            db.Purchases.Add(purchase);
                        }
                        if (db.SaveChanges() > 0)
                        {
                            return(new JsonResult {
                                Data = new { status = status, message = "Purchase added successfully" }
                            });
                        }
                    }
                }
            }
            status = false;
            return(new JsonResult {
                Data = new { status = status, message = "Error !!" }
            });
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "ID,BrandName,Origin")] Brand brand)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "Brand";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.Brands.Add(brand);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(brand));
        }
コード例 #3
0
        public ActionResult Create([Bind(Include = "ID,CountryName")] Country country)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "Country";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.Countries.Add(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "ID,CustomerName,OrderNumber,Date,Description")] Customer customer)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "Customer";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "ID,UnitName,UnitDescription,UnitPrimaryQty")] Unit unit)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "Unit";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.Units.Add(unit);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(unit));
        }
コード例 #6
0
        public ActionResult Create([Bind(Include = "ID,ProductID,ProductPrice1")] ProductPrice productPrice)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "ProductPrice";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.ProductPrices.Add(productPrice);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductID = new SelectList(db.Products, "ID", "ProductName", productPrice.ProductID);
            return(View(productPrice));
        }
コード例 #7
0
        public ActionResult Create([Bind(Include = "EmployeeID")] EmployeeAdmin employeeAdmin)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "EmployeeAdmin";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.EmployeeAdmins.Add(employeeAdmin);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "EmployeeName", employeeAdmin.EmployeeID);
            return(View(employeeAdmin));
        }
コード例 #8
0
        public ActionResult Create([Bind(Include = "ID,CityName,CountryID")] City city)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "City";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryID = new SelectList(db.Countries, "ID", "CountryName", city.CountryID);
            return(View(city));
        }
コード例 #9
0
        public ActionResult Create([Bind(Include = "ID,EmployeeID,EmployeeSalary,SalaryMonth,SalaryReciveDate")] EpmloyeeSalary epmloyeeSalary)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "EmployeeSalary";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.EpmloyeeSalaries.Add(epmloyeeSalary);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeID = new SelectList(db.Employees, "ID", "EmployeeName", epmloyeeSalary.EmployeeID);
            return(View(epmloyeeSalary));
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "ID,CustomerID,ProductID,Price,Quantity,TotalPrice")] Purchase purchase)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "Purchase";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.Purchases.Add(purchase);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CustomerID = new SelectList(db.Customers, "ID", "CustomerName", purchase.CustomerID);
            ViewBag.ProductID  = new SelectList(db.Products, "ID", "ProductName", purchase.ProductID);
            return(View(purchase));
        }
コード例 #11
0
        public ActionResult Create([Bind(Include = "ID,ProductName,ProductCode,ProductQuentity,ProductDescription,ProductPosition,CategoryID,BrandID")] Product product)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "Product";
                return(RedirectToAction("Login", "Employee"));
            }

            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BrandID    = new SelectList(db.Brands, "ID", "BrandName", product.BrandID);
            ViewBag.CategoryID = new SelectList(db.Categories, "ID", "CategoryName", product.CategoryID);
            return(View(product));
        }
コード例 #12
0
        public ActionResult Create(ProductImage productImage, HttpPostedFileBase PI)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "ProductImage";
                return(RedirectToAction("Login", "Employee"));
            }

            productImage.ProductImage1 = System.IO.Path.GetFileName(PI.FileName);

            if (ModelState.IsValid)
            {
                db.ProductImages.Add(productImage);
                db.SaveChanges();
                PI.SaveAs(Server.MapPath("../Images/ProductImage/" + productImage.ID.ToString() + "_" + productImage.ProductImage1));
                return(RedirectToAction("Index"));
            }

            ViewBag.ProductID = new SelectList(db.Products, "ID", "ProductName", productImage.ProductID);
            return(View(productImage));
        }
コード例 #13
0
        public ActionResult Create(Employee employee, HttpPostedFileBase EmployeePicture)
        {
            if (Session["type"] == null || Session["type"].ToString() == "")
            {
                Session["DefaultView"]     = "Create";
                Session["DefaultControll"] = "Employee";
                return(RedirectToAction("Login"));
            }

            employee.EmployeeJoinDate = DateTime.Now;
            employee.EmployeePicture  = System.IO.Path.GetFileName(EmployeePicture.FileName);

            if (ModelState.IsValid)
            {
                db.Employees.Add(employee);
                db.SaveChanges();
                EmployeePicture.SaveAs(Server.MapPath("../Images/Uploads/" + employee.ID.ToString() + "_" + employee.EmployeePicture));
                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeCityID = new SelectList(db.Cities, "ID", "CityName", employee.EmployeeCityID);
            ViewBag.ID             = new SelectList(db.EmployeeAdmins, "EmployeeID", "EmployeeID", employee.ID);
            return(View(employee));
        }