Esempio n. 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
                        )
                    );
            }
        }
Esempio n. 2
0
        public async Task <IHttpActionResult> Get([FromUri] string categoryName = null)
        {
            var categories = await _taskCategoryRepository.GetAll();

            var categoryList = categories.ToList();
            var tasks        = await _taskRepository.GetAll(categoryName);

            var taskList = tasks.ToList();
            var result   = new TaskListResponse
            {
                Data = taskList,
            };

            result.Lists.Add(categories);
            return(Ok(result));
        }
Esempio n. 3
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. 4
0
        public DailyTooDueList CreateDailyTooDueList()
        {
            if (_dailyTooDueListRepository.TryGetCurrentTooDueList(out _))
            {
                throw new DailyTooDueListAlreadyActiveException();
            }

            return(new DailyTooDueList
            {
                Date = DateTimeOffset.Now.Date,

                Tasks =

                    // very naive task selection algorithm
                    _taskItemRepository
                    .GetAll()
                    // ignore any 'snoozed' tasks
                    .Where(x => !x.IsSnoozed())
                    .OrderBy(x => x.Priority)
                    .Take(3)
                    .ToList()
            });
        }
Esempio n. 5
0
        public async Task <List <string> > GetProjectCategoriesByProjectId(Guid projectId, Guid?taskId = null)
        {
            using (var scope = _dbContextScopeFactory.CreateReadOnly())
            {
                IReadOnlyList <ProjectCategory> projectCategories = await _projectCategoryRepository.GetAsync(e => e.ProjectId == projectId && e.IsActive == true);

                List <string> categories = projectCategories.Select(group => group.Name).ToList();
                if (taskId.HasValue)
                {
                    var    taskItem         = _taskItemRepository.GetAll().Where(e => e.Id == taskId && e.IsDeleted == false).FirstOrDefault();
                    string taskItemCategory = string.Empty;
                    if (taskItem != null)
                    {
                        taskItemCategory = taskItem.TaskItemCategory;
                    }
                    if (!string.IsNullOrEmpty(taskItemCategory))
                    {
                        categories.AddRange(taskItemCategory.Split(';').ToList());
                    }
                }
                categories = categories.Distinct().ToList();
                return(categories);
            }
        }
 public IEnumerable <TaskItem> GetAll()
 {
     return(_repository.GetAll());//_context.TaskItems.ToList();
 }
Esempio n. 7
0
 public List <TooDueTaskItem> GetAll()
 {
     return(_taskItemRepository.GetAll());
 }
Esempio n. 8
0
 public async Task <IEnumerable <IEnumerable <TaskItem> > > GetAll()
 {
     return(await _repository.GetAll());
 }
