コード例 #1
0
        public ActionResult placeOrder(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("alert"));
            }

            InventoryProductList products = new InventoryProductList();

            products.inventory = db.Products.ToList().Where(x => x.SupplierId == id && x.quantityOnHand < x.minimumStock).ToList();
            return(View(products));
        }
コード例 #2
0
        public ActionResult placeOrder(InventoryProductList model)
        {
            var checkinSelected = model.inventory.Where(a => a.isOrdered == true).ToList();

            if (checkinSelected == null || checkinSelected.Count < 1)
            {
                return(RedirectToAction("Alert"));
            }

            var    selectedProd    = model.inventory.Where(x => x.isOrdered == true).ToList();
            string productsOrdered = "";
            string supplierName    = "";
            string suplierEmail    = "";
            string managerEmail    = User.Identity.GetUserName();

            foreach (InventoryProduct v in selectedProd)
            {
                OrderSupply o = new OrderSupply();
                o.supplierEmail  = db.Suppliers.ToList().Where(x => x.supplierid == v.SupplierId).FirstOrDefault().supplierEmail;
                o.supplier       = db.Suppliers.ToList().Where(x => x.supplierid == v.SupplierId).FirstOrDefault().supplierName;
                o.suplyNum       = db.Suppliers.ToList().Where(x => x.supplierid == v.SupplierId).FirstOrDefault().supplierNumber;
                o.itemQty        = db.Products.ToList().Where(x => x.productId == v.productId).FirstOrDefault().quantityToOrder;
                o.totalOrder     = (db.Products.ToList().Where(x => x.productId == v.productId).FirstOrDefault().quantityToOrder) * (db.Products.ToList().Where(x => x.productId == v.productId).FirstOrDefault().prevUnitPrice);
                o.dateOrdered    = DateTime.Now.ToString();
                o.ProductsList   = db.Products.ToList().Where(x => x.productId == v.productId).FirstOrDefault().productName;
                o.status         = "Pending";
                o.isOrdered      = true;
                o.orderedBy      = User.Identity.GetUserName();
                suplierEmail     = db.Suppliers.ToList().Where(x => x.supplierid == v.SupplierId).FirstOrDefault().supplierEmail;
                supplierName     = db.Suppliers.ToList().Where(x => x.supplierid == v.SupplierId).FirstOrDefault().supplierName;
                productsOrdered += $" { o.ProductsList} ({o.itemQty}), ";
                InventoryProduct pp = db.Products.ToList().Where(x => x.productId == v.productId).FirstOrDefault();
                pp.status = "Ordered";
                db.OrderSupplies.Add(o);
                db.SaveChanges();
            }
            if (suplierEmail != null)
            {
                string msg = $"Hi {supplierName}. We would like to order the following products { productsOrdered } Contact us at [email protected] for enquiries.";
                emailhelper.sendMail(suplierEmail, "Placing new order", msg);
                string newMsg = $"Hi you have placed an order to { supplierName} for the following products { productsOrdered } Contact us at [email protected] for enquiries.";
                emailhelper.sendMail(managerEmail, "Placed new order", newMsg);
            }
            return(View("addProdSuc"));
        }