示例#1
0
        public void InitializeDomainFromDatabase(
            ITaskItemRepositoryFactory taskItemRepositoryFactory,
            INotificationManager notificationManager,
            ITaskManager taskManager,
            IClock clock)
        {
            /*
             * hook up to notfication added event now, so to retrieve new notifications generated by
             * the TaskItems being created below
             */
            notificationManager.NotificationAdded += OnNotificationAdded;

            /*
             * read in task items from database. Create domain taskItems from
             * data and add items to taskManager
             */
            ITaskItemRepository taskItemRepository = taskItemRepositoryFactory.New();

            foreach (TaskItemDAL task in taskItemRepository.GetAll())
            {
                INotificationFrequency notificationFrequency = null;

                if (task.customNotificationFrequency.HasValue)
                {
                    CustomNotificationFrequencyDAL frequencyDAL = task.customNotificationFrequency.Value;

                    notificationFrequency = NotificationFrequencyFactory.New(
                        //TODO: do something safer than just a cast
                        (NotificationFrequencyType)task.notificationFrequencyType,
                        frequencyDAL.time
                        );
                }
                else
                {
                    notificationFrequency = NotificationFrequencyFactory.New(
                        //TODO: do something safer than just a cast
                        (NotificationFrequencyType)task.notificationFrequencyType
                        );
                }

                taskManager.Add(
                    new TaskItem(
                        task.title,
                        task.description,
                        new Colour(task.r, task.g, task.b),
                        task.startTime,
                        notificationManager,
                        notificationFrequency,
                        clock,
                        task.lastNotificationTime,
                        task.id
                        )
                    );
            }
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Adds a new TaskItemDAL to the repository for it to manage
        /// </summary>
        /// <param name="taskItemDAL">
        /// To be added to the repository
        /// </param>
        /// <returns>
        /// True if the TaskItemDAL was successfuly added to the repository, otherwise false
        /// </returns>
        public bool Add(TaskItemDAL taskItemDAL)
        {
            //create new row
            DataRow newTaskRow = table.NewRow();

            if (taskItemDAL.customNotificationFrequency.HasValue)
            {
                CustomNotificationFrequencyDAL notificationFrequency = taskItemDAL.customNotificationFrequency.Value;

                //add custom notification frequency to notification frequency
                //repository
                if (notificationFrequencyRepository.Add(notificationFrequency) == false)
                {
                    newTaskRow.Delete();
                    return(false);
                }
            }

            try {
                //set all fields of row of new taskItem row
                newTaskRow.SetField("Id", taskItemDAL.id.ToString());
                newTaskRow.SetField("StartTime", taskItemDAL.startTime.ToString());
                newTaskRow.SetField("Title", taskItemDAL.title);
                newTaskRow.SetField("Description", taskItemDAL.description);
                newTaskRow.SetField("LastNotificationTime", taskItemDAL.lastNotificationTime.ToString());
                newTaskRow.SetField("FrequencyType", taskItemDAL.notificationFrequencyType);
                newTaskRow.SetField("R", taskItemDAL.r);
                newTaskRow.SetField("G", taskItemDAL.g);
                newTaskRow.SetField("B", taskItemDAL.b);
            }
            catch {
                //delete the new row since data could not be added
                newTaskRow.Delete();

                if (taskItemDAL.customNotificationFrequency.HasValue)
                {
                    CustomNotificationFrequencyDAL notificationFrequency = taskItemDAL.customNotificationFrequency.Value;

                    //remove previously added Custom notification frequency
                    notificationFrequencyRepository.Delete(notificationFrequency);
                }

                return(false);
            }

            table.Rows.Add(newTaskRow);

            return(true);
        }
        public bool Add(CustomNotificationFrequencyDAL notificationFrequency)
        {
            //get a new DataRow with the NotificationFrequency table schema
            DataRow newRow = table.NewRow();

            try {
                //set the revelant fields of the new NotificationFrequency row
                newRow.SetField("TaskId", notificationFrequency.taskId.ToString());
                newRow.SetField("Time", notificationFrequency.time.ToString());
            }
            catch {
                //delete the new row
                newRow.Delete();
                return(false);
            }

            //add the new row to the table
            table.Rows.Add(newRow);

            return(true);
        }
        public bool Update(CustomNotificationFrequencyDAL notificationFrequency)
        {
            var findByIdQuery = GetQueryForId(notificationFrequency.taskId);

            if (findByIdQuery.Count() != 1)
            {
                return(false);
            }

            DataRow rowToUpdate = findByIdQuery.First();

            try {
                rowToUpdate.BeginEdit();
                rowToUpdate.SetField("Time", notificationFrequency.time.ToString());
                rowToUpdate.EndEdit();
            }
            catch {
                rowToUpdate.CancelEdit();
                return(false);
            }

            return(true);
        }
 public bool Delete(CustomNotificationFrequencyDAL notificationFrequency)
 {
     return(Delete(notificationFrequency.taskId));
 }