public async Task Update_WithValidDto_ShouldUpdateWithSuccess()
        {
            // Arrange
            var taskDto = new TaskForCreationDto
            {
                Completed   = false,
                Description = "integration test",
                Priority    = (int)Priority.Low
            };

            var id = Guid.NewGuid();

            await CreateDataAsync(new TaskDomain(id, "test update", Priority.High, true));

            var url = $"api/task/{id}";

            taskDto.Description = "update";

            var serialiedDto = new StringContent(JsonConvert.SerializeObject(taskDto), Encoding.UTF8, "application/json");

            // Act
            var response = await _httpClient.PutAsync(url, serialiedDto);

            //Assert
            response.EnsureSuccessStatusCode();
            (await GetDataAsync <TaskDomain>(id)).Description.Should().Be(taskDto.Description);
        }
Esempio n. 2
0
        public async Task <IActionResult> AddTask(string userName, TaskForCreationDto taskForCreation)
        {
            if (userName != (User.FindFirst(ClaimTypes.Name).Value))
            {
                return(Unauthorized());
            }

            if (ModelState.IsValid)
            {
                var user = await userManager.Users.Include(u => u.ToDos).FirstOrDefaultAsync(u => u.UserName == userName);

                if (user != null)
                {
                    var toDo = mapper.Map <ToDo>(taskForCreation);


                    user.ToDos.Add(toDo);

                    if (await toDoRepository.SaveAll())
                    {
                        return(StatusCode(201));
                    }

                    return(BadRequest());
                }

                return(Unauthorized());
            }

            return(BadRequest());
        }
Esempio n. 3
0
        public ActionResult CreateTask([FromBody] TaskForCreationDto task)
        {
            var taskEntity = _mapper.Map <Entities.Task>(task);

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

            try
            {
                _easyKBTaskBoardRepository.AddTask(taskEntity);
                _easyKBTaskBoardRepository.Save();
            }
            catch (Exception)
            {
                return(NotFound($"Column with id {task.ColumnId} couldn't be found.\nCreating failed."));
            }

            var createdTaskToReturn = _mapper.Map <TaskDto>(taskEntity);

            return(CreatedAtRoute(
                       "GetTask",
                       new { taskId = createdTaskToReturn.Id },
                       createdTaskToReturn));
        }
Esempio n. 4
0
        public async Task <TaskDetailsDto> CreateATask([FromRoute] int teamId,
                                                       [FromBody] TaskForCreationDto dto)
        {
            dto.TeamId = teamId;

            return(await _mediator.Send(new CreateNewTaskCommand { TaskForCreationDto = dto }));
        }
Esempio n. 5
0
        public async Task <IActionResult> Post([FromBody] TaskForCreationDto taskForCreation)
        {
            var task = new Domain.Entities.Task();
            // Map the Dto columnForCreation to column. For example refer BoardController
            // Assign the AssigneeIds of task by providing the userIds if needed
            await _unitOfWork.Tasks.AddAsync(task);

            await _unitOfWork.SaveChangesAsync();

            return(Ok(task));
        }
Esempio n. 6
0
        public async Task UpdateAsync(Guid id, TaskForCreationDto taskForCreation)
        {
            var task = await GetAndValidateAsync(id);

            task.Update(taskForCreation.Description, taskForCreation.Completed, (Priority)taskForCreation.Priority);

            task.Validate();

            _repository.Update(task);

            await _repository.SaveChangesAsync();
        }
