Beispiel #1
0
        public ActionResult UpdatetaskForproject(Guid projectId, Guid taskId,
                                                 [FromBody] TaskForUpdatingDto task)
        {
            if (!_ProjectTasksRepository.ProjectExisit(projectId))
            {
                return(NotFound());
            }

            var taskFromRepo = _ProjectTasksRepository.GetTask(projectId, taskId);

            if (taskFromRepo == null)
            {
                var taskToAdd = _mapper.Map <Entities.ProjectTask>(task);
                taskToAdd.Id = taskId;
                _ProjectTasksRepository.AddTask(projectId, taskToAdd);
                _ProjectTasksRepository.Save();

                var taskToReturn = _mapper.Map <TaskDto>(taskToAdd);

                return(CreatedAtRoute("GettaskForproject", new { projectId = projectId, taskId = taskToReturn.Id }, taskToReturn));
            }

            _mapper.Map(task, taskFromRepo);
            _ProjectTasksRepository.UpdateTask(taskFromRepo);
            _ProjectTasksRepository.Save();

            return(NoContent());
        }
Beispiel #2
0
        public ActionResult PartiallyUpdatetaskForproject(Guid projectId, Guid taskId,
                                                          [FromBody] JsonPatchDocument <TaskForUpdatingDto> patchDocument)
        {
            if (!_ProjectTasksRepository.ProjectExisit(projectId))
            {
                return(NotFound());
            }

            var taskFromRepo = _ProjectTasksRepository.GetTask(projectId, taskId);

            if (taskFromRepo == null)
            {
                var taskDto = new TaskForUpdatingDto();
                patchDocument.ApplyTo(taskDto);
                var taskToAdd = _mapper.Map <Entities.ProjectTask>(taskDto);
                taskToAdd.Id = taskId;

                _ProjectTasksRepository.AddTask(projectId, taskToAdd);
                _ProjectTasksRepository.Save();

                var taskToReturn = _mapper.Map <TaskDto>(taskToAdd);

                return(CreatedAtRoute("GettaskForproject", new { projectId = projectId, taskId = taskToReturn.Id }, taskToReturn));
            }

            var taskToPatch = _mapper.Map <TaskForUpdatingDto>(taskFromRepo);

            patchDocument.ApplyTo(taskToPatch);

            if (!TryValidateModel(taskToPatch))
            {
                return(ValidationProblem(ModelState));
            }

            _mapper.Map(taskToPatch, taskFromRepo);
            _ProjectTasksRepository.UpdateTask(taskFromRepo);
            _ProjectTasksRepository.Save();

            return(NoContent());
        }