public List <VendorProducts> GetVendorProducts(int vendorid)
 {
     using (var context = new eRaceContext())
     {
         var result = from a in context.VendorCatalogs
                      where a.VendorID == vendorid
                      group a by a.Product.Category.Description into GB1
                      select new VendorProducts
         {
             CategoryName = GB1.Key,
             Items        = from x in GB1
                            where !(from q in context.Orders
                                    where q.VendorID == vendorid && q.OrderNumber == null
                                    from w in q.OrderDetails
                                    select w.ProductID
                                    ).Contains(x.ProductID)
                            select new VendorCatalogInfo
             {
                 Category        = x.Product.Category.Description,
                 ProductID       = x.ProductID,
                 ProductName     = x.Product.ItemName,
                 ItemCost        = x.Product.ItemPrice,
                 ReorderQty      = x.Product.ReOrderLevel,
                 QuantityOnHand  = x.Product.QuantityOnHand,
                 QuantityOnOrder = x.Product.QuantityOnOrder,
                 UnitSize        = x.OrderUnitSize
             }
         };
         return(result.ToList());
     }
 }
 public UnOrderedItem UnOrderdItem_GetItemID(int itemid)
 {
     using (var context = new eRaceContext())
     {
         return(context.UnOrderedItems.Find(itemid));
     }
 }
 public Employee Employee_Get(int employeeid)
 {
     using (var context = new eRaceContext())
     {
         return(context.Employees.Find(employeeid));
     }
 }
 public List <UnOrderedItem> List_GetUnorderedItems()
 {
     using (var context = new eRaceContext())
     {
         return(context.UnOrderedItems.ToList());
     }
 }
