public int GetMaximumPrice()
 {
     using (var context = new GPSContext())
     {
         return((int)(context.Products.Max(x => x.Price)));
     }
 }
 public List <Product> GetProductsByCategory(int categoryID, int pageSize)
 {
     using (var context = new GPSContext())
     {
         return(context.Products.Where(x => x.Category.ID == categoryID).OrderByDescending(x => x.ID).Take(pageSize).Include(x => x.Category).ToList());
     }
 }
Ejemplo n.º 3
0
 public IEnumerable <TEntity> GetAll(int QTDE)
 {
     using (var ctx = new GPSContext())
     {
         return(ctx.Set <TEntity>().Take(QTDE).ToList());
     }
 }
Ejemplo n.º 4
0
 public Config GetConfig(string Key)
 {
     using (var context = new GPSContext())
     {
         return(context.Configurations.Find(Key));
     }
 }
Ejemplo n.º 5
0
 public TEntity GetById(int id)
 {
     using (var ctx = new GPSContext())
     {
         return(ctx.Set <TEntity>().Find(id));
     }
 }
Ejemplo n.º 6
0
 public Empresa GetByCNPJ(string cnpj)
 {
     using (var ctx = new GPSContext())
     {
         return(ctx.Empresas.FirstOrDefault(x => x.Cnpj == cnpj));
     }
 }
Ejemplo n.º 7
0
 public void Remove(TEntity obj)
 {
     using (var ctx = new GPSContext())
     {
         ctx.Set <TEntity>().Remove(obj);
     }
 }
 public Order GetOrderByID(int ID)
 {
     using (var context = new GPSContext())
     {
         return(context.Orders.Where(x => x.ID == ID).Include(x => x.OrderItems).Include("OrderItems.Product").FirstOrDefault());
     }
 }
Ejemplo n.º 9
0
 public Category GetCategory(int ID)
 {
     using (var context = new GPSContext())
     {
         return(context.Categories.Find(ID));
     }
 }
 public List <Product> GetProducts(string search, int pageNo, int pageSize)
 {
     using (var context = new GPSContext())
     {
         if (!string.IsNullOrEmpty(search))
         {
             return(context.Products.Where(product => product.Name != null &&
                                           product.Name.ToLower().Contains(search.ToLower()))
                    .OrderBy(x => x.ID)
                    .Skip((pageNo - 1) * pageSize)
                    .Take(pageSize)
                    .Include(x => x.Category)
                    .ToList());
         }
         else
         {
             return(context.Products
                    .OrderBy(x => x.ID)
                    .Skip((pageNo - 1) * pageSize)
                    .Take(pageSize)
                    .Include(x => x.Category)
                    .ToList());
         }
     }
 }
 public List <Product> GetLatestProducts(int numberOfProducts)
 {
     using (var context = new GPSContext())
     {
         return(context.Products.OrderByDescending(x => x.ID).Take(numberOfProducts).Include(x => x.Category).ToList());
     }
 }
 public List <Product> GetProducts(int pageNo, int pageSize)
 {
     using (var context = new GPSContext())
     {
         return(context.Products.OrderByDescending(x => x.ID).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList());
     }
 }
