Esempio n. 1
0
        public async Task <ActionResult> DeleteCartItem(int id)
        {
            int status = 0;

            inv_RequestCart RequestCartItem = db.inv_RequestCart.Find(id);
            var             CartQuantity    = RequestCartItem.ItemQuantity;


            // Get Item Old Quantity from inventroy
            var Item = db.inv_Items.Where(I => I.ItemID == RequestCartItem.ItemID).FirstOrDefault();
            var InventroyQuantity = Item.ItemQuantity;

            // Update Item  Quantity in  inventroy
            Item.ItemQuantity = (int)InventroyQuantity + (int)CartQuantity;
            await db.SaveChangesAsync();;


            // Delete Item from request cart
            db.inv_RequestCart.Remove(RequestCartItem);
            await db.SaveChangesAsync();


            status = 1;
            return(new JsonResult {
                Data = new { status = status }
            });;
        }
Esempio n. 2
0
        public async Task <JsonResult> InsertInvertoryCart(inv_RequestCart RequestCart, int?RequestType)
        {
            // Get item details from items table
            var Item = db.inv_Items.Where(I => I.ItemID == RequestCart.ItemID).FirstOrDefault();
            var ItemInventoryOldQuantity = Item.ItemQuantity;
            // Get item details from items table

            // Salse Cart Item
            var v = db.inv_RequestCart.Where(I => I.ItemID == RequestCart.ItemID && I.RequestType == RequestType).FirstOrDefault();
            // Salse Cart Item

            int status     = 0;
            var newQnatity = RequestCart.ItemQuantity;

            if ((ItemInventoryOldQuantity - newQnatity) >= 0)
            {
                // Update item in sales cart
                if (v != null)
                {
                    var cartOldQuantity = v.ItemQuantity;
                    v.ItemQuantity = cartOldQuantity + RequestCart.ItemQuantity;

                    var TotalItemsPrice = (cartOldQuantity + RequestCart.ItemQuantity) * Item.ItemSalePrice;
                    v.TotalItemsPrice = TotalItemsPrice;
                    await db.SaveChangesAsync();

                    status = 1;  // success
                }

                // insert new item in sales cart
                else
                {
                    RequestCart.ItemPrice       = Item.ItemSalePrice;
                    RequestCart.RequestType     = RequestType;
                    RequestCart.TotalItemsPrice = RequestCart.ItemQuantity * Item.ItemSalePrice;

                    db.inv_RequestCart.Add(RequestCart);
                    await db.SaveChangesAsync();

                    status = 1; // success
                }
            }


            // New Quantity > inventory Quantity
            else
            {
                status = 3;  // errror
            }



            return(new JsonResult {
                Data = new { status = status }
            });

            //return Json(SalesCart);
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            inv_RequestCart inv_RequestCart = await db.inv_RequestCart.FindAsync(id);

            db.inv_RequestCart.Remove(inv_RequestCart);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Edit([Bind(Include = "RequestCartID,ItemID,ItemName,ItemQuantity,ItemPrice,TotalItemsPrice,RequestType,RequestCartDate")] inv_RequestCart inv_RequestCart)
        {
            if (ModelState.IsValid)
            {
                db.Entry(inv_RequestCart).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(inv_RequestCart));
        }
Esempio n. 5
0
        public async Task <ActionResult> Create([Bind(Include = "RequestCartID,ItemID,ItemName,ItemQuantity,ItemPrice,RequestCartDate")] inv_RequestCart inv_RequestCart)
        {
            if (ModelState.IsValid)
            {
                db.inv_RequestCart.Add(inv_RequestCart);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(inv_RequestCart));
        }
        // GET: CustomerFromInventory/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            inv_RequestCart inv_RequestCart = await db.inv_RequestCart.FindAsync(id);

            if (inv_RequestCart == null)
            {
                return(HttpNotFound());
            }
            return(View(inv_RequestCart));
        }
Esempio n. 7
0
        public async Task <JsonResult> UpdatetRequestCart(inv_RequestCart RequestCart, decimal TotalItemsPrice, int RequestCartID)
        {
            var v = db.inv_RequestCart.Where(I => I.RequestCartID == RequestCartID).FirstOrDefault();


            // Get item details from items table
            var Item = db.inv_Items.Where(I => I.ItemID == RequestCart.ItemID).FirstOrDefault();
            var ItemInventoryQuantity = Item.ItemQuantity;
            var CartOldQuantity       = v.ItemQuantity;
            // Get item details from items table

            int status = 0;

            // Depet (+) Update
            if (RequestCart.ItemQuantity > CartOldQuantity)
            {
                var newQuantity = RequestCart.ItemQuantity + CartOldQuantity;

                // Check Item Quantity in Inventory
                if (ItemInventoryQuantity - newQuantity >= 0)
                {
                    v.ItemQuantity    = RequestCart.ItemQuantity;
                    v.TotalItemsPrice = TotalItemsPrice;
                    await db.SaveChangesAsync();;

                    status = 1;
                }

                // Cart Quantity > Item Quantity
                else
                {
                    status = 3;
                }
            }


            // Cart quantity > new quantity (-)
            else if (CartOldQuantity > RequestCart.ItemQuantity)
            {
                var newQuantity = CartOldQuantity - RequestCart.ItemQuantity;
                if (ItemInventoryQuantity - newQuantity >= 0)
                {
                    v.ItemQuantity    = RequestCart.ItemQuantity;
                    v.TotalItemsPrice = TotalItemsPrice;
                    await db.SaveChangesAsync();

                    status = 1;
                }
                else
                {
                    status = 3;
                }
            }

            else
            {
                status = 1;
            }


            return(new JsonResult {
                Data = new { status = status }
            });

            //return Json(SalesCart);
        }