public Result CreateTheOrder(OETLib.BusinessObjects.Model.ProductList productlist) { Result webRes = new Result(false); try { foreach (OETLib.BusinessObjects.Model.Product product in productlist) { if (product.ProductQuantity != 0) { var order = new OETLib.BusinessObjects.Model.Order(); order.UserID = Singular.Settings.CurrentUserID; order.OrderDate = DateTime.Now; order.ProcessStatusID = 1; order.RequiredDate = order.OrderDate = DateTime.Now; //Save the order var savedToOrder = order.TrySave(typeof(OETLib.BusinessObjects.Model.OrderList)); //Return the just saved OrderID var newOrder = new OETLib.BusinessObjects.Model.Order(); newOrder = GetOrder(Singular.Settings.CurrentUserID); //Create orderDetail var orderDetail = new OETLib.BusinessObjects.Model.OrderDetail(); orderDetail.OrderID = newOrder.OrderID; orderDetail.ProductID = product.ProductID; orderDetail.ProductQuantity = product.ProductQuantity; orderDetail.UnitPrice = (decimal)product.LinePrice; //Save newly created OrderDetail var saveToOrderDetail = orderDetail.TrySave(typeof(OETLib.BusinessObjects.Model.OrderDetailList)); // Get the productId to be able to update the correct inventory var Inventory_product = OETLib.BusinessObjects.Model.InventoryList.GetInventoryList().LastOrDefault(d => d.ProductID == product.ProductID); var Inventory_record = new OETLib.BusinessObjects.Model.Inventory(); //Set inventory elements Inventory_record.ProductID = product.ProductID; Inventory_record.InventoryQuantity = -product.ProductQuantity; Inventory_record.CurrentInventoryQuantity = Inventory_product.CurrentInventoryQuantity - product.ProductQuantity; Inventory_record.InventoryItemCost = Inventory_product.InventoryItemCost; Inventory_record.InventoryTypeID = 2; Inventory_record.OrderID = newOrder.OrderID; //Try and safe the new inventory record Inventory_record.TrySave(typeof(OETLib.BusinessObjects.Model.InventoryList)); OETLib.BusinessObjects.Model.myCartList mycartlist = OETLib.BusinessObjects.Model.myCartList.GetmyCartList(Singular.Settings.CurrentUserID); } } webRes.Success = true; OETLib.BusinessObjects.Model.EditInventoryList inventorylist = OETLib.BusinessObjects.Model.EditInventoryList.GetEditInventoryList(); webRes.Data = inventorylist; } catch { webRes.ErrorText = "There was an error adding your orderr"; } return(webRes); }
public Result ExpireOrder(OETLib.BusinessObjects.Model.UserOrdersList orderlist) { Result webRes = new Result(false); try { //Order, OrderDetail,Inventory objects OETLib.BusinessObjects.Model.Order expiredOrder = new OETLib.BusinessObjects.Model.Order(); OETLib.BusinessObjects.Model.OrderDetail expiredOrderDetail = new OETLib.BusinessObjects.Model.OrderDetail(); OETLib.BusinessObjects.Model.Inventory expiredInventory = new OETLib.BusinessObjects.Model.Inventory(); OETLib.BusinessObjects.Model.Inventory InventoryProduct = new OETLib.BusinessObjects.Model.Inventory(); foreach (OETLib.BusinessObjects.Model.UserOrders item in orderlist) { DateTime now = DateTime.Now; DateTime orderDate = Convert.ToDateTime(item.OrderDate); if ((now - orderDate).TotalMinutes >= (60) && !((now - orderDate).TotalMinutes < 60))//(1/2) { expiredOrder = OETLib.BusinessObjects.Model.OrderList.GetOrderList().LastOrDefault(d => d.OrderID == item.OrderID); expiredOrderDetail = OETLib.BusinessObjects.Model.OrderDetailList.GetOrderDetailList().LastOrDefault(d => d.OrderID == item.OrderID); // Chnage the OrderStatus of the order expiredOrder.ProcessStatusID = 3; expiredOrder.TrySave(typeof(OETLib.BusinessObjects.Model.OrderList)); //Delete order from OrderDetail OETLib.BusinessObjects.Model.OrderDetailList orderDetailList = OETLib.BusinessObjects.Model.OrderDetailList.GetOrderDetailList(); orderDetailList.Remove(expiredOrderDetail); orderDetailList.Save(); //Create new Inventory record that reflects the canceled/expired order InventoryProduct = OETLib.BusinessObjects.Model.InventoryList.GetInventoryList().LastOrDefault(d => d.ProductID == item.ProductID); expiredInventory.ProductID = item.ProductID; expiredInventory.InventoryQuantity = item.ProductQuantity; expiredInventory.CurrentInventoryQuantity = InventoryProduct.CurrentInventoryQuantity + item.ProductQuantity; expiredInventory.InventoryItemCost = InventoryProduct.InventoryItemCost; expiredInventory.InventoryTypeID = 4; expiredInventory.TrySave(typeof(OETLib.BusinessObjects.Model.InventoryList)); item.ProcessStatusID = 2; OETLib.BusinessObjects.Model.UserOrdersList userorderlist = OETLib.BusinessObjects.Model.UserOrdersList.GetUserOrdersList(1); webRes.Data = userorderlist; webRes.Success = true; } } } catch (Exception e) { webRes.ErrorText = e.Message;// "There was an error adding your order"; } return(webRes); }
public Result CreateOrder(OETLib.BusinessObjects.Model.Product product) { Result webREs = new Result(false); try { // Create the order var order = new OETLib.BusinessObjects.Model.Order(); OrderProduct = OETLib.BusinessObjects.Model.ProductList.GetProductList().FirstOrDefault(d => d.ProductID == product.ProductID); var orderdate = new DateTime(); orderdate = DateTime.Now; var requireddate = new DateTime(); requireddate = DateTime.Now; order.UserID = Singular.Settings.CurrentUserID; order.OrderDate = orderdate; order.ProcessStatusID = 1; order.RequiredDate = requireddate; // Save the order var savedToOrder = order.TrySave(typeof(OETLib.BusinessObjects.Model.OrderList)); // Return the just saved OrderID var newOrder = new OETLib.BusinessObjects.Model.Order(); newOrder = GetOrder(Singular.Settings.CurrentUserID); // Create orderDetail var orderDetail = new OETLib.BusinessObjects.Model.OrderDetail(); orderDetail.OrderID = newOrder.OrderID; orderDetail.ProductID = OrderProduct.ProductID; orderDetail.ProductQuantity = product.ProductQuantity; orderDetail.UnitPrice = product.ProductPrice; // Save newly created OrderDetail webREs.Success = true; webREs.Data = orderDetail; } catch { webREs.ErrorText = "There was an error adding your order"; } return(webREs); }