Esempio n. 1
0
        }// part-three, Delete button

        #endregion

        #region receving/returning/reasons data transaction.
        public void RecevingReturningReason_transaction(bool checkOutstand, int purchaseorderid, List <RecevingOrderList> recevOrder)
        {
            using (var context = new eToolsContext())
            {
                foreach (var item in recevOrder)
                {
                    var newstockItem = context.StockItems.Find(item.SID);
                    //newOrderOnHand += (item.Receiving).GetValueOrDefault();

                    newstockItem.QuantityOnHand  += (item.Receiving).GetValueOrDefault();
                    newstockItem.QuantityOnOrder -= (item.Receiving).GetValueOrDefault();

                    context.SaveChanges();

                    //if(item.Outstanding == 0)
                    //{
                    //    Remove_PurchaseOrderDetail(item.PurchasePrderDetail);
                    //}
                }

                Create_ReceiveOrder(purchaseorderid, recevOrder);
                //Create_ReturnedOrderDetails(purchaseorderid, purorderdetailid, recevOrder);

                PurchaseOrder getPO = context.PurchaseOrders.Find(purchaseorderid);

                if (checkOutstand)
                {
                    getPO.Closed = true;
                    context.SaveChanges();
                }
            }
        }
Esempio n. 2
0
        //public List<PODetail> ItemsInStockSuggested(int vendorid)
        //{
        //    List<PODetail> itemToOrder = SuggestedOrderDetails(vendorid);
        //    using (var context = new eToolsContext())
        //    {
        //        //var allItems = context.StockItems.ToList();
        //        List<int> poDetailItems = (from x in itemToOrder
        //                                   select x.SID).ToList();
        //        List<StockItem> remainStockItems = new List<StockItem>();
        //        foreach (var item in context.StockItems.Where(x => x.VendorID == vendorid))
        //        {
        //            if (!poDetailItems.Contains(item.StockItemID))
        //            {
        //                remainStockItems.Add(item);
        //            }
        //        }

        //        var resault = from x in remainStockItems
        //                      select new PODetail
        //                      {
        //                          SID = x.StockItemID,
        //                          description = x.Description,
        //                          qoh = x.QuantityOnHand,
        //                          qoo = x.QuantityOnOrder,
        //                          rol = x.ReOrderLevel,
        //                          price = x.PurchasePrice,
        //                          qto = ((x.QuantityOnHand + x.QuantityOnOrder) - x.ReOrderLevel) >= 0 ? ((x.QuantityOnHand + x.QuantityOnOrder) - x.ReOrderLevel) : 0
        //                      };
        //        return resault.ToList();
        //    }
        //}

        public void Create_PurchaseOrder(int vendorid, int employeeid)
        {
            PurchaseOrder newPO = new PurchaseOrder();

            newPO.VendorID   = vendorid;
            newPO.EmployeeID = employeeid;
            newPO.Closed     = false;
            newPO.TaxAmount  = 0;
            newPO.SubTotal   = 0;
            decimal subTotal = 0;

            //List<PurchaseOrderDetail> showPODetails = new List<PurchaseOrderDetail>();
            using (var context = new eToolsContext())
            {
                context.PurchaseOrders.Add(newPO);
                context.SaveChanges();

                List <StockItem> vendorStockItems = (from x in context.StockItems
                                                     where x.VendorID.Equals(vendorid) && (x.ReOrderLevel - (x.QuantityOnHand + x.QuantityOnOrder)) > 0
                                                     select x).ToList();
                // generate PurchaseOrderDetail for the new PurchaseOrder

                foreach (var item in vendorStockItems)
                {
                    PurchaseOrderDetail newItem = new PurchaseOrderDetail();
                    newItem.PurchaseOrderID = newPO.PurchaseOrderID;
                    newItem.StockItemID     = item.StockItemID;
                    newItem.PurchasePrice   = item.PurchasePrice;
                    newItem.Quantity        = item.ReOrderLevel - (item.QuantityOnHand + item.QuantityOnOrder);

                    subTotal += item.PurchasePrice;

                    //PODetail showPODetail = new PODetail();
                    //showPODetail.SID = item.StockItemID;
                    //showPODetail.description = item.Description;
                    //showPODetail.qoh = item.QuantityOnHand;
                    //showPODetail.qoo = item.QuantityOnOrder;
                    //showPODetail.rol = item.ReOrderLevel;
                    //showPODetail.QtyToOrder = newItem.Quantity;

                    //showPODetails.Add(newItem);
                    context.PurchaseOrderDetails.Add(newItem);
                }

                newPO.SubTotal             = decimal.Round(subTotal, 2);
                newPO.TaxAmount            = decimal.Round(subTotal * ((decimal)0.05), 2);
                context.Entry(newPO).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
        public void Place_ToPurchaseOrder(int vendorid, List <CurrentActiveOrderList> CurrentActiveOrderList)
        {
            using (var context = new eToolsContext())
            {
                var order = context.PurchaseOrders
                            .Where(or => or.VendorID == vendorid && or.OrderDate == null)
                            .Select(or => or).FirstOrDefault();

                Update_ItemsFromCurrentOrder(vendorid, CurrentActiveOrderList);
                order.OrderDate           = DateTime.Today;
                order.PurchaseOrderNumber = (from c in context.PurchaseOrders
                                             select c.PurchaseOrderNumber).Max() + 1;


                var orderdetailsid = order.PurchaseOrderDetails.
                                     Select(de => de.PurchaseOrderDetailID).ToList();

                var stockitem = context.StockItems.Where(st => st.VendorID == vendorid)
                                .Select(st => st).ToList();

                foreach (CurrentActiveOrderList item in CurrentActiveOrderList)
                {
                    foreach (var stock in stockitem)
                    {
                        if (item.StockItemID == stock.StockItemID)
                        {
                            stock.QuantityOnOrder = stock.QuantityOnOrder + item.QuantityToOrder;
                        }
                    }
                }
                context.SaveChanges();
            }
        }
        public void Update_ItemsFromCurrentOrder(int vendorid, List <CurrentActiveOrderList> CurrentActiveOrderList)
        {
            using (var context = new eToolsContext())
            {
                var order = context.PurchaseOrders
                            .Where(or => or.VendorID == vendorid && or.OrderDate == null)
                            .Select(or => or).FirstOrDefault();

                var details = (from c in context.PurchaseOrderDetails
                               where c.PurchaseOrderID == order.PurchaseOrderID
                               select c.PurchaseOrderDetailID).ToList();

                decimal sub = 0;
                foreach (CurrentActiveOrderList item in CurrentActiveOrderList)
                {
                    foreach (var id in details)
                    {
                        PurchaseOrderDetail temp = context.PurchaseOrderDetails.Find(id);
                        if (temp.StockItemID == item.StockItemID)
                        {
                            temp.StockItemID   = item.StockItemID;
                            temp.Quantity      = item.QuantityToOrder;
                            temp.PurchasePrice = item.Price;
                            sub += (item.Price) * (decimal)(item.QuantityToOrder);
                        }
                    }
                }
                order.SubTotal  = Math.Round(sub, 2);
                order.TaxAmount = Math.Round((sub * (decimal)0.05), 2);
                context.SaveChanges();
            }
        }
        public void Remove_CurrentActivePurchaseOrdder(int vendorid, int stockitmeid)
        {
            List <string> reasons = new List <string>();

            using (var context = new eToolsContext())
            {
                var exist = context.PurchaseOrders
                            .Where(c => c.VendorID == vendorid && c.OrderDate == null).Select(c => c).FirstOrDefault();
                if (exist == null)

                {
                    throw new Exception("Purchase Order has been removed from the files.");
                }
                else
                {
                    PurchaseOrderDetail item = null;
                    item = exist.PurchaseOrderDetails.
                           Where(ord => ord.StockItemID == stockitmeid).FirstOrDefault();
                    if (item != null)
                    {
                        exist.SubTotal  = Math.Round(exist.SubTotal - (item.Quantity * (decimal)(item.PurchasePrice)), 2);
                        exist.TaxAmount = Math.Round((exist.SubTotal * (decimal)0.05), 2);
                        context.PurchaseOrderDetails.Remove(item);
                    }
                }
                context.SaveChanges();
            }
        }
        public void Add_LinItemToCurrentActivePurchaseOrdderList(int vendorid, int stockitemid)
        {
            List <string> reasons = new List <string>();

            using (var context = new eToolsContext())
            {
                var order = context.PurchaseOrders
                            .Where(or => or.VendorID == vendorid && or.OrderDate == null)
                            .Select(or => or).FirstOrDefault();

                PurchaseOrderDetail orderdetails = null;

                orderdetails = new PurchaseOrderDetail();
                decimal sub1 = 0;
                orderdetails.StockItemID   = stockitemid;
                orderdetails.Quantity      = 1;
                orderdetails.PurchasePrice = (from c in context.StockItems
                                              where c.VendorID == vendorid &&
                                              c.StockItemID == stockitemid
                                              select c.PurchasePrice).FirstOrDefault();
                orderdetails.PurchaseOrderID = order.PurchaseOrderID;

                sub1 = orderdetails.PurchasePrice * orderdetails.Quantity;

                order.SubTotal  = order.SubTotal + sub1;
                order.TaxAmount = order.TaxAmount + (sub1 * (decimal)0.05);
                context.PurchaseOrderDetails.Add(orderdetails);
                context.SaveChanges();
            }
        }
        public void Delete_CurrentOpenPurchaseOrderDetils(int vendorid)
        {
            using (var context = new eToolsContext())
            {
                var order = context.PurchaseOrders
                            .Where(c => c.VendorID == vendorid && c.OrderDate == DateTime.Today).
                            Select(c => c).FirstOrDefault();
                if (order != null)

                {
                    throw new Exception("purchase Order has been already placed. placed order can not be deleted.");
                }
                else
                {
                    var exist = context.PurchaseOrders
                                .Where(c => c.VendorID == vendorid && c.OrderDate == null).
                                Select(c => c).FirstOrDefault();


                    var temp = (from c in context.PurchaseOrderDetails
                                where c.PurchaseOrderID == exist.PurchaseOrderID
                                select c).ToList();
                    foreach (var item in temp)
                    {
                        context.PurchaseOrderDetails.Remove(item);
                    }
                    context.PurchaseOrders.Remove(exist);
                }

                context.SaveChanges();
            }
        }
Esempio n. 8
0
        public void removeRentalEquipment(int rentalId, int equitmentid)
        {
            using (var context = new eToolsContext())
            {
                //Return equipment
                RentalEquipment checkoutEquipment = context.RentalEquipments
                                                    .Where(x => (x.RentalEquipmentID == equitmentid)).FirstOrDefault();
                //Update availability
                checkoutEquipment.Available = true;

                //COMMIT UPDATE***
                context.Entry(checkoutEquipment).State = EntityState.Modified;
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////



                //retrive rentaldetails table that will destoryed
                RentalDetail existingRentalEquipment = context.RentalDetails
                                                       .Where(x => ((x.RentalID == rentalId) &&
                                                                    (x.RentalEquipmentID == equitmentid))).FirstOrDefault();

                //COMMIT DELETE***
                context.Entry(existingRentalEquipment).State = EntityState.Deleted;

                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////



                //Finalize Transaction!
                context.SaveChanges();
                //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
        }
Esempio n. 9
0
        public void Create_RentalDetails(int rentalID, int equipmentID)
        {
            using (var context = new eToolsContext())
            {
                RentalEquipment equipment = context.RentalEquipments.Where(x => x.RentalEquipmentID.Equals(equipmentID)).Select(x => x).FirstOrDefault();

                RentalDetail exists = context.RentalDetails.Where(x => x.RentalEquipmentID.Equals(equipmentID) && x.RentalID.Equals(rentalID)).Select(x => x).FirstOrDefault();

                if (exists != null)//equipmnet already in there
                {
                    throw new BusinessRuleException("Already Renting This Equipment", "This piece of equipment is already on this rental");
                }
                else
                {
                    RentalDetail detail = new RentalDetail();

                    detail.RentalID        = rentalID;
                    detail.RentalEquipment = equipment;
                    detail.ConditionOut    = equipment.Condition;
                    detail.ConditionIn     = equipment.Condition;

                    context.RentalDetails.Add(detail);

                    context.SaveChanges();
                }
            }
        }
        public int Return_Update(ReturnForm rtn)
        {
            using (var context = new eToolsContext())
            {
                //RentalDetail item = context.RentalDetails.Where(x => (x.RentalDetailID == rtn.ID)).FirstOrDefault();
                //RentalDetail item2 = new RentalDetail();
                //item2 = item;
                //item2.Comments = rtn.CustomerCommets == null ? "" : rtn.CustomerCommets; //can be null
                //item2.ConditionIn = rtn.CoditionCommets == null ? "" : rtn.CoditionCommets;

                RentalDetail rdptr = context.RentalDetails.Where(x => (x.RentalDetailID == rtn.ID)).FirstOrDefault();
                RentalDetail item  = new RentalDetail();
                if (rdptr == null)
                {
                    throw new BusinessRuleException("No such rental exists!", logger);
                }
                else
                {
                    item.RentalDetailID    = rtn.ID;
                    item.RentalID          = rdptr.RentalID;
                    item.RentalEquipmentID = rdptr.RentalEquipmentID;
                    item.Days             = rdptr.Days;
                    item.DailyRate        = rdptr.DailyRate;
                    item.ConditionOut     = rdptr.ConditionOut;
                    item.ConditionIn      = string.IsNullOrEmpty(rtn.CoditionCommets) ? "" : rtn.CoditionCommets;
                    item.DamageRepairCost = rdptr.DamageRepairCost;
                    item.Comments         = string.IsNullOrEmpty(rtn.CustomerCommets) ? "" : rtn.CustomerCommets;
                }
                context.Entry(item).State = System.Data.Entity.EntityState.Modified;
                return(context.SaveChanges());
            }
        }
Esempio n. 11
0
        public int Create_Rental(int employeeID, int customerID, int rentalID)
        {
            //search if rental for same day and employee and customer exists if it does dont let them make one
            //if it does not then create one
            //cancel button will need to delete the rental
            using (var context = new eToolsContext())
            {
                Rental exists = context.Rentals.Where(x => x.CustomerID.Equals(customerID) && x.EmployeeID.Equals(employeeID)).Select(x => x).FirstOrDefault();

                if (exists != null)
                {
                    //dont let them create a thing its already there boi
                    throw new BusinessRuleException("Cannot Have Two Rentals on the Same Day", "One customer and employee pair cannot have two rentals on the same day");
                }
                else
                {
                    exists            = new Rental();
                    exists.EmployeeID = employeeID;
                    exists.CustomerID = customerID;

                    exists.PaymentType = "C";
                    exists.SubTotal    = 0;
                    exists.TaxAmount   = 0;

                    exists = context.Rentals.Add(exists);
                    context.SaveChanges();
                    return(exists.RentalID);

                    //select by usering customer employee and date? cause can only return one so if i do linq to get that one then i can get the rental id from that if this is no work.
                }
            }
        }
 public void Update_ShoppingCartFromDisplay(List <CartSelection> cart)
 {
     using (var context = new eToolsContext())
     {
         bool cartUpdated    = false;
         int  shoppingcartID = 0;
         foreach (CartSelection cartitem in cart)
         {
             ShoppingCartItem item = context.ShoppingCartItems.Find(cartitem.ShoppingCartitemID);
             //check to see if cart has actually been updated, if so, update ShoppingCart UpdatedOn
             if (item.Quantity != cartitem.QuantitySelected)
             {
                 item.Quantity  = cartitem.QuantitySelected;
                 cartUpdated    = true;
                 shoppingcartID = item.ShoppingCartID;
             }
             context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         }
         if (cartUpdated)
         {
             //set updated property in associated shopping cart
             ShoppingCart shoppingCart = context.ShoppingCarts.Find(shoppingcartID);
             shoppingCart.UpdatedOn            = DateTime.Now;
             context.Entry(shoppingCart).State = System.Data.Entity.EntityState.Modified;
         }
         context.SaveChanges();
     }
 }
Esempio n. 13
0
        public void Create_newRentalRecord(int customerid, int employeeid, RentalRecord record)
        {
            using (var context = new eToolsContext())
            {
                decimal subtotal        = 0;
                decimal taxamount       = 0;
                Rental  newRentalRecord = null;
                newRentalRecord.CustomerID = customerid;
                newRentalRecord.EmployeeID = employeeid;
                newRentalRecord.CouponID   = record.CouponID;

                foreach (var item in record.Details)
                {
                    subtotal += item.DailyRate * (decimal)item.Days;
                }
                newRentalRecord.SubTotal = subtotal;

                taxamount = (decimal)0.05 * subtotal;
                newRentalRecord.TaxAmount = taxamount;

                newRentalRecord.RentalDate  = record.RentalDate;
                newRentalRecord.PaymentType = "C";
                newRentalRecord.CreditCard  = record.CreditCard;

                if (newRentalRecord != null)
                {
                    context.Rentals.Add(newRentalRecord);
                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Rental record was created failed.");
                }
            }
        }
Esempio n. 14
0
        }// part-three, Insert button.

        #endregion

        #region Create ReturnedOrderDetails
        public void Create_ReturnedOrderDetails(int receorderid, List <RecevingOrderList> quanreceList)
        {
            using (var context = new eToolsContext())
            {
                // var purchaseorderid = context.PurchaseOrders.Find(item.PurchaseOrderID);
                foreach (var item in quanreceList)
                {
                    if (item.Returning > 0)
                    {
                        ReturnedOrderDetail newReturnOrderDetail = new ReturnedOrderDetail();
                        newReturnOrderDetail.ReceiveOrderID        = receorderid;
                        newReturnOrderDetail.PurchaseOrderDetailID = item.PurchasePrderDetail;

                        var stoItem = context.StockItems.Find(item.SID);
                        newReturnOrderDetail.ItemDescription   = stoItem.Description;
                        newReturnOrderDetail.VendorStockNumber = stoItem.VendorStockNumber;

                        newReturnOrderDetail.Reason   = item.Reason;
                        newReturnOrderDetail.Quantity = item.Returning.GetValueOrDefault();

                        context.ReturnedOrderDetails.Add(newReturnOrderDetail);
                    }
                }

                context.SaveChanges();
            }
        }// Create ReturnedOrderDetails.
        }//eom

        public string RemovingASingleRowFromActiveOrder(int vendorID, int sID)
        {
            using (var context = new eToolsContext())
            {
                decimal subtotal = 0;
                decimal tax      = 0;
                //1. remove the item from DB
                PurchaseOrderDetail toRemove = context.PurchaseOrderDetails
                                               .Where(x => x.PurchaseOrder.VendorID.Equals(vendorID) && x.PurchaseOrder.PurchaseOrderNumber.Equals(null) && x.PurchaseOrder.OrderDate.Equals(null) && x.StockItemID.Equals(sID))
                                               .FirstOrDefault();


                context.PurchaseOrderDetails.Remove(toRemove);
                //2. Calculate the subtotal and tax from the orderDetail
                var detailList = context.PurchaseOrders.Where(x => x.VendorID.Equals(vendorID) && x.OrderDate.Equals(null) && x.PurchaseOrderNumber.Equals(null)).FirstOrDefault().PurchaseOrderDetails.ToList();
                if (detailList.Count > 0)
                {
                    foreach (var item in detailList)
                    {
                        subtotal += item.Quantity * item.PurchasePrice;
                        tax      += (item.Quantity * item.PurchasePrice) * (decimal)0.05;
                    }
                }
                //3. update the order
                PurchaseOrder changedPO = context.PurchaseOrders.Where(x => x.VendorID.Equals(vendorID) && x.OrderDate.Equals(null) && x.PurchaseOrderNumber.Equals(null)).FirstOrDefault();
                changedPO.SubTotal  = subtotal;
                changedPO.TaxAmount = tax;
                //4. save change.
                context.SaveChanges();
                return(toRemove.StockItemID.ToString());
            }
        }//eom
 public void PlaceOrder(Sale sale, ShoppingCart cart)
 {
     using (var context = new eToolsContext())
     {
         context.Sales.Add(sale);
         List <ShoppingCartItem> cartItems = context.ShoppingCartItems.Where(x => x.ShoppingCartID.Equals(cart.ShoppingCartID)).Select(x => x).ToList();
         foreach (ShoppingCartItem cartItem in cartItems)
         {
             StockItem  stockItem  = context.StockItems.Where(x => x.StockItemID.Equals(cartItem.StockItemID)).FirstOrDefault();
             SaleDetail saleDetail = new SaleDetail();
             saleDetail.StockItemID  = cartItem.StockItemID;
             saleDetail.SellingPrice = stockItem.SellingPrice;
             saleDetail.Quantity     = cartItem.Quantity;
             if (saleDetail.Quantity > (stockItem.QuantityOnHand + stockItem.QuantityOnOrder))
             {
                 throw new Exception("Sale cannot proceed. " + stockItem.Description + " is out of stock.");
             }
             saleDetail.Backordered = saleDetail.Quantity > stockItem.QuantityOnHand ? true : false;
             sale.SaleDetails.Add(saleDetail);
             stockItem.QuantityOnHand       = saleDetail.Quantity > stockItem.QuantityOnHand ? 0 : stockItem.QuantityOnHand - saleDetail.Quantity;
             context.Entry(stockItem).State = System.Data.Entity.EntityState.Modified;
             context.ShoppingCartItems.Remove(cartItem);
         }
         ShoppingCart theCart = context.ShoppingCarts.Where(x => x.ShoppingCartID.Equals(cart.ShoppingCartID)).FirstOrDefault();
         context.ShoppingCarts.Remove(theCart);
         context.SaveChanges();
     }
 }
Esempio n. 17
0
        public void PurchaseOrder_Place(List <PurchaseOrderDetail> polist)
        {
            using (var context = new eToolsContext())
            {
                decimal total = 0;
                PurchaseOrder_Update(polist);
                foreach (var item in polist)
                {
                    var stockItem = context.StockItems.Find(item.StockItemID);
                    stockItem.QuantityOnOrder += item.Quantity;
                    total += item.Quantity * item.PurchasePrice;
                }
                //get PurchaseOrderDetail id from ListView
                int poDetailid = (from x in polist
                                  select x.PurchaseOrderDetailID).FirstOrDefault();

                //get PurchaseOrder id from PurchaseOrderDetail
                PurchaseOrderDetail getPurchaseOrderDetail = context.PurchaseOrderDetails.Find(poDetailid);
                int poid = getPurchaseOrderDetail.PurchaseOrderID;

                //get max PurchaseOrderNumber
                var lastPONumber = (from x in context.PurchaseOrders
                                    select x.PurchaseOrderNumber).ToList().Max();
                int lpoNumber = lastPONumber.GetValueOrDefault();
                var resault   = context.PurchaseOrders.Find(poid);
                resault.PurchaseOrderNumber = lpoNumber + 1;
                resault.OrderDate           = DateTime.Now;
                resault.SubTotal            = total;
                resault.TaxAmount           = total * (decimal)0.05;

                context.SaveChanges();
            }
        }
Esempio n. 18
0
        public void updateRental(int rentalID, string creditcard, int couponID)
        {
            using (var context = new eToolsContext())
            {
                Rental rental = context.Rentals.Where(x => x.RentalID.Equals(rentalID)).Select(x => x).FirstOrDefault();


                //RentalDetail exists = context.RentalDetails.Where(x => x.RentalEquipmentID.Equals(equipmentID) && x.RentalID.Equals(rentalID)).Select(x => x).FirstOrDefault();

                if (rental != null)//equipmnet already in there
                {
                    throw new BusinessRuleException("Rental Does not exist", "Rental does not exist, please create a rental before submiting it");
                }
                else
                {
                    Rental update = new Rental();

                    update.RentalID   = rentalID;
                    update.CreditCard = creditcard;
                    //update.CustomerID = customerID;
                    //update.EmployeeID = employeeID;
                    update.CouponID = couponID;

                    context.Entry(update).Property(y => y.CreditCard).IsModified = true;
                    context.Entry(update).Property(y => y.CouponID).IsModified   = true;

                    context.SaveChanges();
                }
            }
        }
Esempio n. 19
0
        }// Create ReturnedOrderDetails.

        #endregion

        #region Update PurchaseOrder
        public int Update_PurchaseOrder(PurchaseOrder item)
        {
            using (var context = new eToolsContext())
            {
                context.Entry(item).State = System.Data.Entity.EntityState.Modified;
                return(context.SaveChanges());
            }
        }// Create ReturnedOrderDetails.
