public List <Category> GetCategories() { using (var context = new NMContext()) { return(context.Categories.ToList()); } }
public List <Category> GetFeaturedCategories() { using (var context = new NMContext()) { return(context.Categories.Where(x => x.isFeatured && x.ImageURL != null).ToList());//.Where(x => x.isFeatured) } }
public Config GetConfig(string Key) { using (var context = new NMContext()) { return(context.Configurations.Find(Key)); } }
public Product GetProduct(int ID) { using (var context = new NMContext()) { return(context.Products.Find(ID)); } }
public List <Product> GetProducts(List <int> IDs) { using (var context = new NMContext()) { return(context.Products.Where(product => IDs.Contains(product.ID)).ToList()); } }
public Category GetCategory(int ID) { using (var context = new NMContext()) { return(context.Categories.Find(ID)); } }
public void UpdateCategory(Category category) { using (var context = new NMContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void SaveCategory(Category category) { using (var context = new NMContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public void UpdateProduct(Product product) { using (var context = new NMContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
public UnitOfWork(NMContext context) { this._context = context; }
public void GetNewContext() { this._context = new NMContext(); }
public BaseRepository(NMContext context) { this.context = context; this.dbSet = context.Set <TEntity>(); }