示例#1
0
 public void AddDefaultUsers()
 {
     using (var context = new eToolDBContext())
     {
         var onlieUser = from data in context.OnlineCustomers where data.OnlineCustomerID == 0 select data;
         foreach (var person in onlieUser)
         {
             if (!Users.Any(u => u.OnlineCustomerID.HasValue && u.OnlineCustomerID.Value == person.OnlineCustomerID))
             {
                 string Name    = string.Format(STR_USERNAME_FORMAT, person.UserName);
                 var    appUser = new ApplicationUser()
                 {
                     UserName         = Name,
                     Email            = string.Format(STR_EMAIL_FORMAT),
                     OnlineCustomerID = person.OnlineCustomerID
                 };
                 this.Create(appUser, STR_DEFAULT_PASSWORD);
             }
         }
         // Add a web  master user
         if (!Users.Any(u => u.UserName.Equals(STR_WEBMASTER_USERNAME)))
         {
             var webMasterAccount = new ApplicationUser()
             {
                 UserName = STR_WEBMASTER_USERNAME,
                 Email    = string.Format(STR_EMAIL_FORMAT, STR_WEBMASTER_USERNAME)
             };
             this.Create(webMasterAccount, STR_DEFAULT_PASSWORD);
         }
     }
 }
 public List <Sale> getSales()
 {
     using (var context = new eToolDBContext())
     {
         return(context.Sales.ToList());
     }
 }
        public List <CategoryPOCOs> getCategoryBrowse()
        {
            using (var context = new eToolDBContext())
            {
                var data = from Category in context.Categories
                           orderby Category.Description
                           select new CategoryPOCOs()
                {
                    ID          = Category.CategoryID,
                    Description = Category.Description,
                    ConutItems  = (from Item in Category.StockItems select Item.StockItemID).Count(),
                    AllItems    = 0
                };

                return(data.ToList());
            }
        }
 public void AddToOnlineCustomer(Guid TrC, string Name)
 {
     using (var context = new eToolDBContext())
     {
         var Customer = context.OnlineCustomers.SingleOrDefault(x => x.TrackingCookie == TrC);
         if (Customer == null)
         {
             Customer = new OnlineCustomer
             {
                 //OnlineCustomerID = ID,
                 UserName  = Name,
                 CreatedOn = DateTime.Now,
             };
             context.OnlineCustomers.Add(Customer);
             context.SaveChanges();
         }
     }
 }
        public void AddToCart(int ProductId, int Quantities)
        {
            eToolDBContext ShoppingCartHeart = new eToolDBContext();

            var cartItem = ShoppingCartHeart.ShoppingCartItems.SingleOrDefault(x => x.StockItem.StockItemID == ProductId && x.ShoppingCartID == ProductId);

            if (cartItem == null)
            {
                cartItem = new ShoppingCartItem
                {
                    ShoppingCartID = ProductId,
                    StockItemID    = ProductId,
                    Quantity       = Quantities
                };
                ShoppingCartHeart.ShoppingCartItems.Add(cartItem);
            }
            else
            {
                Quantities = cartItem.Quantity + Quantities;
            }
            ShoppingCartHeart.SaveChanges();

            //var cartItem = addData.StockItems.Single(x => x.StockItemID == ProductId);
            //cartItem = new StockItem
            //{
            //    StockItemID = ProductId,
            //    Description = cartItem.Description,
            //    SellingPrice = cartItem.SellingPrice,
            //    PurchasePrice = cartItem.PurchasePrice,
            //    QuantityOnHand = cartItem.QuantityOnHand,
            //    QuantityOnOrder = Quantities,
            //    ReOrderLevel = cartItem.ReOrderLevel,
            //    Discontinued = cartItem.Discontinued,
            //    VendorID = cartItem.VendorID,
            //    VendorStockNumber = cartItem.VendorStockNumber,
            //    CategoryID = cartItem.CategoryID
            //};

            //addData.StockItems.Add(cartItem);

            //addData.SaveChanges();
        }
        public List <StockItemPOCOs> getProductMenu(int id)
        {
            using (var context = new eToolDBContext())
            {
                if (id != 0)
                {
                    var dataA = from StockItem in context.StockItems
                                where StockItem.Category.CategoryID == id &&
                                StockItem.Discontinued == false
                                select new StockItemPOCOs
                    {
                        ID             = StockItem.Category.CategoryID,
                        StockItemID    = StockItem.StockItemID,
                        SellingPrice   = StockItem.SellingPrice,
                        Description    = StockItem.Description,
                        QuantityOnHand = StockItem.QuantityOnHand
                    };
                    return(dataA.ToList());
                }

                else
                {
                    var dataB = from StockItem in context.StockItems
                                where StockItem.Discontinued == false
                                select new StockItemPOCOs
                    {
                        ID             = StockItem.Category.CategoryID,
                        StockItemID    = StockItem.StockItemID,
                        SellingPrice   = StockItem.SellingPrice,
                        Description    = StockItem.Description,
                        QuantityOnHand = StockItem.QuantityOnHand
                    };
                    return(dataB.ToList());
                }
            }
        }