Esempio n. 20
0
 public void Add_UnorderedItemToCart(UnorderedPurchaseItemCart item)
 {
     using (var context = new eToolsContext())
     {
         context.UnorderedPurchaseItemCart.Add(item);
         context.SaveChanges();
     }
 }
Esempio n. 21
0
 public void Update_ShoppingCartItem(ShoppingCartItem item)
 {
     using (var context = new eToolsContext())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public int newReturn_Update(RentalEquipment item)
 {
     using (var context = new eToolsContext())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         return(context.SaveChanges());
     }
 }
        public void deleteRental(int rentalid)
        {
            using (var context = new eToolsContext())
            {
                //.FirstOrDefault() is added in Visual Studio not in LINQ, as it does NOT AUTO. CONVERT!!
                Rental rental = context.Rentals.Where(x => (x.RentalID == rentalid)).FirstOrDefault();

                //A return of 1 means an EXACT MATCH
                //either there is a value or not; 1 or 0
                if (rental == null)
                {
                    throw new BusinessRuleException("No such rental exists!", logger);
                }
                else
                {
                    //Heavy Query!
                    DELETE_RentalDetailsTable_UPDATE_RentalEquipmentTable removeList = context.Rentals.Where(x => (x.RentalID == rentalid))
                                                                                       .Select(x =>
                                                                                               new DELETE_RentalDetailsTable_UPDATE_RentalEquipmentTable()
                    {
                        deleteSet = x.RentalDetails.Select(y =>
                                                           new SingleEquipmentPairWithRentalDetailDelete()
                        {
                            _RentalDetailTable    = y,
                            _RentalEquipmentTable = y.RentalEquipment
                        })
                    }).FirstOrDefault();


                    //The.find(...) returns an entity based on...ID

                    //DTO
                    foreach (var remove in removeList.deleteSet)
                    {
                        //I not sure if this returns or mods anything
                        //ii._RentalEquipmentTable.Available = true;

                        //better way... not this, but use above query
                        // ...== ii._RentalEquipmentTable.RentalEquipmentID)... id the equipment
                        //RentalEquipment updatedEquipment = context.RentalEquipments
                        //                                            .Where(x => (x.RentalEquipmentID == ii._RentalEquipmentTable.RentalEquipmentID)).FirstOrDefault();

                        RentalEquipment updatedEquipment = remove._RentalEquipmentTable;
                        updatedEquipment.Available            = true;
                        context.Entry(updatedEquipment).State = EntityState.Modified;     //Update Equipment ....Available = true; aka returned


                        RentalDetail deletedRentalDetail = remove._RentalDetailTable;
                        context.Entry(deletedRentalDetail).State = EntityState.Deleted;  //Delete RentalDetails
                    }

                    //Delete Rental
                    context.Entry(rental).State = EntityState.Deleted;
                }
                //Commit Transaction
                context.SaveChanges();
            }
        }
