Ejemplo n.º 1
0
        public void DeleteCurrentOrder(FinalOrder order)
        {
            using (var context = new eBikesContext())
            {
                var updatedOrder = context.PurchaseOrders.Find(order.PurchaseOrderID);
                var details      = context.PurchaseOrderDetails.Where(x => x.PurchaseOrderID == updatedOrder.PurchaseOrderID)?.ToList();

                if (updatedOrder == null)
                {
                    throw new Exception("Order does not exist.");
                }
                if (updatedOrder.OrderDate != null)
                {
                    throw new Exception("Order has already been placed. ");
                }
                else
                {
                    //going through the original list of details and comparing it with the new one
                    foreach (var item in details)
                    {
                        context.PurchaseOrderDetails.Remove(item);
                    }

                    context.PurchaseOrders.Remove(updatedOrder);
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
 public ShoppingCartCheckoutDTO GetCurrentCheckoutInfo(string username)
 {
     using (var context = new eBikesContext())
     {
         //THIS IS CRASHING WHEN THERE ARE NO ITEMS IN A CART NEED SOME CHECKING HERE
         ShoppingCartCheckoutDTO result = (from x in context.ShoppingCarts
                                           where x.OnlineCustomer.UserName.Equals(username)
                                           select new ShoppingCartCheckoutDTO
         {
             SubTotal = x.ShoppingCartItems.Sum(y => y.Quantity * y.Part.SellingPrice),
             Total = x.ShoppingCartItems.Sum(y => y.Quantity * y.Part.SellingPrice),
             ShoppingCartItems = (from y in x.ShoppingCartItems
                                  orderby y.Part.Description
                                  select new ShoppingCartLineItemPOCO
             {
                 Description = y.Part.Description,
                 Qty = y.Quantity,
                 UnitPrice = y.Part.SellingPrice,
                 ItemTotal = y.Quantity * y.Part.SellingPrice,
                 ShoppingCartItemId = y.ShoppingCartItemID
             }).ToList()
         }).FirstOrDefault();
         return(result);
     }
 }
        public List <PurchaseOrderList> Get_currentInventory(int vendorid)
        {
            using (var context = new eBikesContext())
            {
                var purhcaseorderid = from x in context.PurchaseOrders
                                      where x.VendorID == vendorid && x.OrderDate.Equals(null) && x.PurchaseOrderNumber.Equals(null)
                                      select x.PurchaseOrderID;

                var results = from y in context.Parts
                              where y.VendorID == vendorid && !(from x in context.PurchaseOrderDetails
                                                                where x.PurchaseOrderID == purhcaseorderid.FirstOrDefault()
                                                                select x.PartID).Contains(y.PartID)
                              select new PurchaseOrderList
                {
                    itemid      = y.PartID,
                    Description = y.Description,
                    QOH         = y.QuantityOnHand,
                    ROL         = y.ReorderLevel,
                    QOO         = y.QuantityOnOrder,
                    Price       = y.PurchasePrice
                };

                return(results.ToList());
            }
        }
Ejemplo n.º 4
0
 public void DeleteItemFromCart(string username, int shoppingcartitemid)
 {
     using (var context = new eBikesContext())
     {
         ShoppingCart currentCart = (from x in context.ShoppingCartItems
                                     where x.ShoppingCart.OnlineCustomer.UserName.Equals(username)
                                     select x.ShoppingCart).FirstOrDefault();
         if (currentCart == null)
         {
             throw new Exception("The shopping cart was removed from the database");
         }
         else
         {
             ShoppingCartItem deleteItem = currentCart.ShoppingCartItems.Where(i => i.ShoppingCartItemID == shoppingcartitemid).FirstOrDefault();
             if (deleteItem == null)
             {
                 throw new Exception("Could not find that part in the database");
             }
             else
             {
                 currentCart.UpdatedOn = DateTime.Now;
                 context.ShoppingCartItems.Remove(deleteItem);
                 context.SaveChanges();
             }
         }
     }
 }
 public int CartPartCount()
 {
     using (var context = new eBikesContext())
     {
         return(context.ShoppingCartItems.Count());
     }
 }
 public int?PartsCount()
 {
     using (var context = new eBikesContext())
     {
         return(context.Parts.Count());;
     }
 }
Ejemplo n.º 7
0
        public List <UserProfile> ListAllUsers()
        {
            var rolemgr = new RoleManager();
            List <UserProfile> results = new List <UserProfile>();
            var tempResults            = from person in Users.ToList()
                                         select new UserProfile
            {
                UserId            = person.Id,
                UserName          = person.UserName,
                Email             = person.Email,
                EmailConfirmation = person.EmailConfirmed,
                EmployeeId        = person.EmployeeID,
                CustomerId        = person.CustomerID,
                RoleMemberships   = person.Roles.Select(r => rolemgr.FindById(r.RoleId).Name)
            };

            using (var context = new eBikesContext())
            {
                Employee tempEmployee;
                foreach (var person in tempResults)
                {
                    if (person.EmployeeId.HasValue)
                    {
                        tempEmployee = context.Employees.Find(person.EmployeeId);
                        if (tempEmployee != null)
                        {
                            person.FirstName = tempEmployee.FirstName;
                            person.LastName  = tempEmployee.LastName;
                        }
                    }
                    results.Add(person);
                }
            }
            return(results.ToList());
        }
Ejemplo n.º 8
0
        public void Add_Product_To_ShoppingCart(string username, int productId, int quantity)
        {
            using (var context = new eBikesContext())
            {
                ShoppingCart exists = (from x in context.ShoppingCarts
                                       where x.OnlineCustomer.UserName.Equals(username)
                                       select x).FirstOrDefault();
                ShoppingCartItem newItem = null;
                if (exists == null)
                {
                    exists = new ShoppingCart();
                    exists.OnlineCustomerID = (from x in context.OnlineCustomer
                                               where x.UserName == username
                                               select x.OnlineCustomerID).SingleOrDefault();
                    exists.CreatedOn = DateTime.Now;
                    exists           = context.ShoppingCarts.Add(exists);
                }

                newItem = exists.ShoppingCartItems.SingleOrDefault(x => x.PartID == productId);
                if (newItem != null)
                {
                    newItem.Quantity += quantity;
                }
                else
                {
                    newItem          = new ShoppingCartItem();
                    newItem.PartID   = productId;
                    newItem.Quantity = quantity;

                    exists.ShoppingCartItems.Add(newItem);
                }

                context.SaveChanges();
            }
        }
 public void AddNewServiceDetail(POCOServiceDetail SD)
 {
     using (var context = new eBikesContext())
     {
         var existingJob = context.Jobs.Find(SD.JobID);
         if (existingJob == null)
         {
             throw new Exception("The job has been deleted, because there are no service details associate with it.");
         }
         if (existingJob.StatusCode == "D")
         {
             throw new Exception("The Job is closed, service details associate with the job cannot be edited or deleted.");
         }
         ServiceDetail newSD = new ServiceDetail
         {
             JobID       = SD.JobID,
             Description = SD.Description,
             JobHours    = SD.JobHours,
             Comments    = SD.Comments,
             CouponID    = SD.CouponID == null ? null : SD.CouponID
         };
         context.ServiceDetails.Add(newSD);
         context.SaveChanges();
     }
 }
 public Employee Employee_Get(int employeeId)
 {
     using (var context = new eBikesContext())
     {
         return(context.Employees.Find(employeeId));
     }
 }
 public int CouponValue(string couponIdValue)
 {
     using (var context = new eBikesContext())
     {
         return(context.Coupons.Where(x => x.CouponIDValue == couponIdValue).Select(x => x.CouponDiscount).SingleOrDefault());
     }
 }
Ejemplo n.º 12
0
 public Sale GetSaleConfirmation(int saleid)
 {
     using (var context = new eBikesContext())
     {
         var result = context.Sales.Find(saleid);
         return(result);
     }
 }
Ejemplo n.º 13
0
 public void Add_Service(JobDetail item)
 {
     using (var context = new eBikesContext())
     {
         context.JobDetails.Add(item);
         context.SaveChanges();
     }
 }
 public void Add_UnorderedPart(UnorderedPurchaseItemCart item)
 {
     using (var context = new eBikesContext())
     {
         context.UnorderedPurchaseItemCarts.Add(item);
         context.SaveChanges();
     }
 } //eom
 public void DeleteCartItem(int shoppingCarItemtId)
 {
     using (var context = new eBikesContext())
     {
         var cartItem = context.ShoppingCartItems.Find(shoppingCarItemtId);
         context.ShoppingCartItems.Remove(cartItem);
         context.SaveChanges();
     }
 }
        public List <UnorderedPurchaseItemCart> Get_UnorderedParts()
        {
            using (var context = new eBikesContext())
            {
                var results = context.UnorderedPurchaseItemCarts;

                return(results.ToList());
            }
        } //eom
Ejemplo n.º 17
0
 public void RemoveUnorderedItem(UnorderedPart item)
 {
     using (var context = new eBikesContext())
     {
         var existingItem = context.UnorderedPurchaseItemCarts.Find(item.CartID);
         context.UnorderedPurchaseItemCarts.Remove(existingItem);
         context.SaveChanges();
     }
 }
Ejemplo n.º 18
0
 public List <StandardJob> List_Preset()
 {
     using (var context = new eBikesContext())
     {
         var results = from x in context.StandardJobs
                       select x;
         return(results.ToList());
     }
 }
 public DateTime UpdateDate(int shoppingCartID)
 {
     using (var context = new eBikesContext())
     {
         DateTime date = DateTime.Today;
         date = (DateTime)(context.ShoppingCarts.Where(x => x.ShoppingCartID == shoppingCartID).Select(x => x.UpdatedOn)).SingleOrDefault();
         return(date);
     }
 }
 public List <Coupon> GetListOfAvailableCoupons(DateTime currentDate)
 {
     using (var context = new eBikesContext())
     {
         var results = (from x in context.Coupons
                        where x.EndDate >= currentDate && x.SalesOrService == 1
                        select x).ToList();
         return(results);
     }
 }
 public int getEmployeeID(string username)
 {
     using (var context = new eBikesContext())
     {
         var employee = (from person in context.Employees
                         where (person.FirstName + "." + person.LastName) == username
                         select person.EmployeeID).FirstOrDefault();
         return(employee);
     }
 }
Ejemplo n.º 22
0
 public List <StandardJob> Job_GetByID(int standardJobID)
 {
     using (var context = new eBikesContext())
     {
         var results = from x in context.StandardJobs
                       where x.StandardJobID == standardJobID
                       select x;
         return(results.ToList());
     }
 }
 public decimal GetCouponAmount(int couponId)
 {
     using (var context = new eBikesContext())
     {
         int cpnAmount = (from x in context.Coupons
                          where x.CouponID == couponId
                          select x.CouponDiscount).FirstOrDefault();
         decimal cpnPercent = cpnAmount / Convert.ToDecimal(100.00);
         return(cpnPercent);
     }
 }
        public List <Coupon> List_Coupon()
        {
            using (var context = new eBikesContext())
            {
                var results = from x in context.Coupons
                              where x.SalesOrService == 2
                              select x;

                return(results.ToList());
            }
        }
        public void UpdateCartItemQty(int shoppingCarItemtId, int qty)
        {
            using (var context = new eBikesContext())
            {
                var cartItem = context.ShoppingCartItems.Find(shoppingCarItemtId);

                cartItem.Quantity             = qty;
                context.Entry(cartItem).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
 public int RetriveShoppingCartId(string user)
 {
     using (var context = new eBikesContext())
     {
         var existingOnlineCustomerID = Convert.ToInt32((from c in context.OnlineCustomers
                                                         where c.UserName == user
                                                         select c.OnlineCustomerID).SingleOrDefault());
         var existingShoppingCartId = Convert.ToInt32((from s in context.ShoppingCarts
                                                       where s.OnlineCustomer.OnlineCustomerID == existingOnlineCustomerID
                                                       select s.ShoppingCartID).SingleOrDefault());
         return(existingShoppingCartId);
     }
 }
 public List <POCOCustomer> ListAllCustomers()
 {
     using (var context = new eBikesContext())
     {
         var result = from customer in context.Customers
                      select new POCOCustomer
         {
             CustomerID = customer.CustomerID,
             FullName   = customer.LastName + " " + customer.FirstName
         };
         return(result.ToList());
     }
 }
 public List <POCOCoupon> ListAllCoupon()
 {
     using (var context = new eBikesContext())
     {
         var result = from c in context.Coupons
                      select new POCOCoupon
         {
             CouponID      = c.CouponID,
             CouponIDValue = c.CouponIDValue
         };
         return(result.ToList());
     }
 }
        public void Add_Job(Job item, CurrentJobServiceDetails currentJobDetails)
        {
            using (var context = new eBikesContext())
            {
                context.Jobs.Add(item);
                JobDetail newjobDetail = new JobDetail();
                newjobDetail.CouponID    = currentJobDetails.CouponID;
                newjobDetail.Comments    = currentJobDetails.Comments;
                newjobDetail.Description = currentJobDetails.Description;
                newjobDetail.JobHours    = currentJobDetails.Hours;

                item.JobDetails.Add(newjobDetail);
            }
        }
 public List <CategoryPoco> CategoriesList()
 {
     using (var context = new eBikesContext())
     {
         var results = from c in context.Categories
                       select new CategoryPoco
         {
             CategoryID    = c.CategoryID,
             CategoryDesc  = c.Description,
             CategoryCount = c.Parts.Count()
         };
         return(results.ToList());
     }
 }