Beispiel #1
0
        public async Task <bool> UpdateTaskByIdAsync(int id, TaskUpdateDto taskUpdateDto)
        {
            var task = _mapper.Map <Models.Task>(taskUpdateDto);


            return(await _repo.UpdateTaskByIdAsync(id, task));
        }
        public ActionResult PatchTask(long id, JsonPatchDocument <TaskUpdateDto> jsonPatchDocument)
        {
            _logger.LogInformation("Consultando a tarefa de Id: {id}", id);
            Models.Task task = _tasksRepo.GetTaskById(id);

            if (task == null)
            {
                _logger.LogWarning("A tarefa de Id: {id} não existe", id);
                return(NotFound());
            }

            _logger.LogInformation("Aplicando a alteração na classe de DTO");
            TaskUpdateDto taskUpdateDto = _mapper.Map <TaskUpdateDto>(task);

            jsonPatchDocument.ApplyTo(taskUpdateDto, ModelState);

            _logger.LogInformation("Validando a alteração feita na classe de DTO");
            if (!TryValidateModel(taskUpdateDto))
            {
                return(ValidationProblem(ModelState));
            }

            _logger.LogInformation("Alterando a tarefa de Id: {id}", id);
            _mapper.Map(taskUpdateDto, task);
            _tasksRepo.SaveChanges();

            return(NoContent());
        }
