Exemple #1
0
 public List <Category> GetCategories()
 {
     using (var context = new NMContext())
     {
         return(context.Categories.ToList());
     }
 }
Exemple #2
0
 public List <Category> GetFeaturedCategories()
 {
     using (var context = new NMContext())
     {
         return(context.Categories.Where(x => x.isFeatured && x.ImageURL != null).ToList());//.Where(x => x.isFeatured)
     }
 }
Exemple #3
0
 public Config GetConfig(string Key)
 {
     using (var context = new NMContext())
     {
         return(context.Configurations.Find(Key));
     }
 }
Exemple #4
0
 public Product GetProduct(int ID)
 {
     using (var context = new NMContext())
     {
         return(context.Products.Find(ID));
     }
 }
Exemple #5
0
 public List <Product> GetProducts(List <int> IDs)
 {
     using (var context = new NMContext())
     {
         return(context.Products.Where(product => IDs.Contains(product.ID)).ToList());
     }
 }
Exemple #6
0
 public Category GetCategory(int ID)
 {
     using (var context = new NMContext())
     {
         return(context.Categories.Find(ID));
     }
 }
Exemple #7
0
 public void UpdateCategory(Category category)
 {
     using (var context = new NMContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemple #8
0
 public void SaveCategory(Category category)
 {
     using (var context = new NMContext())
     {
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
Exemple #9
0
 public void UpdateProduct(Product product)
 {
     using (var context = new NMContext())
     {
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemple #10
0
 public List <Product> GetLatestProducts(int numberOfProducts)
 {
     using (var context = new NMContext())
     {
         return(context.Products.OrderByDescending(x => x.ID).Take(numberOfProducts).Include(x => x.Category).ToList());
         //return context.Products.Include(x => x.Category).ToList();
     }
 }
Exemple #11
0
 public List <Product> GetProducts(int pageNo, int pageSize)
 {
     using (var context = new NMContext())
     {
         return(context.Products.OrderByDescending(x => x.ID).Skip((pageNo - 1) * pageSize).Take(pageSize).Include(x => x.Category).ToList());
         // return context.Products.Include(x => x.Category).ToList();
     }
 }
Exemple #12
0
        public void SaveProduct(Product product)
        {
            using (var context = new NMContext())
            {
                context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;

                context.Products.Add(product);
                context.SaveChanges();
            }
        }
Exemple #13
0
 public void DeleteCategory(int ID)
 {
     using (var context = new NMContext())
     {
         //context.Entry(category).State = System.Data.Entity.EntityState.Deleted;
         var category = context.Categories.Find(ID);
         context.Categories.Remove(category);
         context.SaveChanges();
     }
 }
Exemple #14
0
 public void DeleteProduct(int ID)
 {
     using (var context = new NMContext())
     {
         //context.Entry(category).State = System.Data.Entity.EntityState.Deleted;
         var product = context.Products.Find(ID);
         context.Products.Remove(product);
         context.SaveChanges();
     }
 }
Exemple #15
0
 public UnitOfWork(NMContext context)
 {
     this._context = context;
 }
Exemple #16
0
 public void GetNewContext()
 {
     this._context = new NMContext();
 }
 public BaseRepository(NMContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }