Пример #1
0
 public void updateCategory(CategoryDTO updatedCategory)
 {
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         var category = context.Categories.FirstOrDefault(c => c.id_categ == updatedCategory.id_categ);
         category.categ_name = updatedCategory.categ_name;
         context.SaveChanges();
     }
 }
Пример #2
0
            public void deleteCategory(CategoryDTO deletedCategory)
            {
                using (DeviceCategoryContext context = new DeviceCategoryContext())
                {
                    var category = (from c in context.Categories
                                    where c.categ_name == deletedCategory.categ_name
                                    select c).First();
                    context.Categories.Remove(category);

                    context.SaveChanges();
                }
            }
Пример #3
0
 public CategoryDTO GetCategoryByName(string categ_name)
 {
     var category = new CategoryDTO();
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         category = context.Categories.Select(c => new CategoryDTO
         {
             id_categ = c.id_categ,
             categ_name = c.categ_name
         }).FirstOrDefault(c => c.categ_name == categ_name);
     }
     return category;
 }
Пример #4
0
 public List<CategoryDTO> GetCategoriesSortedByName(int start, int take)
 {
     var categories = new List<CategoryDTO>();
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         categories = context.Categories.
             Select(c => new CategoryDTO
             {
                 id_categ = c.id_categ,
                 categ_name = c.categ_name
             }
         ).OrderBy(c => c.categ_name).Skip(start).Take(take).ToList();
     }
     return categories;
 }
Пример #5
0
 public void insertUser(UserDTO insertedUser)
 {
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         Users user = new Users();
         user.id_user = insertedUser.id_user;
         user.first_name = insertedUser.first_name;
         user.last_name = insertedUser.last_name;
         user.email = insertedUser.email;
         user.phone_number = insertedUser.phone_number;
         user.login = insertedUser.login;
         user.password = insertedUser.password;
         user.id_role = insertedUser.id_role;
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Пример #6
0
 public UserDTO GetUserByPassword(string password)
 {
     var user = new UserDTO();
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         user = context.Users.Select(u => new UserDTO
         {
             id_user = u.id_user,
             first_name = u.first_name,
             last_name = u.last_name,
             email = u.email,
             phone_number = u.phone_number,
             login = u.login,
             password = u.password,
             id_role = u.id_role
         }).FirstOrDefault(u => (u.password == password));
     }
     return user;
 }
Пример #7
0
 public int CountCateg()
 {
     int count;
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         count = context.Categories.Count();
     }
     return count;
 }
Пример #8
0
 public void insertCategory(CategoryDTO insertedCategory)
 {
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         Categories category = new Categories();
         category.categ_name = insertedCategory.categ_name;
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }