示例#1
0
 public void AddDepartment(Department dept)
 {
     using (GarmentsContext contex = new GarmentsContext())
     {
         contex.Departments.Add(dept);
         contex.SaveChanges();
     }
 }
示例#2
0
        //Update User

        public void UpdateUser(User UserUP)
        {
            using (GarmentsContext context = new GarmentsContext())
            {
                context.Entry(UserUP).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
示例#3
0
 public void DeleteCategory(int id)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         Category found = context.Categories.Find(id);
         context.Categories.Remove(found);
         context.SaveChanges();
     }
 }
示例#4
0
 public void AddCategory(Category category)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         context.Entry(category.Department).State = EntityState.Unchanged;
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
示例#5
0
 //Add new User
 public void AddUser(User user)
 {
     using (GarmentsContext context = new GarmentsContext())
     {
         if (user != null)
         {
             context.Users.Add(user);
             context.SaveChanges();
         }
     }
 }
示例#6
0
 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();
     }
 }
示例#7
0
 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();
     }
 }
示例#8
0
        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();
            }
        }
示例#9
0
 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();
     }
 }