Example #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();
     }
 }
Example #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();
                }
            }
Example #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;
 }
Example #4
0
 private void addBtn_Click(object sender, EventArgs e)
 {
     if (nameEditTxt.Text != "")
     {
         CategoryDTO dto = new CategoryDTO();
         CategoriesDAL c = new CategoriesDAL();
         dto.categ_name = nameEditTxt.Text;
         dto.id_categ = Convert.ToInt32(idEditTxt.Text);
         c.updateCategory(dto);
         loadData();
         MessageBox.Show("Edited");
     }
     else
     {
         MessageBox.Show("select row for editing");
     }
     
 }
Example #5
0
 private void addBtn_Click(object sender, EventArgs e)
 {
     CategoryDTO dto=new CategoryDTO();
     CategoriesDAL c = new CategoriesDAL();
     dto = c.GetCategoryByName(nameTxt.Text);
     if (dto == null)
     {
         MessageBox.Show("Category is not found!");
     }
     else
     {
         c.deleteCategory(dto);
         loadData();
         clearText();
         MessageBox.Show("Deleted!");
     } 
 }
Example #6
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            CategoryDTO dto=new CategoryDTO();
            CategoriesDAL c = new CategoriesDAL();
            dto.categ_name = nameTxt.Text;
            c.insertCategory(dto);
            start = (c.CountCateg() / size) * size;
            loadData();
            clearText();
            MessageBox.Show("Added!");

           
        }
Example #7
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();
     }
 }