Ejemplo n.º 13
0
        public List <Category> GetCategories(string search, int pageNo)
        {
            int pageSize = 3;

            using (var context = new GPSContext())
            {
                if (!string.IsNullOrEmpty(search))
                {
                    return(context.Categories.Where(category => category.Name != null &&
                                                    category.Name.ToLower().Contains(search.ToLower()))
                           .OrderBy(x => x.ID)
                           .Skip((pageNo - 1) * pageSize)
                           .Take(pageSize)
                           .Include(x => x.Products)
                           .ToList());
                }
                else
                {
                    return(context.Categories
                           .OrderBy(x => x.ID)
                           .Skip((pageNo - 1) * pageSize)
                           .Take(pageSize)
                           .Include(x => x.Products)
                           .ToList());
                }
            }
        }
 public List <Product> GetProducts(List <int> IDs)
 {
     using (var context = new GPSContext())
     {
         return(context.Products.Where(product => IDs.Contains(product.ID)).ToList());
     }
 }
 public void UpdateProduct(Product Product)
 {
     using (var context = new GPSContext())
     {
         context.Entry(Product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public void Add(TEntity obj)
 {
     using (var ctx = new GPSContext())
     {
         ctx.Set <TEntity>().Add(obj);
         ctx.SaveChanges();
     }
 }
 public Product GetProduct(int ID)
 {
     using (var context = new GPSContext())
     {
         //return context.Products.Find(ID);
         return(context.Products.Where(x => x.ID == ID).Include(x => x.Category).FirstOrDefault());
     }
 }
Ejemplo n.º 18
0
 public int SaveOrder(Order order)
 {
     using (var context = new GPSContext())
     {
         context.Orders.Add(order);
         return(context.SaveChanges());
     }
 }
Ejemplo n.º 19
0
 public void AddRange(IEnumerable <Empresa> empresas)
 {
     using (var ctx = new GPSContext())
     {
         ctx.Empresas.AddRange(empresas);
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 20
0
 public void UpdateCategory(Category category)
 {
     using (var context = new GPSContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 21
0
 public List <Category> GetFeaturedCategories()
 {
     using (var context = new GPSContext())
     {
         //return context.Categories.Where(x=>x.isFeatured && x.ImageURL !=null).ToList();
         return(context.Categories.Where(x => x.isFeatured && x.ImageURL != null).ToList());
     }
 }
Ejemplo n.º 22
0
 public List <Category> GetAllCategories()
 {
     using (var context = new GPSContext())
     {
         return(context.Categories
                .ToList());
     }
 }
Ejemplo n.º 23
0
 public void SaveCategory(Category category)
 {
     using (var context = new GPSContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
Ejemplo n.º 24
0
 public void Update(TEntity obj)
 {
     using (var ctx = new GPSContext())
     {
         ctx.Entry(obj).State = System.Data.Entity.EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Ejemplo n.º 25
0
        public int ShopPageSize()
        {
            using (var context = new GPSContext())
            {
                var pageSizeConfig = context.Configurations.Find("ShopPageSize");

                return(pageSizeConfig != null?int.Parse(pageSizeConfig.Value) : 6);
            }
        }
        public void SaveProduct(Product Product)
        {
            using (var context = new GPSContext())
            {
                context.Entry(Product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(Product);
                context.SaveChanges();
            }
        }
        public List <Product> GetProducts(int pageNo)
        {
            int pageSize = 5;// int.Parse(ConfigurationsService.Instance.GetConfig("ListingPageSize").Value);

            using (var context = new GPSContext())
            {
                return(context.Products.OrderBy(x => x.ID).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList());

                //return context.Products.Include(x => x.Category).ToList();
            }
        }
        public void DeleteProduct(int ID)
        {
            using (var context = new GPSContext())
            {
                var Product = context.Products.Find(ID);
                //context.Entry(category).State = System.Data.Entity.EntityState.Deleted;
                context.Products.Remove(Product);

                context.SaveChanges();
            }
        }
Ejemplo n.º 29
0
        public void DeleteCategory(int ID)
        {
            using (var context = new GPSContext())
            {
                var category = context.Categories.Where(x => x.ID == ID).Include(x => x.Products).FirstOrDefault();
                //context.Entry(category).State = System.Data.Entity.EntityState.Deleted;

                context.Products.RemoveRange(category.Products);
                context.Categories.Remove(category);

                context.SaveChanges();
            }
        }
        public bool UpdateOrderStatus(int ID, string status)
        {
            using (var context = new GPSContext())
            {
                var order = context.Orders.Find(ID);

                order.Status = status;

                context.Entry(order).State = EntityState.Modified;

                return(context.SaveChanges() > 0);
            }
        }