Esempio n. 9
0
        public async Task <SendMessageResponse> UpdateProcessTaskAssign(TaskItemAssignDto dto)
        {
            SendMessageResponse sendMessage = new SendMessageResponse();

            try
            {
                using (var scope = _dbContextScopeFactory.Create())
                {
                    List <AttachmentDto> attachmentDtos = dto.Attachments.ToList();
                    dto.Attachments = null;
                    TaskItemAssign entity = _objectRepository.GetAll().Where(e => e.Id == dto.Id).FirstOrDefault();
                    if (entity != null)
                    {
                        TaskItem taskEntity = _taskItemRepository.GetAll().Where(e => e.Id == entity.TaskItemId).FirstOrDefault();
                        if (!dto.IsFullControl && taskEntity.AssignBy != dto.ModifiedBy && entity.AssignTo != dto.ModifiedBy)
                        {
                            sendMessage = SendMessageResponse.CreateFailedResponse("AccessDenied");
                            return(sendMessage);
                        }
                        if (DateTime.TryParseExact(dto.ExtendDateText, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime extendDate))
                        {
                            dto.ExtendDate = extendDate;
                        }
                        else
                        {
                            dto.ExtendDate = null;
                        }
                        entity.AppraiseProcess = dto.AppraiseProcess;
                        entity.AppraiseStatus  = dto.AppraiseStatus;
                        entity.FinishedDate    = dto.FinishedDate;
                        entity.FromDate        = dto.FromDate;
                        entity.IsDeleted       = dto.IsDeleted;
                        entity.ModifiedDate    = dto.ModifiedDate;
                        entity.Problem         = dto.Problem;
                        entity.Solution        = dto.Solution;
                        entity.ToDate          = dto.ToDate;
                        if (entity.AssignTo == dto.ModifiedBy && !dto.IsAssignBy)
                        {
                            switch (dto.ActionText)
                            {
                            case "Process":
                                dto.TaskItemStatusId = TaskItemStatusId.InProcess;
                                dto.ActionId         = ActionId.Process;
                                entity.PercentFinish = dto.PercentFinish;
                                break;

                            case "Report":
                                if (taskEntity.IsReport == false)
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.Finished;
                                    dto.ActionId         = ActionId.Finish;
                                }
                                else
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.Report;
                                    dto.ActionId         = ActionId.Report;
                                }
                                entity.PercentFinish = dto.PercentFinish;
                                break;

                            case "Extend":
                                entity.IsExtend      = true;
                                entity.ExtendDate    = dto.ExtendDate;
                                dto.ActionId         = ActionId.Extend;
                                entity.PercentFinish = dto.PercentFinish;

                                break;

                            case "ReturnReport":
                                dto.TaskItemStatusId = TaskItemStatusId.ReportReturn;
                                dto.ActionId         = ActionId.Return;
                                break;

                            default:
                                break;
                            }
                            if (entity.TaskType != TaskType.Primary)
                            {
                                dto.TaskItemStatusId = TaskItemStatusId.Read;
                            }
                            entity.LastResult = dto.Description;
                            //entity.IsExtend = dto.IsExtend;
                            //entity.ExtendDate = dto.ExtendDate;
                        }
                        if (taskEntity.AssignBy == dto.ModifiedBy && dto.IsAssignBy)
                        {
                            switch (dto.ActionText)
                            {
                            case "Appraise":
                                dto.ActionId = ActionId.Appraise;

                                if (entity.TaskItemStatusId == TaskItemStatusId.Extend)
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.InProcess;
                                }
                                else if (entity.TaskItemStatusId == TaskItemStatusId.Report)
                                {
                                    dto.TaskItemStatusId         = TaskItemStatusId.Finished;
                                    entity.AppraisePercentFinish = dto.AppraisePercentFinish;
                                    entity.PercentFinish         = dto.AppraisePercentFinish;
                                    dto.ActionId = ActionId.Finish;
                                }
                                else if (entity.TaskItemStatusId == TaskItemStatusId.ReportReturn)
                                {
                                    dto.TaskItemStatusId = TaskItemStatusId.Cancel;
                                }
                                break;

                            case "Return":
                                dto.TaskItemStatusId         = TaskItemStatusId.InProcess;
                                entity.AppraisePercentFinish = dto.AppraisePercentFinish;
                                entity.PercentFinish         = dto.AppraisePercentFinish;
                                dto.ActionId = ActionId.Return;
                                break;

                            case "AppraiseExtend":
                                entity.ExtendDate = dto.ExtendDate;
                                taskEntity.ToDate = dto.ExtendDate;
                                entity.IsExtend   = false;
                                dto.ActionId      = ActionId.Appraise;
                                break;

                            case "ReturnExtend":
                                entity.ExtendDate = null;
                                entity.IsExtend   = false;
                                dto.ActionId      = ActionId.Return;
                                break;

                            default:
                                break;
                            }
                            entity.AppraiseResult = dto.Description;
                        }

                        entity.TaskItemStatusId = dto.TaskItemStatusId;
                        TaskItemProcessHistory taskAssignHistory = new TaskItemProcessHistory
                        {
                            Id               = Guid.NewGuid(),
                            ProjectId        = entity.ProjectId,
                            ActionId         = dto.ActionId,
                            CreatedBy        = dto.ModifiedBy,
                            PercentFinish    = entity.PercentFinish,
                            CreatedDate      = dto.ModifiedDate,
                            TaskItemId       = entity.TaskItemId,
                            TaskItemAssignId = entity.Id,
                            TaskItemStatusId = entity.TaskItemStatusId,
                            ProcessResult    = dto.Description
                        };
                        if (entity.TaskType == TaskType.Primary || dto.IsAssignBy)
                        {
                            //TaskItemProcessHistory taskHistory = new TaskItemProcessHistory
                            //{
                            //    Id = Guid.NewGuid(),
                            //    ProjectId = entity.ProjectId,
                            //    ActionId = dto.ActionId,
                            //    CreatedBy = dto.ModifiedBy,
                            //    PercentFinish = dto.PercentFinish,
                            //    CreatedDate = dto.ModifiedDate,
                            //    TaskItemId = entity.TaskItemId,
                            //    TaskItemStatusId = entity.TaskItemStatusId,
                            //    ProcessResult = dto.Description
                            //};
                            taskEntity.TaskItemStatusId = entity.TaskItemStatusId;
                            taskEntity.PercentFinish    = entity.PercentFinish;
                            //_taskItemProcessHistoryRepository.Add(taskHistory);
                        }

                        _objectRepository.Modify(entity);
                        //_taskItemRepository.Modify(taskEntity);
                        _taskItemProcessHistoryRepository.Add(taskAssignHistory);
                        foreach (AttachmentDto attachDto in attachmentDtos)
                        {
                            attachDto.ProjectId = entity.ProjectId;
                            attachDto.ItemId    = entity.Id;
                            Attachment attach = _mapper.Map <Attachment>(attachDto);
                            _attachmentRepository.Add(attach);
                        }
                        if (dto.AttachDelIds != null)
                        {
                            if (dto.AttachDelIds.Any())
                            {
                                List <Attachment> attachDels = _attachmentRepository.GetAll().Where(e => dto.AttachDelIds.Contains(e.Id)).ToList();
                                _attachmentRepository.DeleteRange(attachDels);
                            }
                        }
                        await scope.SaveChangesAsync();

                        var param = new List <SqlParameter>();
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.UniqueIdentifier,
                            ParameterName = "@ProjectId",
                            IsNullable    = false,
                            Value         = dto.ProjectId
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.UniqueIdentifier,
                            ParameterName = "@TaskId",
                            IsNullable    = false,
                            Value         = taskEntity.Id
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.DateTime,
                            ParameterName = "@FromDate",
                            IsNullable    = false,
                            Value         = taskEntity.FromDate
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.DateTime,
                            ParameterName = "@ToDate",
                            IsNullable    = false,
                            Value         = taskEntity.ToDate
                        });
                        param.Add(new SqlParameter()
                        {
                            SqlDbType     = SqlDbType.Bit,
                            ParameterName = "@IsUpdateStatus",
                            IsNullable    = true,
                            Value         = 1
                        });
                        await _objectRepository.SqlQueryAsync(typeof(ProjectDto), "[dbo].[SP_UPDATE_TASK_RANGE_DATE] @ProjectId, @TaskId, @FromDate, @ToDate, @IsUpdateStatus", param.ToArray());
                    }
                }
                sendMessage = SendMessageResponse.CreateSuccessResponse(string.Empty);
                return(sendMessage);
            }
            catch (Exception ex)
            {
                _loggerServices.WriteError(ex.ToString());
                sendMessage = SendMessageResponse.CreateFailedResponse(string.Empty);
                return(sendMessage);
            }
        }