Beispiel #3
0
        public TaskDto Change(TaskUpdateDto task)
        {
            var entity = mapper.Map <TaskBase>(task);

            taskManager.Change(entity);
            return(mapper.Map <TaskDto>(entity));
        }
        public IActionResult UpdateTask(int id, [FromBody] JsonPatchDocument <TaskUpdateDto> patchDoc)
        {
            var taskData = TasksDataStore.Current.Tasks.FirstOrDefault(x => x.Id.Equals(id));

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

            var taskToPatch = new TaskUpdateDto();

            patchDoc.ApplyTo(taskToPatch);

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            foreach (var property in taskToPatch.GetType().GetProperties())
            {
                if (property.GetValue(taskToPatch) != null)
                {
                    taskData.GetType().GetProperty(property.Name).SetValue(taskData, property.GetValue(taskToPatch));
                }
            }

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

            return(NoContent());
        }
        public async Task <IActionResult> UpdateTasksIndex(TaskUpdateDto taskUpdateDto)
        {
            var userId = await _userManager.FindByNameAsync(User.Identity.Name);

            taskUpdateDto.AppUserId = userId.Id;
            await _tasksManager.UpdateTasksPost(taskUpdateDto);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> UpdateTaskAsync(int id, [FromBody] TaskUpdateDto taskUpdateDto)
        {
            var result = await _service.UpdateTaskByIdAsync(id, taskUpdateDto);

            if (!result)
            {
                return(BadRequest("Update failed!"));
            }

            return(NoContent());
        }
Beispiel #7
0
        public void PutTask_ExistingIdPassed_ReturnsNoContent()
        {
            _mockTasksRepo.Setup(r => r.GetTaskById(It.IsAny <long>())).Returns(new Task());

            TaskUpdateDto taskUpdateDto = new TaskUpdateDto()
            {
                Title = "Fazer teste técnico"
            };

            var noContentResult = _controller.PutTask(5, taskUpdateDto);

            Assert.IsType <NoContentResult>(noContentResult);
        }
Beispiel #8
0
        public void PutTask_UnknownIdPassed_ReturnsNotFound()
        {
            _mockTasksRepo.Setup(r => r.GetTaskById(It.IsAny <long>())).Returns((Task)null);

            TaskUpdateDto taskUpdateDto = new TaskUpdateDto()
            {
                Title = "Fazer teste técnico"
            };

            var notFoundResult = _controller.PutTask(5, taskUpdateDto);

            Assert.IsType <NotFoundResult>(notFoundResult);
        }
Beispiel #9
0
        public ActionResult UpdateTask(int id, TaskUpdateDto taskUpdate)
        {
            var task = _repository.GetTaskById(id);

            if (task == null)
            {
                return(NotFound());
            }
            _mapper.Map(taskUpdate, task);
            _repository.UpdateTask(task);
            _repository.SaveChanges();

            return(NoContent());
        }
        public IActionResult UpdateTask(int id, [FromBody] TaskUpdateDto task)
        {
            var taskToUpdate = TasksDataStore.Current.Tasks.FirstOrDefault(x => x.Id.Equals(id));

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

            foreach (var property in task.GetType().GetProperties())
            {
                taskToUpdate.GetType().GetProperty(property.Name).SetValue(taskToUpdate, property.GetValue(task));
            }

            return(NoContent());
        }
Beispiel #11
0
 public IActionResult UpdateTask(TaskUpdateDto model)
 {
     if (ModelState.IsValid)
     {
         _taskService.Update(new Task()
         {
             Id          = model.Id,
             Description = model.Description,
             Name        = model.Name,
             PriorityId  = model.PriorityId
         });
         return(RedirectToAction("Index"));
     }
     ViewBag.PriorityList = new SelectList(_priorityService.GetAll(), "Id", "Definition", model.PriorityId);
     return(View(model));
 }
        public ActionResult PutTask(long id, TaskUpdateDto taskUpdateDto)
        {
            _logger.LogInformation("Consultando a tarefa de Id: {id}", id);
            Models.Task task = _tasksRepo.GetTaskById(id);

            if (task == null)
            {
                _logger.LogWarning("A tarefa de Id: {id} não existe", id);
                return(NotFound());
            }

            _logger.LogInformation("Editando a tarefa de Id: {id}", id);
            _mapper.Map(taskUpdateDto, task);
            _tasksRepo.SaveChanges();

            if (task.TaskTags != null && task.TaskTags.Count > 0)
            {
                _logger.LogInformation("Deletando as tags atuais da tarefa de Id: {id}", id);
                _taskTagsRepo.DeleteTaskTags(task.TaskTags);
                _taskTagsRepo.SaveChanges();
            }

            if (taskUpdateDto.Tags != null && taskUpdateDto.Tags.Count > 0)
            {
                Tag     tag;
                TaskTag taskTag = new TaskTag()
                {
                    TaskId = task.Id
                };

                _logger.LogInformation("Cadastrando as novas tags da tarefa de Id: {id}", id);
                foreach (TagUpdateDto tagUpdateDto in taskUpdateDto.Tags)
                {
                    tag = _mapper.Map <Tag>(tagUpdateDto);
                    _tagsRepo.PostTag(tag);
                    _tagsRepo.SaveChanges();

                    taskTag.TagId = tag.Id;
                    _taskTagsRepo.PostTaskTag(taskTag);
                    _taskTagsRepo.SaveChanges();
                }
            }

            return(NoContent());
        }
Beispiel #13
0
        public IActionResult UpdateTask(long id, [FromBody] TaskUpdateDto updateDto)
        {
            var existingTask = _taskRepository.GetSingle(id);

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

            Mapper.Map(updateDto, existingTask);

            _taskRepository.Update(existingTask);

            bool result = _taskRepository.Save();

            if (!result)
            {
                return(new StatusCodeResult(500));
            }

            return(Ok(Mapper.Map <TaskDto>(existingTask)));
        }
Beispiel #14
0
        public async Task <TaskUpdateDto> UpdateTasksPost(TaskUpdateDto taskUpdateDto)
        {
            //var veri = await _generictaskdate.GetAllAsync();



            var gunluk   = _taskDateDal.GetGunluk();
            var haftalik = _taskDateDal.GetHaftalık();
            var aylik    = _taskDateDal.GetAylik();



            if (taskUpdateDto.TaskDate == gunluk)
            {
                taskUpdateDto.StartDate  = DateTime.Now;
                taskUpdateDto.FinishDate = DateTime.Now.AddDays(1);
            }
            else if (taskUpdateDto.TaskDate == haftalik)
            {
                taskUpdateDto.StartDate  = DateTime.Now;
                taskUpdateDto.FinishDate = DateTime.Now.AddDays(7);
            }
            else if (taskUpdateDto.TaskDate == aylik)
            {
                taskUpdateDto.StartDate  = DateTime.Now;
                taskUpdateDto.FinishDate = DateTime.Now.AddDays(30);
            }
            taskUpdateDto.Status = "Active";


            //await _genericDal.UpdateAsync(_mapper.Map<Tasks>(taskUpdateDto));



            return(null);
        }
        public async Task <IActionResult> UpdateTaskForUser(string idUser, string idTask, [FromBody] TaskUpdateDto taskUpdateDto)
        {
            if (null == taskUpdateDto)
            {
                return(BadRequest());
            }

            if (taskUpdateDto.Name == taskUpdateDto.Description)
            {
                ModelState.AddModelError(nameof(TaskUpdateDto), "Task Name and Description should not match");
            }
            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var userId = ObjectId.Parse(idUser);

            if (!await _appRepository.UserExistsAsync(userId))
            {
                return(NotFound());
            }

            var taskId       = ObjectId.Parse(idTask);
            var taskToUpdate = await _appRepository.GetTaskAsync(userId, taskId);

            if (null == taskToUpdate)
            {
                return(NotFound());                      // won't allow Upserting
            }
            Mapper.Map(taskUpdateDto, taskToUpdate);
            var result = await _appRepository.UpdateTaskAsync(userId, taskId, taskToUpdate);

            if (!result)
            {
                throw new Exception($"Failed to update task: {idTask}, for author: {idUser}");
            }
            return(NoContent());
        }