Esempio n. 24
0
        public void ReceivePurchaseOrder(int orderNumber, List <ViewPurchaseOrderItems> orderDetails, bool orderCompleted)
        {
            using (var context = new eToolsContext())
            {
                PurchaseOrder purchaseOrder = context.PurchaseOrders.Find(orderNumber);
                purchaseOrder.Closed = orderCompleted;
                context.Entry(purchaseOrder).Property("Closed").IsModified = true;

                ReceiveOrder receiveOrder = new ReceiveOrder();
                receiveOrder.PurchaseOrderID = orderNumber;
                receiveOrder.ReceiveDate     = DateTime.Now;
                context.ReceiveOrders.Add(receiveOrder);

                StockItem           stockItem           = null;
                PurchaseOrderDetail purchaseOrderDetail = null;
                ReceiveOrderDetail  receiveOrderDetail  = null;
                ReturnedOrderDetail returnedOrderDetail = null;

                foreach (ViewPurchaseOrderItems item in orderDetails)
                {
                    purchaseOrderDetail = purchaseOrder.PurchaseOrderDetails.Where(order => order.StockItemID == item.ItemID).SingleOrDefault();
                    if (item.Received > 0)
                    {
                        receiveOrderDetail = new ReceiveOrderDetail();
                        receiveOrderDetail.ReceiveOrderID        = receiveOrder.ReceiveOrderID;
                        receiveOrderDetail.PurchaseOrderDetailID = purchaseOrderDetail.PurchaseOrderDetailID;
                        receiveOrderDetail.QuantityReceived      = item.Received;
                        context.ReceiveOrderDetails.Add(receiveOrderDetail);

                        stockItem = context.StockItems.Find(item.ItemID);
                        stockItem.QuantityOnHand += item.Received;
                        context.Entry(stockItem).Property("QuantityOnHand").IsModified = true;

                        if (item.Received > stockItem.QuantityOnOrder)
                        {
                            stockItem.QuantityOnOrder = 0;
                        }
                        else
                        {
                            stockItem.QuantityOnOrder -= item.Received;
                        }
                        context.Entry(stockItem).Property("QuantityOnOrder").IsModified = true;
                    }
                    if (item.Returned > 0)
                    {
                        returnedOrderDetail = new ReturnedOrderDetail();
                        returnedOrderDetail.ReceiveOrderID        = receiveOrder.ReceiveOrderID;
                        returnedOrderDetail.PurchaseOrderDetailID = purchaseOrderDetail.PurchaseOrderDetailID;
                        returnedOrderDetail.ItemDescription       = stockItem.Description;
                        returnedOrderDetail.Quantity = item.Returned;
                        returnedOrderDetail.Reason   = item.Reason;
                        context.ReturnedOrderDetails.Add(returnedOrderDetail);
                    }
                }
                context.SaveChanges();
            }
        }
