예제 #1
0
        public async Task <IActionResult> Create(CreateJobApplicantInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var rowsCreated = await this.applicantService.AddApplicantAsync(model, model.Image);

            if (rowsCreated != WebConstants.OneRow)
            {
                return(this.BadRequest());
            }

            return(this.Redirect(WebConstants.HomePagePath));
        }
        public async Task CreateApplicantInvalidPosition_ShouldThrowJobExc()
        {
            this.Initialize();
            this.SeedPositions();

            var input = new CreateJobApplicantInputModel()
            {
                Firstname           = FirstName,
                Middlename          = MiddleName,
                Lastname            = LastName,
                PhoneNumber         = PhoneNumber,
                Bio                 = Bio,
                Age                 = Age,
                ExperienceInSelling = false,
                Position            = PositionTwoName,
            };

            await Assert.ThrowsAsync <JobPositionNotFoundException>(() => this.service.AddApplicantAsync(input, image));
        }
        public async Task CreateApplicant_ShouldReturnCorrect()
        {
            this.Initialize();
            this.SeedPositions();

            var input = new CreateJobApplicantInputModel()
            {
                Firstname           = FirstName,
                Middlename          = MiddleName,
                Lastname            = LastName,
                PhoneNumber         = PhoneNumber,
                Bio                 = Bio,
                Age                 = Age,
                ExperienceInSelling = false,
                Position            = PositionName,
            };

            var input2 = new CreateJobApplicantInputModel()
            {
                Firstname           = FirstName,
                Middlename          = MiddleName,
                Lastname            = LastName,
                PhoneNumber         = PhoneNumber,
                Bio                 = Bio,
                Age                 = Age,
                ExperienceInSelling = true,
                Position            = PositionName + 1,
            };

            var expectedCount = 1;
            var addedCount    = await this.service.AddApplicantAsync(input, image);

            Assert.Equal(expectedCount, addedCount);
            Assert.Equal(expectedCount, this.context.Applicants.Count());

            addedCount = await this.service.AddApplicantAsync(input2, image);

            Assert.Equal(expectedCount, addedCount);
            expectedCount = 2;
            Assert.Equal(expectedCount, this.context.Applicants.Count());
        }
예제 #4
0
        public async Task <int> AddApplicantAsync(CreateJobApplicantInputModel inputModel, IFormFile image)
        {
            var jobPosition = await this.context
                              .Positions
                              .SingleOrDefaultAsync(x => x.Name == inputModel.Position);

            if (jobPosition == null)
            {
                throw new JobPositionNotFoundException(string.Format(
                                                           ExceptionMessages.InvalidJobPosition, inputModel.Position));
            }

            var entity = this.mapper.Map <JobApplicant>(inputModel);

            entity.Position = jobPosition;
            entity.ImageUrl = this.cloudinary.UploadImage(image);

            this.context.Applicants.Add(entity);

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

            return(rowsAdded);
        }