Ejemplo n.º 1
0
 public static int AddReview(Review review)
 {
     using (var _context = new EduShopEntities())
     {
         _context.ReviewSet.Add(review);
         return(_context.SaveChanges());
     }
 }
Ejemplo n.º 2
0
 public static int AddOrderRow(OrderRow orderRow)
 {
     using (var _context = new EduShopEntities())
     {
         _context.OrderRowSet.AddOrUpdate(orderRow);
         return(_context.SaveChanges());
     }
 }
Ejemplo n.º 3
0
 public static List <Product> GetProducts()
 {
     using (var _context = new EduShopEntities())
     {
         return
             ((from c in _context.ProductSet
               select c).ToList());
     }
 }
Ejemplo n.º 4
0
 public static UserModel GetUserOnEmail(string email)
 {
     using (var _context = new EduShopEntities())
     {
         return(ConvertToUserModel((from c in _context.UserSet
                                    where c.Email == email
                                    select c).FirstOrDefault()));
     }
 }
Ejemplo n.º 5
0
 public static UserModel GetUser(string password)
 {
     using (var _context = new EduShopEntities())
     {
         return(ConvertToUserModel((from c in _context.UserSet
                                    where c.Password == password
                                    select c).FirstOrDefault()));
     }
 }
Ejemplo n.º 6
0
 public static int AddUser(User user)
 {
     using (var _context = new EduShopEntities())
     {
         user.Password = PasswordHash.CreateHash(user.Password);
         _context.UserSet.AddOrUpdate(user);
         return(_context.SaveChanges());
     }
 }
Ejemplo n.º 7
0
 public static OrderModel GetLastOrder()
 {
     using (var _context = new EduShopEntities())
     {
         return(ConvertToOrderModel((from c in _context.OrderSet
                                     orderby c.Id descending
                                     select c).FirstOrDefault()));
     }
 }
Ejemplo n.º 8
0
 public static List <Product> GetProductsOnSearch(string search)
 {
     using (var _context = new EduShopEntities())
     {
         return((
                    from c in _context.ProductSet
                    where c.Category.Contains(search) || c.Name.Contains(search)
                    select c).ToList());
     }
 }
Ejemplo n.º 9
0
 public static List <Product> GetProductsOnCategory(string category)
 {
     using (var _context = new EduShopEntities())
     {
         return((
                    from c in _context.ProductSet
                    where c.Category == category
                    select c).ToList());
     }
 }
Ejemplo n.º 10
0
 public static Product GetProduct(int id)
 {
     using (var _context = new EduShopEntities())
     {
         return((
                    from c in _context.ProductSet
                    where c.Id == id
                    select c).FirstOrDefault());
     }
 }
Ejemplo n.º 11
0
 public static User CheckForUser(UserModel userModel)
 {
     using (var _context = new EduShopEntities())
     {
         return((
                    from c in _context.UserSet
                    where c.Email == userModel.Email
                    select c).FirstOrDefault());
     }
 }
Ejemplo n.º 12
0
 public static List <Review> GetReviews(int id)
 {
     using (var _context = new EduShopEntities())
     {
         return((
                    from c in _context.ReviewSet
                    where c.ProductId == id
                    orderby c.DateAdded descending
                    select c).ToList());
     }
 }
Ejemplo n.º 13
0
        public static int AddOrUpdateProductRating(int id)
        {
            using (var _context = new EduShopEntities())
            {
                int     rating  = ReviewModel.CalculateAverageRating(id);
                Product product = GetProduct(id);
                product.AverageRating = rating;

                _context.ProductSet.AddOrUpdate(product);
                return(_context.SaveChanges());
            }
        }
Ejemplo n.º 14
0
        public static List <UserModel> GetAllUsers()
        {
            using (var _context = new EduShopEntities())
            {
                var         userModelList = new List <UserModel>();
                List <User> userList      = (from c in _context.UserSet
                                             select c).ToList();

                foreach (var item in userList)
                {
                    userModelList.Add(ConvertToUserModel(item));
                }

                return(userModelList);
            }
        }
Ejemplo n.º 15
0
        public static bool CheckIfUSerEmailIsUnique(User user)
        {
            using (var _context = new EduShopEntities())
            {
                var query = (from u in _context.UserSet
                             where u.Email == user.Email
                             select u).Count();

                if (query > 0)
                {
                    return(false);
                }

                AddUser(user);

                return(true);
            }
        }