예제 #1
0
        public Models.Order CreateNewOrderWithSupplierWithFirstOrderDetail(ADProjectDb db, int empId, string supplier, int itemId)
        {
            Supplier      selectedSupplier = GetSupplierByName(db, supplier);
            ItemCatalogue firstitem        = GetItemCatalogue(db, itemId);
            // create new PO object with SupplierId and EmpId
            OrderStatus orderStatusDraft = db.OrderStatus.Where(x => x.OrderStatusId == 1).FirstOrDefault();

            ADProject.Models.Order newOrder = new ADProject.Models.Order()
            {
                EmpId = empId, SupplierId = selectedSupplier.SupplierId, Supplier = selectedSupplier, OrderStatus = orderStatusDraft
            };
            db.Order.Add(newOrder);
            //Need to save changes first so that the new order id will be generated
            db.SaveChanges();
            // Get back the last added order, need its orderId
            newOrder = db.Order.OrderByDescending(o => o.OrderId).FirstOrDefault();
            //Get the reordering qty
            var reorder = db.StockInfo.Where(x => x.ItemCatalogueId == itemId).FirstOrDefault().ReOrderQuantity;
            // Create and add the new orderdetail, qty is the default restock quantity
            OrderDetail firstOd = new OrderDetail()
            {
                OrderId = newOrder.OrderId, ItemId = itemId, ItemCatalogue = firstitem, OrderQuantity = reorder
            };

            db.OrderDetail.Add(firstOd);
            newOrder.OrderDetails = new List <OrderDetail>();
            newOrder.OrderDetails.Add(firstOd);
            db.SaveChanges();
            return(newOrder);
        }
예제 #2
0
 public void DeleteOrder(ADProjectDb db, int orderId)
 {
     // get the Order to delete and commit
     ADProject.Models.Order toDelete = db.Order.Where(x => x.OrderId == orderId).FirstOrDefault();
     db.Order.Remove(toDelete);
     db.SaveChanges();
 }
예제 #3
0
        public void AddOrderDetailtoOrder(ADProjectDb db, int orderId, int itemId, int orderQty)
        {
            //Create Orderdetail object
            OrderDetail toAdd = new OrderDetail()
            {
                OrderId = orderId, ItemId = itemId, OrderQuantity = orderQty
            };

            db.OrderDetail.Add(toAdd);

            //Get that order and add orderdetail to it
            ADProject.Models.Order orderToAddto = db.Order.Where(x => x.OrderId == orderId).FirstOrDefault();

            if (orderToAddto != null)
            {
                if (orderToAddto.OrderDetails == null)
                {
                    orderToAddto.OrderDetails = new List <OrderDetail>();
                }
                orderToAddto.OrderDetails.Add(toAdd);
            }
            db.SaveChanges();
        }