示例#5
0
        public void AddItemToCart(int productID, int quantity, int EmployeeId)
        {
            using (var context = new eRaceContext())
            {
                var exists = (from item in context.SalesCartItems where item.EmployeeID == EmployeeId && item.ProductID == productID select item).FirstOrDefault();

                if (exists == null)
                {
                    SalesCartItem inCart = new SalesCartItem();

                    inCart.EmployeeID = EmployeeId;
                    inCart.ProductID  = productID;
                    inCart.Quantity   = quantity;
                    context.SalesCartItems.Add(inCart);
                }
                else
                {
                    var newQty = context.SalesCartItems.Where(x => x.EmployeeID == EmployeeId && x.ProductID == productID).FirstOrDefault();

                    newQty.Quantity += quantity;
                }

                context.SaveChanges();
            }
        }
        public int Pay_ForCart(NewInvoice invoice)
        {
            using (var context = new eRaceContext())
            {
                Invoice newitem = new Invoice();
                newitem.EmployeeID  = invoice.EmployeeID;
                newitem.InvoiceDate = invoice.InvoiceDate;
                newitem.SubTotal    = invoice.Subtotal;
                newitem.GST         = invoice.GST;
                newitem.Total       = invoice.Total;

                newitem = context.Invoices.Add(newitem);


                InvoiceDetail newDetail = null;
                foreach (var item in invoice.NewDetails)
                {
                    newDetail           = new InvoiceDetail();
                    newDetail.ProductID = item.ProductID;
                    newDetail.Quantity  = item.Quantity;
                    newDetail.Price     = item.Price;
                    context.InvoiceDetails.Add(newDetail);

                    var product = (from x in context.Products
                                   where x.ProductID == item.ProductID
                                   select x).FirstOrDefault();
                    product.QuantityOnHand -= newDetail.Quantity;
                    context.Entry(product).Property(y => y.QuantityOnHand).IsModified = true;
                }

                return(context.SaveChanges());
            }
        }
        public void Force_Closure(int orderid, string comment)
        {
            using (var context = new eRaceContext())
            {
                var ForceClosure = from x in context.OrderDetails
                                   where x.OrderID == orderid
                                   //select x;
                                   select x.OrderDetailID;

                //var OrderDetail = context.OrderDetails.Find(orderid);
                //var OrderDetailQuantity = OrderDetail.Quantity;

                //var results = (from x in context.ReceiveOrderItems
                //               where x.OrderDetail.OrderID == orderid
                //               select x.OrderDetailID).ToList();

                //foreach (var order in orderlist)
                //{
                //    var quantityzero = from x in context.OrderDetails
                //                       where
                //}

                var commitClosure = context.Orders.Find(orderid);
                commitClosure.Comment = comment;
                commitClosure.Closed  = true;

                context.Entry(commitClosure).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
        public List <CategoryDTO> Category_VendorCatalog_Get(int vendorID)
        {
            using (var context = new eRaceContext())
            {
                var results = from vc in context.VendorCatalogs
                              group vc by vc.Product.Category.Description into Group
                              orderby Group.Key
                              select new CategoryDTO
                {
                    Category = Group.Key,
                    Products = (from x in Group
                                where x.VendorID == vendorID
                                select new VendorCatalogPOCO
                    {
                        //ProductId = x.Product.ProductID,
                        ProductName = x.Product.ItemName,
                        Reorder = x.Product.ReOrderLevel,
                        InStock = x.Product.QuantityOnHand,
                        // ItemPrice = x.Product.ItemPrice,
                        OnOrder = x.Product.QuantityOnHand,
                        Size = x.OrderUnitType + " " + "(" + x.OrderUnitSize + ")"
                    }).ToList()
                };

                return(results.ToList());
            }
        }
示例#9
0
 public List <SalesCartItem> SalesCartItem_List()
 {
     using (var context = new eRaceContext())
     {
         return(context.SalesCartItems.ToList());
     }
 }
示例#10
0
 public List <RefundDetail> List_InvoiceDetailsList(int invoiceID)
 {
     using (var context = new eRaceContext())
     {
         var results = (from x in context.Invoices
                        where x.InvoiceID.Equals(invoiceID)
                        select x).FirstOrDefault();
         if (results == null)
         {
             return(null);
         }
         else
         {
             var items = from x in context.InvoiceDetails
                         where x.InvoiceID.Equals(invoiceID)
                         select new RefundDetail
             {
                 Product       = x.Product.ItemName,
                 Qty           = x.Quantity,
                 Price         = (decimal)x.Price,
                 Amount        = x.Quantity * (decimal)x.Price,
                 RestockCharge = x.Product.ReStockCharge
             };
             return(items.ToList());
         }
     }
 }
示例#11
0
        public void ForceCloseOrder(ForceCloseDetails order)
        { /* command modify Products, Order and OrderDeatails */
          // Validation

            List <Exception> errors = new List <Exception>();

            if (order == null)
            {
                throw new ArgumentNullException(nameof(order), $"No {nameof(ForceCloseDetails)} was supplied for an existing PO.");
            }
            else
            {
                if (order.Comment.Trim().Equals(null))
                {
                    throw new Exception("Please give a reason in the comment box for why the order is being closed.");
                }
            }


            using (var context = new eRaceContext())
            {
                var given = context.Orders.Find(order.OrderID);
                if (given == null)
                {
                    throw new ArgumentException($"The given order id of {order.OrderID} does not exist in the database.");
                }

                given.Comment = order.Comment;
                given.Closed  = true;

                var existingOrder = context.Entry(given);

                existingOrder.Property(nameof(given.Comment)).IsModified = true;
                existingOrder.Property(nameof(given.Closed)).IsModified  = true;

                foreach (var item in order.Items)
                {
                    var givenOrder   = context.OrderDetails.Find(item.ProductID);
                    var givenProduct = context.Products.Find(givenOrder.ProductID);

                    if (givenProduct == null)
                    {
                        throw new ArgumentException($"The given product id of {item.ProductID} does not exist in the database.");
                    }

                    givenProduct.QuantityOnOrder = givenProduct.QuantityOnOrder - item.QuantityOutstanding;

                    if (givenProduct.QuantityOnOrder < 0)
                    {
                        givenProduct.QuantityOnOrder = 0;
                    }

                    var existingProduct = context.Entry(givenProduct);

                    existingProduct.Property(nameof(givenProduct.QuantityOnOrder)).IsModified = true;
                }

                context.SaveChanges();
            }
        }
示例#12
0
 internal List <Employee> ListEmployees()
 {
     using (var context = new eRaceContext())
     {
         return(context.Employees.ToList());
     }
 }
示例#13
0
 // Get Order Comments
 public Order Purchasing_VendorOrderComment_Get(int vendorID)
 {
     using (var context = new eRaceContext())
     {
         var info = context.Orders.Find(vendorID);
         return(info);
     }
 }
示例#14
0
 public Vendor Purchasing_Vendor_Get(int vendorID)
 {
     using (var context = new eRaceContext())
     {
         var info = context.Vendors.Find(vendorID);
         return(info);
     }
 }
示例#15
0
 public void DeleteUnorderedItem(UnorderedInfo item)
 {
     using (var context = new eRaceContext())
     {
         var existing = context.UnOrderedItems.Find(item.ItemID);
         context.UnOrderedItems.Remove(existing);
         context.SaveChanges();
     }
 }
示例#16
0
 public void ClearCart(int employeeID, int productID)
 {
     using (var context = new eRaceContext())
     {
         var result = context.SalesCartItems.Find(employeeID, productID);
         context.SalesCartItems.Remove(result);
         context.SaveChanges();
     }
 }
示例#17
0
        public int ReturnInvoiceID()
        {
            using (var context = new eRaceContext())
            {
                var date = (from x in context.StoreRefunds orderby x.InvoiceID descending select x.InvoiceID).FirstOrDefault();

                return(date);
            }
        }
示例#18
0
        public void Add_ItemToCart(int employeid, int productid, int qty)
        {
            if (qty < 0)
            {
                throw new Exception("Quantity cannot be zero");
            }
            else
            {
                //var buyItem = context.SalesCartItems.Add(new SalesCartItem());
                //buyItem.ProductID = productid;
                //buyItem.EmployeeID = employeid;
                //buyItem.Quantity = qty;
                using (var context = new eRaceContext())
                {
                    Product newProduct = null;
                    int     product    = 0;
                    Product products   = new Product();

                    Product prdct = (from x in context.Products
                                     .Where(x => x.ProductID.Equals(productid))
                                     select x).FirstOrDefault();

                    SalesCartItem exists = (from x in context.SalesCartItems
                                            .Where(x => x.EmployeeID.Equals(employeid) && x.ProductID.Equals(productid))
                                            select x).FirstOrDefault();
                    if (exists == null)
                    {
                        exists            = new SalesCartItem();
                        exists.EmployeeID = employeid;
                        exists.ProductID  = productid;
                        exists.UnitPrice  = prdct.ItemPrice;
                        exists.Quantity   = qty;



                        exists  = context.SalesCartItems.Add(exists);
                        product = 1;
                    }
                    else
                    {
                        newProduct = exists.Product.Category.Products.SingleOrDefault(x => x.ProductID == productid);

                        if (newProduct == null)
                        {
                            product = exists.Product.Category.Products.Count() + 1;
                        }
                        else
                        {
                            product = exists.Quantity++;
                        }
                    }


                    context.SaveChanges();
                }
            }
        }//end of Add_ItemToCart
示例#19
0
 public int Driver_Update(RaceDetail driver)
 {
     using (var context = new eRaceContext())
     {
         context.Entry(driver).State =
             System.Data.Entity.EntityState.Modified;
         return(context.SaveChanges());
     }
 }
示例#20
0
        public int ProcessRefund(List <Refund> returns, int employeeId, decimal total, int orderID)
        {
            using (var context = new eRaceContext())
            {
                if (total == 0)
                {
                    throw new Exception("There are no returns on this order.");
                }

                List <int> returned = (from item in context.StoreRefunds where item.OriginalInvoiceID == orderID select item.ProductID).ToList();


                var invoice = new Invoice
                {
                    EmployeeID  = employeeId,
                    InvoiceDate = DateTime.Now,
                    SubTotal    = total,
                    GST         = Math.Round(total * (decimal)0.05, 2),
                    Total       = Math.Round(total * (decimal)1.05, 2)
                };

                foreach (var item in returns)
                {
                    bool alreadyReturned = returned.Contains(item.ProductID);

                    if (alreadyReturned == false)
                    {
                        if (item.Reason != "")
                        {
                            invoice.StoreRefunds.Add(new StoreRefund
                            {
                                InvoiceID         = invoice.InvoiceID,
                                ProductID         = item.ProductID,
                                OriginalInvoiceID = orderID,
                                Reason            = item.Reason
                            });
                            var newQOH = context.Products.Where(x => x.ProductID == item.ProductID).FirstOrDefault();

                            newQOH.QuantityOnHand += item.Quantity;
                        }
                        else
                        {
                            throw new Exception($"{item.ItemName} requires a return reason.");
                        }
                    }
                    else
                    {
                        throw new Exception($"{item.ItemName} has already been returned");
                    }
                }
                context.Invoices.Add(invoice);

                context.SaveChanges();

                return(invoice.InvoiceID);
            }
        }
 public List <string> Positions_GetList()
 {
     using (var context = new eRaceContext())
     {
         var results = from x in context.Positions
                       select x.Description;
         return(results.ToList());
     }
 }
示例#22
0
 public int Get_CategoryID(string product)
 {
     using (var context = new eRaceContext())
     {
         var id = (from x in context.Products
                   where x.ItemName.Equals(product)
                   select x.CategoryID).FirstOrDefault();
         return(id);
     };
 }
        public int Insert_ReturnItems(UnOrderedItem item)
        {
            using (var context = new eRaceContext())
            {
                context.UnOrderedItems.Add(item);
                context.SaveChanges();

                return(item.ItemID);
            }
        }
示例#24
0
        public void RemoveCartItem(int productID, int employeeID)
        {
            using (var context = new eRaceContext())
            {
                var result = context.SalesCartItems.Where(x => x.ProductID == productID && x.EmployeeID == employeeID).FirstOrDefault();

                context.SalesCartItems.Remove(result);
                context.SaveChanges();
            }
        }
示例#25
0
 public List <RaceDetail> RaceDetail_GetByRaceID(int raceid)
 {
     using (var context = new eRaceContext())
     {
         var results = from x in context.RaceDetails
                       where x.RaceID == raceid
                       select x;
         return(results.ToList());
     }
 }
示例#26
0
 public int Driver_Add(RaceDetail driver)
 {
     using (var context = new eRaceContext())
     {
         //yet to develop the business logic and error handling
         context.RaceDetails.Add(driver); //staging
         context.SaveChanges();           //committed
         return(driver.RaceDetailID);     //return new id value
     }
 }
示例#27
0
 public IEnumerable <SetupPositions> ListPositions()
 {
     using (var context = new eRaceContext())
     {
         var results = from positions in context.Positions.ToList()
                       select new SetupPositions
         {
             Position = positions.Description
         };
         return(results);
     }
 }
示例#28
0
 public List <PenaltyList> Penalties_List()
 {
     using (var context = new eRaceContext())
     {
         var results = from x in context.RacePenalties
                       select new PenaltyList
         {
             Description = x.Description
         };
         return(results.ToList());
     }
 }
示例#29
0
 public List <CarList> Car_List()
 {
     using (var context = new eRaceContext())
     {
         var results = from x in context.Cars
                       select new CarList
         {
             CarID        = x.CarID,
             SerialNumber = x.SerialNumber,
         };
         return(results.ToList());
     }
 }
示例#30
0
 public List <CarClassList> CarClass_List()
 {
     using (var context = new eRaceContext())
     {
         var results = from x in context.CarClasses
                       select new CarClassList
         {
             CarClassID = x.CarClassID,
             ClassName  = x.CarClassName
         };
         return(results.ToList());
     }
 }