public IHttpActionResult CompleteOrder(int OrderID) { if (OrderDataValidation.ValidateOpenOrder(OrderID)) { if (!CartDataValidation.ValidateEmptyCart(OrderID)) { using (ShoppingEntities entity = new ShoppingEntities()) { using (ShoppingDiscount total = new ShoppingDiscount()) { entity.Orders.First(o => o.O_ID == OrderID).O_TotalAmount = total.TotalAfterDiscount(OrderID); entity.Orders.First(o => o.O_ID == OrderID).O_Status = ShoppingData.CloseOrderStatus; entity.SaveChanges(); return(Ok("Total Amount after Discount = " + total.TotalAfterDiscount(OrderID))); } } } else { return(BadRequest("There is no item in cart")); } } else { return(BadRequest("Invalid OrderID")); } }
public IHttpActionResult RemoveProductFromCart(int OrderID, int ProductID) { if (OrderDataValidation.ValidateOpenOrder(OrderID)) { if (ShoppingData.ProductList().Any(p => p.P_ID == ProductID)) { using (ShoppingEntities entities = new ShoppingEntities()) { if (entities.Cart.Any(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID)) { int NoOfItems = entities.Cart.Where(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).First().C_Count; if (NoOfItems > 0) { NoOfItems = NoOfItems - 1; entities.Cart.First(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).C_Count = NoOfItems; entities.SaveChanges(); return(Ok("1 Item removed from Cart")); } else { return(BadRequest("0 items in Cart")); } } else { return(BadRequest("Items not present in Cart")); } } } else { return(BadRequest("Invalid Product ID")); } } else { return(BadRequest("Invalid OrderID")); } }
public IHttpActionResult CheckOutOrder(int OrderID) { if (OrderDataValidation.ValidateOpenOrder(OrderID)) { if (CartDataValidation.ValidateEmptyCart(OrderID)) { return(BadRequest("There is no item in Cart")); } else { using (ShoppingDiscount total = new ShoppingDiscount()) { return(Ok("Total Amount after Discount = " + total.TotalAfterDiscount(OrderID))); } } } else { return(BadRequest("Invalid OrderID")); } }
public IHttpActionResult AddProductToCart(int OrderID, int ProductID) { if (OrderDataValidation.ValidateOpenOrder(OrderID)) { if (ShoppingData.ProductList().Any(p => p.P_ID == ProductID)) { using (ShoppingEntities entities = new ShoppingEntities()) { if (entities.Cart.Any(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID)) { int NoOfItems = entities.Cart.Where(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).First().C_Count; NoOfItems = NoOfItems + 1; entities.Cart.First(c => c.C_OrderID == OrderID && c.C_ProductID == ProductID).C_Count = NoOfItems; entities.SaveChanges(); } else { entities.Cart.Add(new Cart { C_OrderID = OrderID, C_ProductID = ProductID, C_Count = 1 }); entities.SaveChanges(); } return(Ok("Item added in Cart")); } } else { return(BadRequest("Invalid Product ID")); } } else { return(BadRequest("Invalid OrderID")); } }