Esempio n. 25
0
 public void PurchaseOrderDetail_Remove(int poDetailid)
 {
     using (var context = new eToolsContext())
     {
         var res = context.PurchaseOrderDetails.Find(poDetailid);
         context.PurchaseOrderDetails.Remove(res);
         context.SaveChanges();
     }
 }
Esempio n. 26
0
        public void StartOrder(PurchaseOrder item)
        {
            using (var context = new eToolsContext())
            {
                var added = context.PurchaseOrders.Add(item);

                context.SaveChanges();
            }
        }
Esempio n. 27
0
        public void AddShoppingCart(ShoppingCart item2)
        {
            using (var context = new eToolsContext())
            {
                // Add the item to the dbContext
                var added = context.ShoppingCarts.Add(item2);

                context.SaveChanges();
            }
        }
Esempio n. 28
0
        }// Create ReturnedOrderDetails.

        #endregion

        #region Force Close.
        public void For_CloseOrder(int poid, string note)
        {
            using (var context = new eToolsContext())
            {
                PurchaseOrder getPurchaseOrder = context.PurchaseOrders.Find(poid);
                getPurchaseOrder.Notes  = note;
                getPurchaseOrder.Closed = true;
                context.SaveChanges();
            }
        }
Esempio n. 29
0
        public void DeleteItem(PurchaseOrderDetail item)
        {
            using (var context = new eToolsContext())
            {
                var existing = context.StockItems.Find(item.StockItemID);

                context.StockItems.Remove(existing);

                context.SaveChanges();
            }
        }
Esempio n. 30
0
        public void DeleteOrder(PurchaseOrder item)
        {
            using (var context = new eToolsContext())
            {
                var existing = context.PurchaseOrders.Find(item.PurchaseOrderID);

                context.PurchaseOrders.Remove(existing);

                context.SaveChanges();
            }
        }