示例#1
0
 public List <UserModel> ReadUsers()
 {
     using (var context = new WebShopContext())
     {
         List <UserModel> users = context.UserModel.ToList();
         return(users);
     }
 }
示例#2
0
 public void InsertUser(UserModel userModel)
 {
     using (var context = new WebShopContext())
     {
         context.UserModel.Add(userModel);
         context.SaveChanges();
     }
 }
示例#3
0
 public UserModel GetUserByName(string name)
 {
     using (var context = new WebShopContext())
     {
         UserModel user = context.UserModel.Where(u => u.Name == name).FirstOrDefault();
         return(user);
     }
 }
 public void InsertContact(ContactModel contactModel)
 {
     using (var context = new WebShopContext())
     {
         context.ContactModel.Add(contactModel);
         context.SaveChanges();
     }
 }
示例#5
0
 public List <CategoriesModel> ReadCategories()
 {
     using (var context = new WebShopContext())
     {
         List <CategoriesModel> categories = context.CategoriesModel.ToList();
         return(categories);
     }
 }
示例#6
0
 public List <RecipesModel> ReadRecipes()
 {
     using (var context = new WebShopContext())
     {
         List <RecipesModel> recipes = context.RecipesModel.ToList();
         return(recipes);
     }
 }
示例#7
0
 public List <BrandsModel> ReadBrands()
 {
     using (var context = new WebShopContext())
     {
         List <BrandsModel> brands = context.BrandsModel.ToList();
         return(brands);
     }
 }
示例#8
0
 public void DeleteProduct(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.ProductModel.Select(p => p.ProductId == id));
         context.SaveChanges();
     }
 }
示例#9
0
 public BrandsModel getBrandByName(string name)
 {
     using (var context = new WebShopContext())
     {
         BrandsModel brand = context.BrandsModel.Where(p => p.Name == name).SingleOrDefault();
         return(brand);
     }
 }
示例#10
0
 public UserModel True(LoginModel loginModel)
 {
     using (var context = new WebShopContext())
     {
         UserModel user = context.UserModel.Where(u => u.Email == loginModel.Email && u.Password == loginModel.Password).FirstOrDefault();
         return(user);
     }
 }
示例#11
0
 public List <ProductModel> PriceRange(int min, int max)
 {
     using (var context = new WebShopContext())
     {
         List <ProductModel> listProducts = context.ProductModel.Where(p => (p.SalePrice <= Convert.ToDecimal(max) && p.SalePrice >= Convert.ToDecimal(min)) && (p.Price <= Convert.ToDecimal(max) && p.Price >= Convert.ToDecimal(min))).ToList();
         return(listProducts);
     }
 }
示例#12
0
 public void DeleteRecipe(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.RecipesModel.Select(p => p.RecipeId == id));
         context.SaveChanges();
     }
 }
示例#13
0
 public CategoriesModel getCategoryByName(string name)
 {
     using (var context = new WebShopContext())
     {
         CategoriesModel categorie = context.CategoriesModel.Where(p => p.Name == name).SingleOrDefault();
         return(categorie);
     }
 }
示例#14
0
 public List <ProductModel> ReadProducts()
 {
     using (var context = new WebShopContext())
     {
         List <ProductModel> products = context.ProductModel.ToList();
         return(products);
     }
 }
示例#15
0
 public List <OrdersModel> ReadOrders()
 {
     using (var context = new WebShopContext())
     {
         List <OrdersModel> orders = context.OrdersModel.ToList();
         return(orders);
     }
 }
示例#16
0
 public void DeleteCategory(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.CategoriesModel.Select(p => p.CategoryId == id));
         context.SaveChanges();
     }
 }
示例#17
0
 public void InsertOrder(OrdersModel ordersModel)
 {
     using (var context = new WebShopContext())
     {
         context.OrdersModel.Add(ordersModel);
         context.SaveChanges();
     }
 }
示例#18
0
 public void DeleteOrder(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.OrdersModel.Select(p => p.OrderId == id));
         context.SaveChanges();
     }
 }
示例#19
0
 public List <RestaurantsModel> ReadRestaurants()
 {
     using (var context = new WebShopContext())
     {
         List <RestaurantsModel> restaurants = context.RestaurantsModel.ToList();
         return(restaurants);
     }
 }
示例#20
0
 public List <ProductModel> GetProductsByCategory(int id)
 {
     using (var context = new WebShopContext())
     {
         List <ProductModel> products = context.ProductModel.Where(p => p.CategoryId == id).ToList();
         return(products);
     }
 }
示例#21
0
 public void InsertCategory(CategoriesModel categoriesModel)
 {
     using (var context = new WebShopContext())
     {
         context.CategoriesModel.Add(categoriesModel);
         context.SaveChanges();
     }
 }
示例#22
0
 public void InsertProduct(ProductModel productModel)
 {
     using (var context = new WebShopContext())
     {
         context.ProductModel.Add(productModel);
         context.SaveChanges();
     }
 }
示例#23
0
 public void InsertRecipe(RecipesModel recipesModel)
 {
     using (var context = new WebShopContext())
     {
         context.RecipesModel.Add(recipesModel);
         context.SaveChanges();
     }
 }
示例#24
0
 public List <ProductModel> Search(string searchBy)
 {
     using (var context = new WebShopContext())
     {
         List <ProductModel> products = context.ProductModel.Where(p => p.Name.Contains(searchBy)).ToList();
         return(products);
     }
 }
示例#25
0
 public void DeleteBrand(int id)
 {
     using (var context = new WebShopContext())
     {
         context.Remove(context.BrandsModel.Select(p => p.BrandId == id));
         context.SaveChanges();
     }
 }
示例#26
0
 public void InsertBrand(BrandsModel brandsModel)
 {
     using (var context = new WebShopContext())
     {
         context.BrandsModel.Add(brandsModel);
         context.SaveChanges();
     }
 }
示例#27
0
 public ProductModel ProductDetail(int productId)
 {
     using (var context = new WebShopContext())
     {
         ProductModel productModel = context.ProductModel.Where(p => p.ProductId == productId).FirstOrDefault();
         productModel.categoryModel = context.CategoriesModel.Where(p => p.CategoryId == productModel.CategoryId).FirstOrDefault();
         productModel.brandModel    = context.BrandsModel.Where(p => p.BrandId == productModel.BrandId).FirstOrDefault();
         return(productModel);
     }
 }
示例#28
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);
     }
 }
 public List <OrderLineModel> ReadOrderLines()
 {
     using (var context = new WebShopContext())
     {
         List <OrderLineModel> orderLines = context.OrderLineModel.ToList();
         foreach (var item in orderLines)
         {
             item.Product = context.ProductModel.Where(p => p.ProductId == item.ProductId).FirstOrDefault();
         }
         return(orderLines);
     }
 }
        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);
        }