Beispiel #1
0
        public async Task <IActionResult> TaskEdit(string id)
        {
            TaskServiceModel taskServiceModel = await this._taskService.GetByIdAsync(id);

            AdminEditTaskModel baseTaskWebModel = new AdminEditTaskModel
            {
                Id             = taskServiceModel.Id,
                IssuerId       = taskServiceModel.Issuer.Id,
                TaskStatusId   = taskServiceModel.TaskStatus.Id,
                Description    = taskServiceModel.Description,
                Name           = taskServiceModel.Name,
                Budget         = taskServiceModel.Budget,
                DueDate        = taskServiceModel.DueDate,
                Location       = taskServiceModel.Location,
                TaskCategory   = taskServiceModel.TaskCategory,
                Locations      = await this._locationService.GetAllAsync(),
                TaskCategories = await this._taskService.GetAllTaskCtagories(),
                TaskStatuses   = await this._taskService.GetAllTaskStatuses()
            };

            if (taskServiceModel.Assignee != null)
            {
                baseTaskWebModel.AssigneeId = taskServiceModel.Assignee.Id;
            }

            return(View(baseTaskWebModel));
        }
Beispiel #2
0
        public async Task <IActionResult> TaskEdit(string id, AdminEditTaskModel taskModel)
        {
            try
            {
                TaskServiceModel taskServiceModel = new TaskServiceModel
                {
                    Id             = id,
                    Name           = taskModel.Name,
                    Description    = taskModel.Description,
                    Budget         = taskModel.Budget,
                    DueDate        = taskModel.DueDate,
                    LocationId     = taskModel.SelectedLocationId,
                    TaskCategoryId = taskModel.SelectedTaskCategoryId,
                    IssuerId       = taskModel.IssuerId,
                    AssigneeId     = taskModel.AssigneeId,
                    TaskStatusId   = taskModel.SelectedTaskStatusId
                };

                await this._taskService.UpdateAsync(taskServiceModel, taskServiceModel.IssuerId, false);

                return(RedirectToAction(nameof(Tasks)));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <IActionResult> SetTaskCompletion(Guid taskId, Guid userId,
                                                            [FromBody] TaskCompletionModel task)
        {
            UserServiceModel user = await _userService.GetByPrincipalAsync(User);

            if (user == null || user.Id != userId)
            {
                return(Unauthorized());
            }

            if (taskId != task.Id)
            {
                return(BadRequest());
            }

            TaskServiceModel taskServiceModel = await _taskService.GetByIdAsync(taskId);

            if (taskServiceModel == null)
            {
                return(NotFound());
            }

            await _taskService.TaskCompletion(taskId, task.IsDone);

            return(NoContent());
        }
        // GET: TaskController/Edit/5
        public async Task <IActionResult> Edit(string id)
        {
            string           userId           = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            TaskServiceModel taskServiceModel = await this._taskService.GetByIdAsync(id);

            EditTaskWebModel baseTaskWebModel = new EditTaskWebModel
            {
                Id             = taskServiceModel.Id,
                IssuerId       = taskServiceModel.Issuer.Id,
                TaskStatusId   = taskServiceModel.TaskStatus.Id,
                Description    = taskServiceModel.Description,
                Name           = taskServiceModel.Name,
                Budget         = taskServiceModel.Budget,
                DueDate        = taskServiceModel.DueDate,
                Location       = taskServiceModel.Location,
                TaskCategory   = taskServiceModel.TaskCategory,
                Locations      = await this._locationService.GetAllAsyncOfUser(userId),
                TaskCategories = await this._taskService.GetAllTaskCtagories()
            };

            if (taskServiceModel.Assignee != null)
            {
                baseTaskWebModel.AssigneeId = taskServiceModel.Assignee.Id;
            }

            return(View(baseTaskWebModel));
        }
Beispiel #5
0
        private async Task <Data.Models.Task> MapToDataModel(TaskServiceModel entity, string userId)
        {
            Data.Models.Task task = new Data.Models.Task
            {
                Id              = entity.Id,
                Name            = entity.Name,
                Description     = entity.Description,
                Budget          = entity.Budget,
                CompleationDate = entity.CompleationDate,
                DueDate         = entity.DueDate,
                PictureUrl      = entity.PictureUrl
            };

            User user = await this._userManager.FindByIdAsync(userId);

            task.Issuer = user;

            TaskCategory taskCategory = this._context.TaskCategories.Find(entity.TaskCategoryId);

            task.TaskCategory = taskCategory;

            Data.Models.TaskStatus taskStatus = this._context.TaskStatuses.Find(entity.TaskStatusId);
            task.TaskStatus = taskStatus;

            Location location = this._context.Locations.Find(entity.LocationId);

            task.Location = location;

            return(task);
        }
Beispiel #6
0
        public async Task <IActionResult> TaskCreate(CreateTaskWebModel taskModel)
        {
            try
            {
                string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

                TaskServiceModel taskServiceModel = new TaskServiceModel
                {
                    Id             = Guid.NewGuid().ToString(),
                    Name           = taskModel.Name,
                    Description    = taskModel.Description,
                    Budget         = taskModel.Budget,
                    DueDate        = taskModel.DueDate,
                    LocationId     = taskModel.SelectedLocationId,
                    TaskCategoryId = taskModel.SelectedTaskCategoryId,
                    IssuerId       = userId
                };

                await this._taskService.CreateAsync(taskServiceModel, userId);

                return(RedirectToAction(nameof(Tasks)));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <IActionResult> Edit(string id, EditTaskWebModel taskModel)
        {
            try
            {
                TaskServiceModel taskServiceModel = new TaskServiceModel
                {
                    Id             = id,
                    Name           = taskModel.Name,
                    Description    = taskModel.Description,
                    Budget         = taskModel.Budget,
                    DueDate        = taskModel.DueDate,
                    LocationId     = taskModel.SelectedLocationId,
                    TaskCategoryId = taskModel.SelectedTaskCategoryId,
                    IssuerId       = taskModel.IssuerId,
                    AssigneeId     = taskModel.AssigneeId,
                    TaskStatusId   = taskModel.TaskStatusId
                };

                await this._taskService.UpdateAsync(taskServiceModel, taskServiceModel.IssuerId);

                return(RedirectToAction(nameof(Index)));
            }
            catch (TaskNotCorrectStatusException ex)
            {
                TempData["TheErrorHappendWhen"] = "editing";
                TempData["Entity"]           = "task";
                TempData["ExceptionMessage"] = ex.Message;
                return(RedirectToAction("CRUDError", "Error"));
            }
            catch
            {
                return(View());
            }
        }
        public async Task RemoveAsync(TaskServiceModel entity)
        {
            DAL.Models.Entities.Task task = await _uow.GetRepository <DAL.Models.Entities.Task>()
                                            .GetFirstOrDefaultAsync(
                predicate: t => t.Id == entity.Id,
                disableTracking: false);

            _uow.GetRepository <DAL.Models.Entities.Task>().Remove(task);

            await _uow.SaveChangesAsync();
        }
Beispiel #9
0
        public async System.Threading.Tasks.Task PutForReview(TaskServiceModel taskServiceModel)
        {
            Data.Models.TaskStatus taskStatus = await this._context.TaskStatuses.FirstAsync(x => x.Name == TaskStatusesConstants.ForReview);

            taskServiceModel.TaskStatus = new TaskStatusServiceModel {
                Id = taskStatus.Id, Name = taskStatus.Name
            };
            taskServiceModel.TaskStatusId = taskStatus.Id;

            await this.UpdateAsync(taskServiceModel, taskServiceModel.Issuer.Id, false);
        }
Beispiel #10
0
        public async Task RemoveAsync(Guid id)
        {
            DAL.Models.Entities.Task task = await _uow.GetRepository <DAL.Models.Entities.Task>()
                                            .GetByIdAsync(id);

            TaskServiceModel taskServiceModel = _mapper
                                                .Map <DAL.Models.Entities.Task, TaskServiceModel>(task);

            await _schedulerService.UnscheduleTaskById(id);

            await RemoveAsync(taskServiceModel);
        }
Beispiel #11
0
        public async Task <TaskServiceModel> GetByIdAsync(Guid id)
        {
            DAL.Models.Entities.Task task = await _uow.GetRepository <DAL.Models.Entities.Task>()
                                            .GetFirstOrDefaultAsync(
                predicate: t => t.Id == id,
                include: query => query
                .Include(t => t.Calendar));

            TaskServiceModel taskServiceModel = _mapper.Map <DAL.Models.Entities.Task, TaskServiceModel>(task);

            return(taskServiceModel);
        }
Beispiel #12
0
        public async Task <TaskServiceModel> CreateAsync(TaskServiceModel entity, string userId)
        {
            HauseKeeping.Data.Models.Task task = await MapToDataModel(entity, userId);

            Data.Models.TaskStatus taskStatus = this._context.TaskStatuses.FirstOrDefault(x => x.Name == TaskStatusesConstants.Awaiting);
            task.TaskStatus = taskStatus;

            await this._context.AddAsync(task);

            await this._context.SaveChangesAsync();

            return(null);
        }
Beispiel #13
0
        public async Task <IActionResult> TaskDelete(string id, TaskServiceModel taskServiceModel)
        {
            try
            {
                await this._taskService.DeleteAsync(id);

                return(RedirectToAction(nameof(Tasks)));
            }
            catch
            {
                return(View());
            }
        }
Beispiel #14
0
        //TODO: isUser should be falase best practice
        public async Task <TaskServiceModel> UpdateAsync(TaskServiceModel entity, string issuerrId, bool isUser = true)
        {
            User user = await this._userManager.FindByIdAsync(issuerrId);

            Data.Models.Task task = await this._context.Tasks.Include(x => x.Location)
                                    .Include(x => x.Issuer)
                                    .Include(x => x.Assignee)
                                    .Include(x => x.TaskStatus)
                                    .Include(x => x.TaskCategory)
                                    .FirstOrDefaultAsync(x => x.Id == entity.Id);

            if (isUser)
            {
                if (task.TaskStatus.Name != TaskStatusesConstants.Awaiting)
                {
                    throw new TaskNotCorrectStatusException($"Only tasks with status {TaskStatusesConstants.Awaiting} can be editted!");
                }
            }

            task.Name            = entity.Name;
            task.Description     = entity.Description;
            task.Budget          = entity.Budget;
            task.CompleationDate = entity.CompleationDate;
            task.DueDate         = entity.DueDate;
            task.PictureUrl      = entity.PictureUrl;

            if (entity.AssigneeId != null)
            {
                User assignee = await this._userManager.FindByIdAsync(entity.AssigneeId);

                task.Assignee = assignee;
            }

            TaskCategory taskCategory = this._context.TaskCategories.Find(entity.TaskCategoryId);

            task.TaskCategory = taskCategory;

            Data.Models.TaskStatus taskStatus = this._context.TaskStatuses.Find(entity.TaskStatusId);
            task.TaskStatus = taskStatus;

            task.Issuer = user;

            Location location = this._context.Locations.Find(entity.LocationId);

            task.Location = location;

            this._context.Update(task);
            await this._context.SaveChangesAsync();

            return(null);
        }
Beispiel #15
0
        public async Task <TaskServiceModel> GetByIdAsync(string id)
        {
            Data.Models.Task task = this._context.Tasks
                                    .Include(x => x.Location)
                                    .Include(x => x.Issuer)
                                    .Include(x => x.Assignee)
                                    .Include(x => x.TaskStatus)
                                    .Include(x => x.TaskCategory)
                                    .FirstOrDefault(x => x.Id == id);

            TaskServiceModel serviceModel = this.MapToServiceModel(task);

            return(serviceModel);
        }
Beispiel #16
0
        public async Task <TaskServiceModel> AddAsync(TaskCreationServiceModel entity)
        {
            DAL.Models.Entities.Task task = _mapper.Map <TaskCreationServiceModel, DAL.Models.Entities.Task>(entity);

            await _uow.GetRepository <DAL.Models.Entities.Task>().AddAsync(task);

            await _uow.SaveChangesAsync();

            await _schedulerService.ScheduleTaskById(task.Id);

            TaskServiceModel taskServiceModel = _mapper.Map <DAL.Models.Entities.Task, TaskServiceModel>(task);

            return(taskServiceModel);
        }
        public async Task <ActionResult <TaskModel> > GetTask(Guid taskId, Guid userId)
        {
            UserServiceModel user = await _userService.GetByPrincipalAsync(User);

            if (user == null || user.Id != userId)
            {
                return(Unauthorized());
            }

            TaskServiceModel taskServiceModel = await _taskService.GetByIdAsync(taskId);

            TaskModel taskModel = _mapper.Map <TaskServiceModel, TaskModel>(taskServiceModel);

            return(Ok(taskModel));
        }
Beispiel #18
0
        public async Task <List <TaskServiceModel> > GetAllAsyncOfCareTaker(string careTakerId)
        {
            List <Data.Models.Task> tasks = this._context.Tasks
                                            .Include(x => x.Location)
                                            .Include(x => x.Issuer)
                                            .Include(x => x.Assignee)
                                            .Include(x => x.TaskStatus)
                                            .Include(x => x.TaskCategory)
                                            .Where(x => x.Assignee.Id == careTakerId).ToList();

            List <TaskServiceModel> serviceModels = new List <TaskServiceModel>();

            foreach (var task in tasks)
            {
                TaskServiceModel taskServiceModel = this.MapToServiceModel(task);
                serviceModels.Add(taskServiceModel);
            }

            return(serviceModels);
        }
        public async Task <ActionResult <TaskModel> > CreateTask(Guid userId, [FromBody] TaskCreationModel taskCreationModel)
        {
            UserServiceModel user = await _userService.GetByPrincipalAsync(User);

            if (user == null || user.Id != userId)
            {
                return(Unauthorized());
            }

            TaskCreationServiceModel taskCreationServiceModel = _mapper
                                                                .Map <TaskCreationModel, TaskCreationServiceModel>(taskCreationModel);
            TaskServiceModel taskServiceModel = await _taskService.AddAsync(taskCreationServiceModel);

            TaskModel taskModel = _mapper.Map <TaskServiceModel, TaskModel>(taskServiceModel);

            return(CreatedAtAction(nameof(GetTask), new
            {
                taskId = taskModel.Id,
                userId = user.Id
            }, taskModel));
        }
Beispiel #20
0
        public async Task <IActionResult> ForReview(string id, ForReviewModel forReviewModel)
        {
            string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            TaskServiceModel taskServiceModel = await this._taskService.GetByIdAsync(forReviewModel.TaskId);

            if (taskServiceModel.Assignee.Id == userId)
            {
                taskServiceModel.CompleationDate = DateTime.Now;
                taskServiceModel.PictureUrl      = forReviewModel.PictureURL;
                taskServiceModel.LocationId      = taskServiceModel.Location.Id;
                taskServiceModel.TaskStatusId    = taskServiceModel.TaskStatus.Id;
                taskServiceModel.TaskCategoryId  = taskServiceModel.TaskCategory.Id;

                await this._taskService.PutForReview(taskServiceModel);

                return(RedirectToAction(nameof(Index)));
            }

            TempData["ExceptionMessage"] = "You can not mark Tasks that are not assigned to you as \"ForReview\"";
            return(RedirectToAction("InvalidTaskStatusChange", "Error"));
        }
Beispiel #21
0
        private TaskServiceModel MapToServiceModel(Data.Models.Task entity)
        {
            TaskServiceModel task = new TaskServiceModel
            {
                Id              = entity.Id,
                Name            = entity.Name,
                Description     = entity.Description,
                Budget          = entity.Budget,
                CompleationDate = entity.CompleationDate,
                DueDate         = entity.DueDate,
                Issuer          = new UserServiceModel {
                    Id = entity.Issuer.Id, FirstName = entity.Issuer.FirstName, LastName = entity.Issuer.LastName, UserName = entity.Issuer.UserName
                },
                Location = new LocationServiceModel {
                    Id = entity.Location.Id, Adress = entity.Location.Adress, Name = entity.Location.Name
                },
                TaskCategory = new TaskCategoryServiceModel {
                    Id = entity.TaskCategory.Id, Name = entity.TaskCategory.Name
                },
                TaskStatus = new TaskStatusServiceModel {
                    Id = entity.TaskStatus.Id, Name = entity.TaskStatus.Name
                },
                PictureUrl = entity.PictureUrl
            };

            if (entity.Assignee != null)
            {
                UserServiceModel assignee = new UserServiceModel {
                    Id = entity.Assignee.Id, FirstName = entity.Assignee.FirstName, LastName = entity.Assignee.LastName, UserName = entity.Assignee.UserName
                };

                task.Assignee = assignee;
            }

            return(task);
        }
Beispiel #22
0
        public async Task <IActionResult> TaskDetails(string id)
        {
            TaskServiceModel taskServiceModel = await this._taskService.GetByIdAsync(id);

            return(View(taskServiceModel));
        }