public void Add(string categoryName) { try { if (categoryName == null || categoryName == "") { throw new ArgumentNullException(); } TaskСategory taskCategory = new TaskСategory() { Name = categoryName }; context.TaskСategories.Create(taskCategory); context.SaveChanges(); } catch (Exception) { throw; } }
public void Edit(int categoryId, string categoryName) { try { if (categoryId <= 0 || categoryName == null || categoryName == "") { throw new ArgumentNullException(); } TaskСategory taskCategory = new TaskСategory() { Id = categoryId, Name = categoryName }; context.TaskСategories.Update(taskCategory); context.SaveChanges(); } catch (Exception) { throw; } }
public void Delete(int id) { try { if (id <= 0) { throw new ArgumentNullException(); } TaskСategory taskСategory = context.TaskСategories.GetAll().FirstOrDefault(c => c.Id == id); if (taskСategory == null) { throw new ArgumentNullException(); } context.TaskСategories.Delete(taskСategory); context.SaveChanges(); } catch (Exception) { throw; } }