Ejemplo n.º 1
0
        /// <summary>
        /// Executes the logic of the <see cref="ViewTasksUseCase"/>. Retrieves TaskItem data and
        /// stores it in the <see cref="ViewTasksUseCase"/>'s Output property.
        /// </summary>
        public ViewTasksOutput Execute(ViewTasksInput input)
        {
            ITaskItemRepository taskRepo = taskItemRepositoryFactory.New();

            ViewTasksOutput output = new ViewTasksOutput {
                Success = true
            };

            /*
             * go through all taskItems in database then add them to the Output property as
             * TaskItemDTO's.
             */
            foreach (TaskItem domainTask in taskManager.GetAll())
            {
                //retrieve dataLayer task which carries notification frequency description
                Maybe <TaskItemDAL> maybeTask = taskRepo.GetById(domainTask.ID);

                if (maybeTask.HasValue)
                {
                    TaskItemDAL taskDAL             = maybeTask.Value;
                    TimeSpan    customFrequencyTime = new TimeSpan();

                    //if the current taskItem has a custom frequency type, then retrieve its Time value
                    if (taskDAL.customNotificationFrequency.HasValue)
                    {
                        CustomNotificationFrequencyDAL frequencyDAL = taskDAL.customNotificationFrequency.Value;
                        customFrequencyTime = frequencyDAL.time;
                    }

                    DTO.TaskItemDTO taskDTO =
                        new DTO.TaskItemDTO()
                    {
                        Id          = domainTask.ID,
                        Title       = domainTask.Title,
                        Description = domainTask.Description,
                        R           = domainTask.Colour.R,
                        G           = domainTask.Colour.G,
                        B           = domainTask.Colour.B,
                        StartTime   = domainTask.StartTime,
                        //TODO: prefer to do a better conversion that just a cast to an enum
                        NotificationFrequencyType =
                            (NotificationFrequencyType)taskDAL.notificationFrequencyType,
                        CustomNotificationFrequency = customFrequencyTime
                    };

                    output.TaskItems.Add(taskDTO);
                }
            }

            return(output);
        }
        /// <summary>
        /// Executes the ViewNotificationsUseCase. Sets the Output property of the UseCase object
        /// once complete
        /// </summary>
        public ViewNotificationsOutput Execute(ViewNotificationsInput input)
        {
            //no input for use case
            ITaskItemRepository taskRepo = taskItemRepositoryFactory.New();

            ViewNotificationsOutput output = new ViewNotificationsOutput {
                Success = true
            };

            /*
             * Get all notifications that are present in the application, convert them to DTO's, then
             * add them to a collection to return
             */
            INotificationRepository notificationRepository = notificationRepositoryFactory.New();

            foreach (NotificationDAL notification in notificationRepository.GetAll())
            {
                Maybe <TaskItemDAL> maybeTask = taskRepo.GetById(notification.taskId);

                if (maybeTask.HasValue)
                {
                    TaskItemDAL     taskDAL = maybeTask.Value;
                    NotificationDTO dto     = new NotificationDTO()
                    {
                        TaskId = taskDAL.id,
                        Title  = taskDAL.title,
                        Time   = notification.time,
                        R      = taskDAL.r,
                        G      = taskDAL.g,
                        B      = taskDAL.b
                    };

                    output.Notifications.Add(dto);
                }
            }

            return(output);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Deletes a Task Item from the application
        /// </summary>
        /// <param name="input">
        /// Holds the input necessary for deleting a TaskItem
        /// </param>
        /// <returns>
        /// The result of deleting the TaskItem
        /// </returns>
        public DeleteTaskUseCaseOutput Execute(DeleteTaskUseCaseInput input)
        {
            Guid idToDelete = input.Id;

            ITaskItemRepository taskRepo = taskItemRepositoryFactory.New();

            //retrieve task item to delete
            Maybe <TaskItemDAL> maybeTask = taskRepo.GetById(idToDelete);

            if (maybeTask.HasValue)
            {
                TaskItemDAL taskToDelete = maybeTask.Value;

                //delete task item from repository
                if (taskRepo.Delete(idToDelete) == false)
                {
                    //unable to delete task
                    return(new DeleteTaskUseCaseOutput()
                    {
                        Error = "Unable to to delete TaskItem", Success = false
                    });
                }

                //delete task item from domain
                if (taskItemManager.Remove(idToDelete) == false)
                {
                    //failed to remove TaskItem from domain
                    //TODO : handle this appropriately
                    return(new DeleteTaskUseCaseOutput()
                    {
                        Error = "Unable to to delete TaskItem", Success = false
                    });
                }

                INotificationRepository notificationRepo = notificationRepositoryFactory.New();

                //iterate through notifications in repository and delete those generated by the deleted task
                foreach (NotificationDAL notificationDAL in notificationRepo.GetAll())
                {
                    if (notificationDAL.taskId == idToDelete)
                    {
                        if (notificationRepo.Delete(notificationDAL) == false)
                        {
                            //unable to delete notification
                            //TODO : handle this appropriately
                        }
                    }
                }

                //delete task notifications in domain
                if (notificationManager.Remove(idToDelete) == false)
                {
                    //failed to remove task notifications from domain
                    //TODO : handle this appropriately
                }

                notificationRepo.Save();
                taskRepo.Save();
            }
            else
            {
                return(new DeleteTaskUseCaseOutput()
                {
                    Error = "Unable to find TaskItem to delete", Success = false
                });
            }

            return(new DeleteTaskUseCaseOutput()
            {
                Success = true
            });
        }