/// <summary> /// Добавляет задачу в БД /// </summary> /// <param name="task"></param> private void AddTaskDb(Task task) { using (var context = new PlannerContext()) { context.Tasks.Add(task); context.SaveChanges(); } }
/// <summary> /// Добавляет категорию в БД /// </summary> /// <param name="category"> Категория </param> private void AddCategoryDb(Category category) { using (var context = new PlannerContext()) { context.Categories.Add(category); context.SaveChanges(); } }
/// <summary> /// Удаляет задачу /// </summary> /// <param name="id">Id задачи</param> public void DeleteTask(int id) { using (var context = new PlannerContext()) { var task = context.Tasks.FirstOrDefault(x => x.Id == id); context.Tasks.Remove(task); context.SaveChanges(); } Tasks = GetTasks(); }
/// <summary> /// Снимает пометку просроченности у задачи /// </summary> /// <param name="taskId">Id задачи</param> public void UnOverdueTask(int taskId) { using (var context = new PlannerContext()) { var task = context.Tasks.FirstOrDefault(x => x.Id == taskId); task.IsOverdue = false; context.SaveChanges(); } Tasks = GetTasks(); }
/// <summary> /// Завершает задачу /// </summary> /// <param name="taskId">Id задачи</param> public void FinishTask(int taskId) { using (var context = new PlannerContext()) { var task = context.Tasks.FirstOrDefault(x => x.Id == taskId); task.FinishDate = DateTime.Now; task.IsFinished = true; context.SaveChanges(); } Tasks = GetTasks(); }
/// <summary> /// Редактирует задачу /// </summary> /// <param name="editedTask">Задача</param> public void EditTask(Task editedTask) { using (var context = new PlannerContext()) { var task = context.Tasks.FirstOrDefault(x => x.Id == editedTask.Id); task.Name = editedTask.Name; task.CreationDate = editedTask.CreationDate; task.StartDate = editedTask.StartDate; task.EndDate = editedTask.EndDate; task.PriorityId = editedTask.PriorityId; task.CategoryId = editedTask.CategoryId; context.SaveChanges(); } }