//Update User public void UpdateUser(User UserUP) { using (GarmentsContext context = new GarmentsContext()) { context.Entry(UserUP).State = EntityState.Modified; context.SaveChanges(); } }
public void AddCategory(Category category) { using (GarmentsContext context = new GarmentsContext()) { context.Entry(category.Department).State = EntityState.Unchanged; context.Categories.Add(category); context.SaveChanges(); } }
public void AddProduct(Product product) { using (GarmentsContext context = new GarmentsContext()) { context.Entry(product.Fabric).State = EntityState.Unchanged; context.Entry(product.SubCategory).State = EntityState.Unchanged; foreach (var c in product.ColorsOffered) { context.Entry(c).State = EntityState.Unchanged; } foreach (var s in product.SizesOffered) { context.Entry(s).State = EntityState.Unchanged; } context.Products.Add(product); context.SaveChanges(); } }
public void UpdateCategory(int id, Category category) { using (GarmentsContext context = new GarmentsContext()) { Category found = context.Categories.Find(id); if (!string.IsNullOrWhiteSpace(category.Name)) { found.Name = category.Name; } if (!string.IsNullOrWhiteSpace(category.ImageUrl)) { found.ImageUrl = category.ImageUrl; } if (category.Department != null && category.Department.Id > 0) { found.Department = category.Department; } context.Entry(category.Department).State = EntityState.Unchanged; context.SaveChanges(); } }