Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> Patch(TaskItem task)
        {
            await _taskRepository.Update(task);

            return(Ok());
        }