Esempio n. 7
0
        public async Task <Guid> CreateAsync(TaskForCreationDto taskForCreation)
        {
            var taskDomain = new TaskDomain(Guid.NewGuid(), taskForCreation.Description, (Priority)taskForCreation.Priority, taskForCreation.Completed);

            taskDomain.Validate();

            var id = await _repository.CreateAsync(taskDomain);

            await _repository.SaveChangesAsync();

            return(id);
        }
        public async Task CreateAsync_WithValidValues_ShouldCreateTaskAndReturnId()
        {
            // Arrange
            var taskDto = new TaskForCreationDto
            {
                Completed   = false,
                Description = "test",
                Priority    = 1
            };

            var id = Guid.NewGuid();

            _repository.CreateAsync(default).ReturnsForAnyArgs(id);
Esempio n. 9
0
        public async Task <IActionResult> CreateTaskForProject(Guid projectId, TaskForCreationDto taskForCreation)
        {
            if (taskForCreation.StartDate < DateTime.Today)
            {
                return(BadRequest("Start Date cannot be before today"));
            }

            if (taskForCreation.EndDate < taskForCreation.StartDate)
            {
                return(BadRequest("End Date cannot be before Start Date"));
            }

            var projectFromRepo = await _repository.Project.GetProject(projectId);

            if (projectFromRepo == null)
            {
                return(BadRequest("Project doesn't exist"));
            }

            Status     status;
            Priority   priority;
            Completion percentage;

            Enum.TryParse(taskForCreation.Status, out status);
            Enum.TryParse(taskForCreation.Percentage, out percentage);
            Enum.TryParse(taskForCreation.Priority, out priority);

            var taskToCreate = _mapper.Map <Entities.Models.Task>(taskForCreation);
            var creatorId    = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));

            taskToCreate.Priority   = priority;
            taskToCreate.Percentage = percentage;
            taskToCreate.Status     = status;
            taskToCreate.ProjectId  = projectId;
            taskToCreate.CreatorId  = creatorId;

            _repository.Task.CreateTask(taskToCreate);
            var saveTask = await _repository.SaveAsync();

            if (!saveTask)
            {
                throw new Exception("Failed to create task for project");
            }

            var taskToReturn = _mapper.Map <TaskForDetailedDto>(taskToCreate);

            return(CreatedAtRoute("GetTask",
                                  new { projectId = taskToCreate.ProjectId, taskId = taskToCreate.TaskId }, taskToReturn));
        }
 public IActionResult AddTask([FromBody] TaskForCreationDto taskForCreation, Guid userId)
 {
     try
     {
         if (taskForCreation == null)
         {
             return(BadRequest());
         }
         Task taskEntity = Mapper.Map <Task>(taskForCreation);
         Task task       = taskServices.AddTask(taskEntity, userId);
         if (!taskServices.Save())
         {
             return(StatusCode(500, "A problem happened with handling your request."));
         }
         return(Ok(task));
     }
     catch (Exception exp)
     {
         return(StatusCode(500, "A problem happened with handling your request."));
     }
 }
Esempio n. 11
0
        public async Task <IActionResult> Create(TaskForCreationDto task)
        {
            if (!await _users.UserExist(task.CreatorId) || !await _users.UserExist(task.AssigneeId) || !await _organizations.OrganizationExist(task.OrganizationId))
            {
                return(BadRequest("Bad request data, data don't exist."));
            }
            var taskToCreate = new Task
            {
                Title          = task.Title,
                Description    = task.Description,
                CreatorId      = task.CreatorId,
                AssigneeId     = task.AssigneeId,
                OrganizationId = task.OrganizationId,
                Created        = DateTime.Now,
                LastUpdated    = DateTime.Now,
            };
            var taskCreated = await _repo.Add(taskToCreate);

            var taskToReturn = _mapper.Map <TaskForListDto>(taskCreated);

            return(Ok(taskToReturn));
        }
Esempio n. 12
0
        public IActionResult CreateTask([FromBody] TaskForCreationDto task)
        {
            try
            {
                if (task == null)
                {
                    _logger.LogError("Task object sent from client is null");
                    return(BadRequest("Task object is null"));
                }

                var user = _repository.User.GetUserById(task.UserId);

                if (user == null)
                {
                    _logger.LogError($"User with id {task.UserId} was not found in database");
                    return(BadRequest("Invalid user id"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid user object sent from client");
                    return(BadRequest("Invalid model object"));
                }

                var taskEntity = _mapper.Map <Task>(task);

                _repository.Task.CreateTask(taskEntity);
                _repository.Save();

                var createdTask = _mapper.Map <TaskDto>(taskEntity);

                return(CreatedAtRoute("TaskDetails", new { userId = user.Id, taskId = createdTask.Id }, createdTask));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateTask action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public async Task Create_WithValidDto_ShouldCreateWithSuccess()
        {
            // Arrange
            var url = "api/task";
            var dto = new TaskForCreationDto
            {
                Completed   = false,
                Description = "integration test",
                Priority    = (int)Priority.Low
            };

            var serialiedDto = new StringContent(JsonConvert.SerializeObject(dto), Encoding.UTF8, "application/json");

            // Act
            var response = await _httpClient.PostAsync(url, serialiedDto);

            //Assert
            response.EnsureSuccessStatusCode();

            var id = JsonConvert.DeserializeObject <Guid>(await response.Content.ReadAsStringAsync());

            id.Should().NotBe(Guid.Empty);
        }
Esempio n. 14
0
        public async Task <IActionResult> Put(Guid id, [FromBody] TaskForCreationDto dto)
        {
            await _appService.UpdateAsync(id, dto);

            return(NoContent());
        }
Esempio n. 15
0
 public async Task <IActionResult> Post([FromBody] TaskForCreationDto dto)
 {
     return(Ok(await _appService.CreateAsync(dto)));
 }