public async Task <ValidationResult> ValidateUpdateAsync(int id, ApiJobCandidateRequestModel model)
 {
     this.BusinessEntityIDRules();
     this.ModifiedDateRules();
     this.ResumeRules();
     return(await this.ValidateAsync(model, id));
 }
Beispiel #2
0
        private async Task <ApiJobCandidateResponseModel> CreateRecord(ApiClient client)
        {
            var model = new ApiJobCandidateRequestModel();

            model.SetProperties(2, DateTime.Parse("1/1/1988 12:00:00 AM"), "B");
            CreateResponse <ApiJobCandidateResponseModel> result = await client.JobCandidateCreateAsync(model);

            result.Success.Should().BeTrue();
            return(result.Record);
        }
        public void MapModelToBO()
        {
            var mapper = new BOLJobCandidateMapper();
            ApiJobCandidateRequestModel model = new ApiJobCandidateRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            BOJobCandidate response = mapper.MapModelToBO(1, model);

            response.BusinessEntityID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Resume.Should().Be("A");
        }
        public virtual async Task <IActionResult> Create([FromBody] ApiJobCandidateRequestModel model)
        {
            CreateResponse <ApiJobCandidateResponseModel> result = await this.JobCandidateService.Create(model);

            if (result.Success)
            {
                return(this.Created($"{this.Settings.ExternalBaseUrl}/api/JobCandidates/{result.Record.JobCandidateID}", result));
            }
            else
            {
                return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
            }
        }
Beispiel #5
0
        public virtual BOJobCandidate MapModelToBO(
            int jobCandidateID,
            ApiJobCandidateRequestModel model
            )
        {
            BOJobCandidate boJobCandidate = new BOJobCandidate();

            boJobCandidate.SetProperties(
                jobCandidateID,
                model.BusinessEntityID,
                model.ModifiedDate,
                model.Resume);
            return(boJobCandidate);
        }
        public virtual async Task <CreateResponse <ApiJobCandidateResponseModel> > Create(
            ApiJobCandidateRequestModel model)
        {
            CreateResponse <ApiJobCandidateResponseModel> response = new CreateResponse <ApiJobCandidateResponseModel>(await this.JobCandidateModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                var bo     = this.BolJobCandidateMapper.MapModelToBO(default(int), model);
                var record = await this.JobCandidateRepository.Create(this.DalJobCandidateMapper.MapBOToEF(bo));

                response.SetRecord(this.BolJobCandidateMapper.MapBOToModel(this.DalJobCandidateMapper.MapEFToBO(record)));
            }

            return(response);
        }
        private async Task <ApiJobCandidateRequestModel> PatchModel(int id, JsonPatchDocument <ApiJobCandidateRequestModel> patch)
        {
            var record = await this.JobCandidateService.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                ApiJobCandidateRequestModel request = this.JobCandidateModelMapper.MapResponseToRequest(record);
                patch.ApplyTo(request);
                return(request);
            }
        }
        public void CreatePatch()
        {
            var mapper = new ApiJobCandidateModelMapper();
            var model  = new ApiJobCandidateRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");

            JsonPatchDocument <ApiJobCandidateRequestModel> patch = mapper.CreatePatch(model);
            var response = new ApiJobCandidateRequestModel();

            patch.ApplyTo(response);
            response.BusinessEntityID.Should().Be(1);
            response.ModifiedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Resume.Should().Be("A");
        }
        public async void Create()
        {
            var mock  = new ServiceMockFacade <IJobCandidateRepository>();
            var model = new ApiJobCandidateRequestModel();

            mock.RepositoryMock.Setup(x => x.Create(It.IsAny <JobCandidate>())).Returns(Task.FromResult(new JobCandidate()));
            var service = new JobCandidateService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.JobCandidateModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLJobCandidateMapperMock,
                                                  mock.DALMapperMockFactory.DALJobCandidateMapperMock);

            CreateResponse <ApiJobCandidateResponseModel> response = await service.Create(model);

            response.Should().NotBeNull();
            mock.ModelValidatorMockFactory.JobCandidateModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiJobCandidateRequestModel>()));
            mock.RepositoryMock.Verify(x => x.Create(It.IsAny <JobCandidate>()));
        }
        public async void Delete()
        {
            var mock  = new ServiceMockFacade <IJobCandidateRepository>();
            var model = new ApiJobCandidateRequestModel();

            mock.RepositoryMock.Setup(x => x.Delete(It.IsAny <int>())).Returns(Task.CompletedTask);
            var service = new JobCandidateService(mock.LoggerMock.Object,
                                                  mock.RepositoryMock.Object,
                                                  mock.ModelValidatorMockFactory.JobCandidateModelValidatorMock.Object,
                                                  mock.BOLMapperMockFactory.BOLJobCandidateMapperMock,
                                                  mock.DALMapperMockFactory.DALJobCandidateMapperMock);

            ActionResponse response = await service.Delete(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Delete(It.IsAny <int>()));
            mock.ModelValidatorMockFactory.JobCandidateModelValidatorMock.Verify(x => x.ValidateDeleteAsync(It.IsAny <int>()));
        }
        public virtual async Task <UpdateResponse <ApiJobCandidateResponseModel> > Update(
            int jobCandidateID,
            ApiJobCandidateRequestModel model)
        {
            var validationResult = await this.JobCandidateModelValidator.ValidateUpdateAsync(jobCandidateID, model);

            if (validationResult.IsValid)
            {
                var bo = this.BolJobCandidateMapper.MapModelToBO(jobCandidateID, model);
                await this.JobCandidateRepository.Update(this.DalJobCandidateMapper.MapBOToEF(bo));

                var record = await this.JobCandidateRepository.Get(jobCandidateID);

                return(new UpdateResponse <ApiJobCandidateResponseModel>(this.BolJobCandidateMapper.MapBOToModel(this.DalJobCandidateMapper.MapEFToBO(record))));
            }
            else
            {
                return(new UpdateResponse <ApiJobCandidateResponseModel>(validationResult));
            }
        }
        public virtual async Task <IActionResult> Update(int id, [FromBody] ApiJobCandidateRequestModel model)
        {
            ApiJobCandidateRequestModel request = await this.PatchModel(id, this.JobCandidateModelMapper.CreatePatch(model));

            if (request == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                UpdateResponse <ApiJobCandidateResponseModel> result = await this.JobCandidateService.Update(id, request);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }
        public virtual async Task <IActionResult> Patch(int id, [FromBody] JsonPatchDocument <ApiJobCandidateRequestModel> patch)
        {
            ApiJobCandidateResponseModel record = await this.JobCandidateService.Get(id);

            if (record == null)
            {
                return(this.StatusCode(StatusCodes.Status404NotFound));
            }
            else
            {
                ApiJobCandidateRequestModel model = await this.PatchModel(id, patch);

                UpdateResponse <ApiJobCandidateResponseModel> result = await this.JobCandidateService.Update(id, model);

                if (result.Success)
                {
                    return(this.Ok(result));
                }
                else
                {
                    return(this.StatusCode(StatusCodes.Status422UnprocessableEntity, result));
                }
            }
        }