protected void OnNotificationAdded(object source, Notification notification) { //update database with new notification NotificationDAL notificationDal = new NotificationDAL { taskId = notification.Producer.ID, time = notification.Time }; INotificationRepository notificationRepo = notificationRepositoryFactory.New(); notificationRepo.Add(notificationDal); ITaskItemRepository taskRepo = taskItemRepositoryFactory.New(); List <TaskItemDAL> tasks = new List <TaskItemDAL>(taskRepo.GetAll()); if (notification.Producer is TaskItem task) { //update the notifications producer in the database TaskItemDAL taskItemDAL = tasks.Find(t => t.id == task.ID); taskItemDAL.lastNotificationTime = task.LastNotificationTime; if (taskRepo.Update(taskItemDAL) == false) { //could not update task in database } //create DTO to invoke NotificationAdded with NotificationDTO dto = new NotificationDTO() { TaskId = task.ID, Time = notification.Time, Title = notification.Producer.Title, R = task.Colour.R, G = task.Colour.G, B = task.Colour.B }; //invoked event delegates NotificationAdded?.Invoke(source, dto); } taskRepo.Save(); notificationRepo.Save(); }
public ResultEntity <TaskItem> UpdateTask(TaskItemModel task) { ResultEntity <TaskItem> result = new ResultEntity <TaskItem>(); var taskItem = repository.Get(task.Id); if (taskItem != null) { taskItem.Name = task.Name; taskItem.Priority = task.Priority; taskItem.Description = task.Description; repository.Update(taskItem); } else { result.AddError("Task item not found."); } return(result); }
public async Task <IHttpActionResult> Patch(TaskItem task) { await _taskRepository.Update(task); return(Ok()); }