public void AddDepartment(Department dept) { using (GarmentsContext contex = new GarmentsContext()) { contex.Departments.Add(dept); contex.SaveChanges(); } }
//Update User public void UpdateUser(User UserUP) { using (GarmentsContext context = new GarmentsContext()) { context.Entry(UserUP).State = EntityState.Modified; context.SaveChanges(); } }
public void DeleteCategory(int id) { using (GarmentsContext context = new GarmentsContext()) { Category found = context.Categories.Find(id); context.Categories.Remove(found); 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(); } }
//Add new User public void AddUser(User user) { using (GarmentsContext context = new GarmentsContext()) { if (user != null) { context.Users.Add(user); context.SaveChanges(); } } }
public void DeleteDepartment(int idToSearch) { using (GarmentsContext contex = new GarmentsContext()) { Department found = (from d in contex.Departments where d.Id == idToSearch select d).First(); contex.Departments.Remove(found); contex.SaveChanges(); } }
public void UpdateDepartment(int idToSearch, Department dept) { using (GarmentsContext contex = new GarmentsContext()) { Department found = (from d in contex.Departments where d.Id == idToSearch select d).First(); if (!string.IsNullOrWhiteSpace(dept.Name)) { found.Name = dept.Name; } found.ImageUrl = dept.ImageUrl; contex.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(); } }