Beispiel #1
0
        public ActionResult ConfirmOrder(ProductSelection products, [Bind(Include = "Id,OrderCost,ProductId,QtyOrdered,LastEditUser,LastEditDateTime")] OrderProduct orderProduct, Order orders)
        {
            var  inventory     = dbITInventory.Products.ToList();
            bool successful    = false;
            var  orderList     = dbITInventory.Orders.ToList();
            var  orderProds    = dbITInventory.OrderProducts.ToList();
            var  lastUserOrder = orderProds.Where(x => x.LastEditUser == HDUtilities.UserInformation.GetCurrentUserName() && x.Order.Submitted != true);
            var  lastOrderId   = lastUserOrder.FirstOrDefault().OrderId;

            foreach (var order in orderProds.Where(r => r.OrderId == lastOrderId))
            {
                inventory.Where(r => r.Id == order.ProductId).FirstOrDefault().OnOrder += order.Quantity;
            }

            orderList.Where(r => r.Id == lastOrderId).FirstOrDefault().Submitted = true;

            foreach (var order in lastUserOrder)
            {
                order.Order.Submitted = true;
            }

            try
            {
                dbITInventory.SaveChanges();
                successful = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(new { Result = successful }, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult CreateKit(ProductSelection KitBuild, Product products, Kit Kits, KitProduct KitProducts)
        {
            bool successful = false;
            var  kitList    = db.Kits.ToList();
            var  kitId      = 0;

            if (kitList.FirstOrDefault().Id != null)
            {
                kitId                 = kitList.Max(r => r.Id) + 1;
                Kits.KitName          = KitBuild.KitName;
                Kits.LastEditDateTime = DateTime.Now;
                Kits.LastEditUser     = HDUtilities.UserInformation.GetCurrentUserName();
            }
            else
            {
                kitId                 = 1;
                Kits.KitName          = KitBuild.KitName;
                Kits.LastEditDateTime = DateTime.Now;
                Kits.LastEditUser     = HDUtilities.UserInformation.GetCurrentUserName();
            }
            db.Kits.Add(Kits);
            db.SaveChanges();

            for (var x = 0; x < KitBuild.productList.Length; x++)
            {
                KitProducts.KitId            = kitId;
                KitProducts.ProductId        = Convert.ToInt32(KitBuild.productList[x]);
                KitProducts.Quantity         = Convert.ToInt32(KitBuild.orderQty[x]);
                KitProducts.LastEditDateTime = DateTime.Now;
                KitProducts.LastEditUser     = HDUtilities.UserInformation.GetCurrentUserName();
                //decimal prodPrice =  db.Products.Where(r => r.Id == KitProducts.ProductId).FirstOrDefault().SellPrice;
                //kitPrice += Convert.ToDecimal(KitBuild.orderQty[x]) * prodPrice;
                try
                {
                    db.KitProducts.Add(KitProducts);
                    db.SaveChanges();
                    successful = true;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            products.ProductName = KitBuild.KitName;
            products.SKU         = "kit";
            //products.SellPrice = kitPrice;
            products.Weight           = 0;
            products.WeightUnit       = "lbs";
            products.PackageWeight    = 0;
            products.PackageLength    = 0;
            products.PackageHeight    = 0;
            products.PackageUnits     = "lbs";
            products.CategoryId       = 1;
            products.QtyPerPackage    = 0;
            products.DefaultOrderSize = 0;
            products.VendorId         = 1;
            products.OnOrder          = 0;
            products.StockLevel       = 20;
            products.ReorderThreshold = 0;
            products.IsKit            = true;
            products.KitId            = kitId;
            products.Active           = true;
            products.LastOrderedDate  = DateTime.Now;
            products.LastEditDateTime = DateTime.Now;
            products.LastEditUser     = HDUtilities.UserInformation.GetCurrentUserName();
            try
            {
                db.Products.Add(products);
                db.SaveChanges();
                successful = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }


            return(Json(new { Result = successful }, JsonRequestBehavior.AllowGet));
        }