public object updateCusOrderStatuses(int id, string description) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); try { Customer_Order_Status newStatus = db.Customer_Order_Status.Where(x => x.CustomerOrderStatusID == id).FirstOrDefault(); newStatus.CODescription = description; db.SaveChanges(); toReturn.Message = "Customer Order Status Update Successful"; } catch { toReturn.Error = "Customer Order Status Update Unsuccessful"; } return(toReturn); }
public object deleteCusOrderStatuses(int id) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); try { Customer_Order_Status newStatus = db.Customer_Order_Status.Where(x => x.CustomerOrderStatusID == id).FirstOrDefault(); db.Customer_Order_Status.Remove(newStatus); db.SaveChanges(); toReturn.Message = "Customer Order Status Delete Successful"; } catch { toReturn.Error = "Customer Order Status Delete Unsuccessful"; } return(toReturn); }
public object addCusOrderStatuses(string description) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); try { Customer_Order_Status newStatus = new Customer_Order_Status(); newStatus.CODescription = description; db.Customer_Order_Status.Add(newStatus); db.SaveChanges(); toReturn.Message = "Customer Order Status Added Successfully"; } catch { toReturn.Error = "Customer Order Status Add Unsuccessful"; } return(toReturn); }
public dynamic placeOrder(Customer_Order order) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); toReturn.newOrder = new ExpandoObject(); string newOrderNo = ""; try { //Get Product Order Line Details from order List <Product_Order_Line> productList = order.Product_Order_Line.ToList(); if (order != null && productList != null) { Customer customer = db.Customers.Where(x => x.CustomerID == order.CustomerID).FirstOrDefault(); User user = db.Users.Where(x => x.UserID == order.UserID).FirstOrDefault(); Container con = db.Containers.Where(x => x.ContainerID == order.ContainerID).FirstOrDefault(); Customer_Order_Status order_Status = db.Customer_Order_Status.Where(x => x.CODescription == "Placed").FirstOrDefault(); //save customer order details Customer_Order customerOrder = new Customer_Order(); customerOrder.Customer = customer; customerOrder.Customer_Order_Status = order_Status; customerOrder.User = user; customerOrder.Container = con; customerOrder.CusOrdNumber = order.CusOrdNumber; customerOrder.CusOrdDate = DateTime.Now; db.Customer_Order.Add(customerOrder); db.SaveChanges(); //Get The Saved Order details form the db Customer_Order placedOrder = db.Customer_Order.ToList().LastOrDefault(); if (placedOrder != null) { //Add the Product_Order_Line Records for each product foreach (var prod in productList) { Product product = db.Products.Where(x => x.ProductID == prod.ProductID).FirstOrDefault(); Product_Order_Line orderProd = new Product_Order_Line(); orderProd.Customer_Order = placedOrder; orderProd.Product = product; orderProd.PLQuantity = prod.PLQuantity; db.Product_Order_Line.Add(orderProd); db.SaveChanges(); } //Get the placed Orders Order Number newOrderNo = placedOrder.CusOrdNumber; } else { toReturn.Message = "Something went wrong adding the products!"; } //Set the return Objects toReturn.newOrder = searchByOrderNo(newOrderNo); toReturn.Message = "Success! Order was placed successfully and email confirmation sent."; } else { toReturn.Message = " Null Parameters Received"; } } catch (Exception error) { toReturn.Message = error.Message; } return(toReturn); }
public object initiatePlaceOrder(int customerID, dynamic session) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); toReturn.customer = new ExpandoObject(); toReturn.orderInfo = new ExpandoObject(); toReturn.products = new ExpandoObject(); try { Container con = new Container(); //get container of current user string sessionID = session.token; var user = db.Users.Where(x => x.SessionID == sessionID).FirstOrDefault(); if (user.ContainerID == null) { return(toReturn.Error = ("Curent Container Not Found")); } con = db.Containers.Where(x => x.ContainerID == user.ContainerID).FirstOrDefault(); if (con == null) { return(toReturn.Error = ("Curent Container Not Found")); } //get products in container List <Container_Product> conProd = db.Container_Product.Include(x => x.Product).Where(x => x.CPQuantity < 1 && x.ContainerID == con.ContainerID).ToList(); //get customer details Customer customer = new Customer(); customer = db.Customers.Where(x => x.CustomerID == customerID).FirstOrDefault(); toReturn.customer = customer; if (customer != null) { //Get Order No Customer_Order prevOrder = db.Customer_Order.ToList().LastOrDefault(); Customer_Order prevID = db.Customer_Order.ToList().LastOrDefault(); int prevOrderNo = Convert.ToInt32(prevOrder.CusOrdNumber); int OrderNo = prevOrderNo + 1; //Get Todays date var orderDate = DateTime.Now.ToString("yyyy-MM-dd"); //Set Order No And Order Date In Dynamic Object dynamic orderInfo = new ExpandoObject(); orderInfo.OrderNo = OrderNo; orderInfo.OrderDate = orderDate; orderInfo.VatPerc = db.VATs.Where(x => x.VATStartDate <= DateTime.Now).ToList().LastOrDefault(); toReturn.orderInfo = orderInfo; //Get List Of products with current price List <Product> productsList = db.Products.ToList(); List <dynamic> products = new List <dynamic>(); foreach (var prod in conProd) { Price price = db.Prices.Include(x => x.Product).Where(x => x.PriceStartDate <= DateTime.Now && x.PriceEndDate >= DateTime.Now && x.ProductID == prod.ProductID).FirstOrDefault(); if (price != null) { double Price = (double)price.UPriceR; dynamic productDetails = new ExpandoObject(); productDetails.ProductCategoryID = prod.Product.ProductCategoryID; productDetails.ProductID = prod.ProductID; productDetails.ProdDescription = prod.Product.ProdDesciption; productDetails.Prodname = prod.Product.ProdName; productDetails.Quantity = 0; productDetails.Price = Math.Round(Price, 2); productDetails.Subtotal = 0.0; products.Add(productDetails); } } toReturn.products = products; toReturn.VAT = db.VATs.Where(x => x.VATStartDate <= DateTime.Now).ToList().LastOrDefault(); Customer_Order_Status order_Status = db.Customer_Order_Status.Where(x => x.CODescription == "Placed").FirstOrDefault(); //set up sale Customer_Order customerOrder = new Customer_Order(); customerOrder.Customer = customer; customerOrder.Customer_Order_Status = order_Status; customerOrder.UserID = user.UserID; customerOrder.User = user; customerOrder.Container = con; customerOrder.ContainerID = con.ContainerID; customerOrder.CusOrdNumber = Convert.ToString(OrderNo); customerOrder.CusOrdDate = DateTime.Now; db.Customer_Order.Add(customerOrder); db.SaveChanges(); toReturn.CustomerOrder = db.Customer_Order.ToList().LastOrDefault(); orderInfo.CustomerOrderID = customerOrder.CustomerOrderID; } else { toReturn.Message = "No products were found. All products seem to be in stock."; } } catch (Exception error) { toReturn.Message = error.Message; } return(toReturn); }
public object updateCustomerOrder(int containerID, int supplierOrderID) { db.Configuration.ProxyCreationEnabled = false; dynamic toReturn = new ExpandoObject(); bool fulfilled = false; try { Supplier_Order_Status delivered = db.Supplier_Order_Status.Where(x => x.SupplierOrderStatusID == 3).FirstOrDefault(); Supplier_Order suporder = db.Supplier_Order.Where(x => x.SupplierOrderID == supplierOrderID).FirstOrDefault(); if (suporder != null && delivered != null) { suporder.SupplierOrderStatusID = delivered.SupplierOrderStatusID; suporder.Supplier_Order_Status = delivered; db.SaveChanges(); } Customer_Order_Status status = db.Customer_Order_Status.Where(x => x.CustomerOrderStatusID == 2).FirstOrDefault(); List <Customer_Order> orders = db.Customer_Order.Where(x => x.CustomerOrderStatusID == 1 && x.ContainerID == containerID).ToList(); if (orders.Count != 0) { foreach (Customer_Order order in orders) { List <Product_Order_Line> product_Orders = db.Product_Order_Line.Where(x => x.CustomerOrderID == order.CustomerOrderID).ToList(); if (product_Orders.Count != 0) { foreach (Product_Order_Line product in product_Orders) { Container_Product prod = db.Container_Product.Where(x => x.ProductID == product.ProductID && x.ContainerID == containerID).FirstOrDefault(); if (prod != null) { if (product.PLQuantity <= prod.CPQuantity) { fulfilled = true; } else { fulfilled = false; } } } } if (fulfilled == true) { order.CustomerOrderStatusID = status.CustomerOrderStatusID; order.Customer_Order_Status = status; db.SaveChanges(); } } } toReturn.Message = "Stock Received And Recorded Successfuly"; } catch { toReturn.Error = "No Orders Found"; } return(toReturn); }