コード例 #1
0
 public void DeleteBrand(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.BrandsModel.Select(p => p.BrandId == id));
         context.SaveChanges();
     }
 }
コード例 #2
0
 public void InsertBrand(BrandsModel brandsModel)
 {
     using (var context = new WebShopContext())
     {
         context.BrandsModel.Add(brandsModel);
         context.SaveChanges();
     }
 }
コード例 #3
0
 public void InsertCategory(CategoriesModel categoriesModel)
 {
     using (var context = new WebShopContext())
     {
         context.CategoriesModel.Add(categoriesModel);
         context.SaveChanges();
     }
 }
コード例 #4
0
 public void InsertRecipe(RecipesModel recipesModel)
 {
     using (var context = new WebShopContext())
     {
         context.RecipesModel.Add(recipesModel);
         context.SaveChanges();
     }
 }
コード例 #5
0
 public void InsertProduct(ProductModel productModel)
 {
     using (var context = new WebShopContext())
     {
         context.ProductModel.Add(productModel);
         context.SaveChanges();
     }
 }
コード例 #6
0
 public void DeleteRecipe(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.RecipesModel.Select(p => p.RecipeId == id));
         context.SaveChanges();
     }
 }
コード例 #7
0
 public void DeleteOrder(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.OrdersModel.Select(p => p.OrderId == id));
         context.SaveChanges();
     }
 }
コード例 #8
0
 public void InsertOrder(OrdersModel ordersModel)
 {
     using (var context = new WebShopContext())
     {
         context.OrdersModel.Add(ordersModel);
         context.SaveChanges();
     }
 }
コード例 #9
0
 public void InsertUser(UserModel userModel)
 {
     using (var context = new WebShopContext())
     {
         context.UserModel.Add(userModel);
         context.SaveChanges();
     }
 }
コード例 #10
0
 public void InsertContact(ContactModel contactModel)
 {
     using (var context = new WebShopContext())
     {
         context.ContactModel.Add(contactModel);
         context.SaveChanges();
     }
 }
コード例 #11
0
 public void DeleteProduct(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.ProductModel.Select(p => p.ProductId == id));
         context.SaveChanges();
     }
 }
コード例 #12
0
 public void DeleteCategory(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.CategoriesModel.Select(p => p.CategoryId == id));
         context.SaveChanges();
     }
 }
コード例 #13
0
 public UserModel DeleteMaxId(List <UserModel> list)
 {
     using (var context = new WebShopContext())
     {
         var       id         = list.Max(u => u.UserId);
         UserModel deleteUser = context.UserModel.Where(u => u.UserId == id).FirstOrDefault();
         context.UserModel.Remove(deleteUser);
         context.SaveChanges();
         return(deleteUser);
     }
 }
コード例 #14
0
        public int OrderToBase(int userId, decimal totalPrice)
        {
            var dateTime = DateTime.Now;
            int orderId;

            using (var context = new WebShopContext())
            {
                OrdersModel order = new OrdersModel(userId, dateTime, totalPrice);
                context.OrdersModel.Add(order);
                context.SaveChanges();
                OrdersModel orderForUser = context.OrdersModel.Where(p => p.UserId == userId && p.Date == dateTime).FirstOrDefault();
                orderId = orderForUser.OrderId;
            }
            return(orderId);
        }
コード例 #15
0
 public void UpdateProduct(ProductModel productModel)
 {
     using (var context = new WebShopContext())
     {
         try
         {
             // context.ProductModel.Attach(productModel);
             context.Entry(productModel).State = EntityState.Modified;
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             throw;
         }
     }
 }
コード例 #16
0
 public void UpdateOrder(OrdersModel ordersModel)
 {
     using (var context = new WebShopContext())
     {
         var result = context.OrdersModel.SingleOrDefault(b => b.OrderId == ordersModel.OrderId);
         if (result != null)
         {
             try
             {
                 context.OrdersModel.Attach(ordersModel);
                 context.Entry(ordersModel).State = EntityState.Modified;
                 context.SaveChanges();
             }
             catch (Exception ex)
             {
                 throw;
             }
         }
     }
 }
コード例 #17
0
 public void UpdateBrand(BrandsModel brandsModel)
 {
     using (var context = new WebShopContext())
     {
         var result = context.BrandsModel.SingleOrDefault(b => b.BrandId == brandsModel.BrandId);
         if (result != null)
         {
             try
             {
                 context.BrandsModel.Attach(brandsModel);
                 context.Entry(brandsModel).State = EntityState.Modified;
                 context.SaveChanges();
             }
             catch (Exception ex)
             {
                 throw;
             }
         }
     }
 }
コード例 #18
0
 public void UpdateRecipe(RecipesModel recipesModel)
 {
     using (var context = new WebShopContext())
     {
         var result = context.RecipesModel.SingleOrDefault(b => b.RecipeId == recipesModel.RecipeId);
         if (result != null)
         {
             try
             {
                 context.RecipesModel.Attach(recipesModel);
                 context.Entry(recipesModel).State = EntityState.Modified;
                 context.SaveChanges();
             }
             catch (Exception ex)
             {
                 throw;
             }
         }
     }
 }
コード例 #19
0
 public void UpdateCategory(CategoriesModel categoriesModel)
 {
     using (var context = new WebShopContext())
     {
         var result = context.CategoriesModel.SingleOrDefault(b => b.CategoryId == categoriesModel.CategoryId);
         if (result != null)
         {
             try
             {
                 context.CategoriesModel.Attach(categoriesModel);
                 context.Entry(categoriesModel).State = EntityState.Modified;
                 context.SaveChanges();
             }
             catch (Exception ex)
             {
                 throw ex;
             }
         }
     }
 }
コード例 #20
0
        public CheckoutModel ProductToCard(string sessionKey, List <ProductModel> productFromSessionCard)
        {
            int     userId     = Convert.ToInt32(sessionKey);
            decimal totalPrice = productFromSessionCard.Sum(p => p.SessionPrice);
            int     orderId    = OrderToBase(userId, totalPrice);

            using (var context = new WebShopContext())
            {
                foreach (ProductModel item in productFromSessionCard)
                {
                    OrderLineModel orderline = new OrderLineModel(orderId, item.ProductId, item.SessionQuantity, item.SessionPrice);
                    context.OrderLineModel.Add(orderline);
                }
                context.SaveChanges();
                CheckoutModel checkoutModel = new CheckoutModel();
                checkoutModel.orderLines = context.OrderLineModel.Where(p => p.OrderId == orderId).ToList();
                checkoutModel.order      = context.OrdersModel.Where(p => p.OrderId == orderId).FirstOrDefault();
                checkoutModel.user       = context.UserModel.Where(p => p.UserId == userId).FirstOrDefault();
                return(checkoutModel);
            }
        }