public ActionResult <AssignmentReadDto> CreateAssignment(AssignmentCreateDto assignmentCreateDto)
        {
            var assignmentModel = _mapper.Map <Assignment>(assignmentCreateDto);

            _repository.CreateAssignment(assignmentModel);
            _repository.SaveChanges();

            var assignmentReadDto = _mapper.Map <AssignmentReadDto>(assignmentModel);

            return(CreatedAtRoute(nameof(GetAssignmentById),
                                  new { ID = assignmentReadDto.ID }, assignmentReadDto));
        }
        public async void AssignAllreadyAssignedUserToApplicationShouldReturnBadRequest()
        {
            var assignmentCreateDto = new AssignmentCreateDto()
            {
                UserId = _userId1
            };

            var serializedAssignmentCreateDto = JsonConvert.SerializeObject(assignmentCreateDto);
            var httpResponse = await _fixture.PostHttpResult($"{UrlPath}{_applicationId4}/assignments/", serializedAssignmentCreateDto);

            httpResponse.Should().NotBeNull();
            httpResponse.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        public async void AssignUserToApplicationShouldReturnOkAndAssignThisUserToTheApplication()
        {
            var assignmentCreateDto = new AssignmentCreateDto()
            {
                UserId = _userId3
            };

            var serializedAssignmentCreateDto = JsonConvert.SerializeObject(assignmentCreateDto);
            var httpResponse = await _fixture.PostHttpResult($"{UrlPath}{_applicationId4}/assignments/", serializedAssignmentCreateDto);

            httpResponse.Should().NotBeNull();
            httpResponse.StatusCode.Should().Be(HttpStatusCode.OK);
        }
        public async Task <bool> CreateAssignmentAsync(AssignmentCreateDto input)
        {
            var assignment = input.To <Assignment>();

            var inputStatusName = await this.statusesService.GetStatusNameByIdAsync(input.StatusId);

            if (inputStatusName == Constants.STATUS_COMPLETED)
            {
                assignment.EndDate  = DateTime.UtcNow;
                assignment.Progress = Constants.PROGRESS_MAX_VALUE;
            }

            assignment.AssignmentsAssistants = this.assignmentsEmployeesService.CreateWithAssistantsIds(input.AssistantsIds).ToList();

            await this.context.Assignments.AddAsync(assignment);

            var result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Exemple #5
0
        // assignes a user to an application
        public IActionResult AssignUserToApplication(Guid applicationId, AssignmentCreateDto assignmentCreateDto)
        {
            var assignmentExists = _applicationDbContext.Assignment.SingleOrDefault(
                assignment => assignment.ApplicationId == applicationId &&
                assignment.UserId == assignmentCreateDto.UserId);

            if (assignmentExists != null)
            {
                return(new BadRequestObjectResult("User is allready assigned to this application"));
            }

            _applicationDbContext.Assignment.Add(new Assignment()
            {
                ApplicationId = applicationId,
                UserId        = assignmentCreateDto.UserId
            });

            Save();

            var updatedApplication = GetApplicationById(applicationId);

            return(new OkObjectResult(updatedApplication));
        }
        public virtual IActionResult AssignUserToApplication([FromRoute] Guid applicationId, [FromBody] AssignmentCreateDto assingnmentCreateDto)
        {
            var result = _applicationRepository.AssignUserToApplication(applicationId, assingnmentCreateDto);

            return(result);
        }