示例#1
0
        public virtual ApiCallPersonServerResponseModel MapEntityToModel(
            CallPerson item)
        {
            var model = new ApiCallPersonServerResponseModel();

            model.SetProperties(item.Id,
                                item.Note,
                                item.PersonId,
                                item.PersonTypeId);
            if (item.PersonIdNavigation != null)
            {
                var personIdModel = new ApiPersonServerResponseModel();
                personIdModel.SetProperties(
                    item.PersonIdNavigation.Id,
                    item.PersonIdNavigation.FirstName,
                    item.PersonIdNavigation.LastName,
                    item.PersonIdNavigation.Phone,
                    item.PersonIdNavigation.Ssn);

                model.SetPersonIdNavigation(personIdModel);
            }

            if (item.PersonTypeIdNavigation != null)
            {
                var personTypeIdModel = new ApiPersonTypeServerResponseModel();
                personTypeIdModel.SetProperties(
                    item.PersonTypeIdNavigation.Id,
                    item.PersonTypeIdNavigation.Name);

                model.SetPersonTypeIdNavigation(personTypeIdModel);
            }

            return(model);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALCallPersonMapper();
            ApiCallPersonServerRequestModel model = new ApiCallPersonServerRequestModel();

            model.SetProperties("A", 1, 1);
            CallPerson response = mapper.MapModelToEntity(1, model);

            response.Note.Should().Be("A");
            response.PersonId.Should().Be(1);
            response.PersonTypeId.Should().Be(1);
        }
示例#3
0
        public virtual async Task <ApiCallPersonServerResponseModel> Get(int id)
        {
            CallPerson record = await this.CallPersonRepository.Get(id);

            if (record == null)
            {
                return(null);
            }
            else
            {
                return(this.DalCallPersonMapper.MapEntityToModel(record));
            }
        }
        public void MapEntityToModelList()
        {
            var        mapper = new DALCallPersonMapper();
            CallPerson item   = new CallPerson();

            item.SetProperties(1, "A", 1, 1);
            List <ApiCallPersonServerResponseModel> response = mapper.MapEntityToModel(new List <CallPerson>()
            {
                { item }
            });

            response.Count.Should().Be(1);
        }
        public void MapEntityToModel()
        {
            var        mapper = new DALCallPersonMapper();
            CallPerson item   = new CallPerson();

            item.SetProperties(1, "A", 1, 1);
            ApiCallPersonServerResponseModel response = mapper.MapEntityToModel(item);

            response.Id.Should().Be(1);
            response.Note.Should().Be("A");
            response.PersonId.Should().Be(1);
            response.PersonTypeId.Should().Be(1);
        }
示例#6
0
        public virtual CallPerson MapModelToEntity(
            int id,
            ApiCallPersonServerRequestModel model
            )
        {
            CallPerson item = new CallPerson();

            item.SetProperties(
                id,
                model.Note,
                model.PersonId,
                model.PersonTypeId);
            return(item);
        }
示例#7
0
        public virtual async Task <CreateResponse <ApiCallPersonServerResponseModel> > Create(
            ApiCallPersonServerRequestModel model)
        {
            CreateResponse <ApiCallPersonServerResponseModel> response = ValidationResponseFactory <ApiCallPersonServerResponseModel> .CreateResponse(await this.CallPersonModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                CallPerson record = this.DalCallPersonMapper.MapModelToEntity(default(int), model);
                record = await this.CallPersonRepository.Create(record);

                response.SetRecord(this.DalCallPersonMapper.MapEntityToModel(record));
                await this.mediator.Publish(new CallPersonCreatedNotification(response.Record));
            }

            return(response);
        }
示例#8
0
        public async void Get_ShouldReturnRecords()
        {
            var mock   = new ServiceMockFacade <ICallPersonService, ICallPersonRepository>();
            var record = new CallPerson();

            mock.RepositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(record));
            var service = new CallPersonService(mock.LoggerMock.Object,
                                                mock.MediatorMock.Object,
                                                mock.RepositoryMock.Object,
                                                mock.ModelValidatorMockFactory.CallPersonModelValidatorMock.Object,
                                                mock.DALMapperMockFactory.DALCallPersonMapperMock);

            ApiCallPersonServerResponseModel response = await service.Get(default(int));

            response.Should().NotBeNull();
            mock.RepositoryMock.Verify(x => x.Get(It.IsAny <int>()));
        }
示例#9
0
        public virtual async Task <UpdateResponse <ApiCallPersonServerResponseModel> > Update(
            int id,
            ApiCallPersonServerRequestModel model)
        {
            var validationResult = await this.CallPersonModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                CallPerson record = this.DalCallPersonMapper.MapModelToEntity(id, model);
                await this.CallPersonRepository.Update(record);

                record = await this.CallPersonRepository.Get(id);

                ApiCallPersonServerResponseModel apiModel = this.DalCallPersonMapper.MapEntityToModel(record);
                await this.mediator.Publish(new CallPersonUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiCallPersonServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiCallPersonServerResponseModel> .UpdateResponse(validationResult));
            }
        }