public List <TaskTypeView> GetCategoryList(int Id)
        {
            List <TaskTypeView> uvModel = new List <TaskTypeView>();


            var perentList = TaskTypeContract.TaskTypes.Where(t => t.TaskParentTypeID == Id).ToList();

            if (perentList.Count > 0)
            {
                foreach (var item in perentList)
                {
                    TaskTypeView userViewModel = new TaskTypeView
                    {
                        TaskTypeID       = item.Id,
                        TaskTypeName     = item.TaskTypeName,
                        ChildrenTaskType = new List <TaskTypeView>()
                    };
                    List <TaskTypeView> tempList = GetCategoryList(item.Id);
                    if (tempList.Count > 0)
                    {
                        userViewModel.ChildrenTaskType = tempList;
                    }
                    uvModel.Add(userViewModel);
                }
            }
            return(uvModel);
        }
Esempio n. 2
0
        public TaskTypeView Create(TaskTypeView taskTypeView)
        {
            IsTaskTypeNameHasChars(taskTypeView.Name);
            IsNameUnique(taskTypeView);

            if (taskTypeView.ProjectId != null && !ApplicationUserCurrent.IsAdmin)
            {
                if (taskTypeView.ProjectId != null)
                {
                    var project = Uow.ProjectRepository.LinkedCacheGetById((int)taskTypeView.ProjectId);
                    if (project == null)
                    {
                        throw new CoralTimeEntityNotFoundException($"Project with id {taskTypeView.ProjectId} not found");
                    }

                    var managerRoleId = Uow.ProjectRoleRepository.GetManagerRoleId();

                    var memberProjectRole = Uow.MemberProjectRoleRepository.LinkedCacheGetList().FirstOrDefault(r => r.MemberId == MemberCurrent.Id && r.ProjectId == project.Id && r.RoleId == managerRoleId);
                    if (memberProjectRole == null)
                    {
                        throw new CoralTimeForbiddenException("Forbidden");
                    }
                }
            }

            var taskType = taskTypeView.GetModel(Mapper, true);

            Uow.TaskTypeRepository.Insert(taskType);
            Uow.Save();
            Uow.TaskTypeRepository.LinkedCacheClear();

            return(Uow.TaskTypeRepository.LinkedCacheGetById(taskType.Id).GetView(Mapper));
        }
Esempio n. 3
0
        public TaskTypeView Update(TaskTypeView taskTypeView)
        {
            IsTaskTypeNameHasChars(taskTypeView.Name);
            IsNameUnique(taskTypeView);

            var taskType = Uow.TaskTypeRepository.GetQueryWithIncludesById(taskTypeView.Id);

            if (taskType == null)
            {
                throw new CoralTimeEntityNotFoundException($"TaskType with id {taskTypeView.Id} not found");
            }

            #region We shouldn't change projectId for Tasks

            if (taskType.ProjectId != taskTypeView.ProjectId)
            {
                taskTypeView.ProjectId = taskType.ProjectId;
            }

            #endregion We shouldn't change projectId for Tasks

            if (taskTypeView.ProjectId != null && !ApplicationUserCurrent.IsAdmin)
            {
                var project = Uow.ProjectRepository.LinkedCacheGetById((int)taskTypeView.ProjectId);
                if (project == null)
                {
                    throw new CoralTimeEntityNotFoundException($"Project with id {taskTypeView.ProjectId} not found");
                }

                var managerRoleId = Uow.ProjectRoleRepository.GetManagerRoleId();

                var memberProjectRole = Uow.MemberProjectRoleRepository.LinkedCacheGetList()
                                        .FirstOrDefault(r => r.MemberId == MemberCurrent.Id && r.ProjectId == project.Id && r.RoleId == managerRoleId);

                if (memberProjectRole == null)
                {
                    throw new CoralTimeForbiddenException("Forbidden");
                }
            }

            if (!taskTypeView.IsActive)
            {
                var timeEntries = Uow.TimeEntryRepository.GetQueryWithIncludes()
                                  .Where(t => t.TaskTypesId == taskType.Id && t.Date.Date == DateTime.Now.Date)
                                  .ToList();

                timeEntries.ForEach(t => t.StopTimer());
            }

            UpdateValuesForTaskType(taskType, taskTypeView);

            Uow.TaskTypeRepository.Update(taskType);
            Uow.Save();
            Uow.TaskTypeRepository.LinkedCacheClear();

            return(Uow.TaskTypeRepository.LinkedCacheGetById(taskType.Id).GetView(Mapper));
        }
Esempio n. 4
0
        private void IsNameUnique(TaskTypeView taskTypeView)
        {
            var isNameUnique = Uow.TaskTypeRepository.LinkedCacheGetList()
                               .FirstOrDefault(task => task.IsActive && task.Name == taskTypeView.Name &&
                                               (task.ProjectId == taskTypeView.ProjectId || task.ProjectId == null)) == null;

            if (!isNameUnique)
            {
                throw new CoralTimeAlreadyExistsException($"Task with name {taskTypeView.Name} already exist");
            }
        }
Esempio n. 5
0
        public static TaskType GetModel(this TaskTypeView member, IMapper _mapper, bool?isActive = null)
        {
            var memberModel = _mapper.Map <TaskTypeView, TaskType>(member);

            if (isActive != null)
            {
                memberModel.IsActive = (bool)isActive;
            }

            return(memberModel);
        }
Esempio n. 6
0
        private void UpdateValuesForTaskType(TaskType taskType, TaskTypeView taskTypeView)
        {
            #region #1. Update related entites.

            taskType.ProjectId = taskTypeView.ProjectId;

            #endregion

            #region #2. Update other values.

            taskType.Name        = taskTypeView.Name;
            taskType.IsActive    = taskTypeView.IsActive;
            taskType.Color       = taskTypeView.Color;
            taskType.Description = taskTypeView.Description;

            #endregion
        }
Esempio n. 7
0
        public IActionResult Patch([FromODataUri] int id, [FromBody] TaskTypeView taskTypeView)
        {
            if (!ModelState.IsValid)
            {
                return(SendInvalidModelResponse());
            }

            taskTypeView.Id = id;

            try
            {
                var taskTypeViewResult = _service.Update(taskTypeView);
                return(new ObjectResult(taskTypeViewResult));
            }
            catch (Exception e)
            {
                return(SendErrorODataResponse(e));
            }
        }
Esempio n. 8
0
        public IActionResult Create([FromBody] TaskTypeView taskTypeView)
        {
            if (!ModelState.IsValid)
            {
                return(SendInvalidModelResponse());
            }

            try
            {
                var taskTypeViewResult = _service.Create(taskTypeView);
                var locationUri        = $"{Request.Host}/{BaseODataRoute}/Tasks({taskTypeViewResult.Id})";

                return(Created(locationUri, taskTypeViewResult));
            }
            catch (Exception e)
            {
                return(SendErrorODataResponse(e));
            }
        }