//********************Save category public void SaveCategory(Category category) { using (var context = new FAContext()) { context.Categories.Add(category); context.SaveChanges(); } }
//********************Update category public void UpdateCategory(Category category) { using (var context = new FAContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
//********************Update Products public void UpdateProduct(Product Product) { using (var context = new FAContext()) { context.Entry(Product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public int SaveOrder(Order order) { using (var context = new FAContext()) { context.Orders.Add(order); return(context.SaveChanges()); } }
public object UpdateOrderStatus(int ID, string status) { using (var context = new FAContext()) { var order = context.Orders.Find(ID); order.status = status; context.Entry(order).State = EntityState.Modified; return(context.SaveChanges() > 0); } }
//********************Save Products public void SaveProduct(Product Product) { using (var context = new FAContext()) { context.Entry(Product.Category).State = System.Data.Entity.EntityState.Unchanged; context.Products.Add(Product); context.SaveChanges(); } }
//********************Delete Products public void DeleteProduct(int ID) { using (var context = new FAContext()) { var Product = context.Products.Find(ID); context.Products.Remove(Product); context.SaveChanges(); } }
//********************Delete category***** public void DeleteCategory(int ID) { using (var context = new FAContext()) { var categoty = context.Categories.Where(x => x.ID == ID).Include(x => x.Products).FirstOrDefault(); context.Products.RemoveRange(categoty.Products); context.Categories.Remove(categoty); context.SaveChanges(); } }