Exemplo n.º 1
0
        public JsonPatchDocument <ApiPersonServerRequestModel> CreatePatch(ApiPersonServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiPersonServerRequestModel>();

            patch.Replace(x => x.PersonName, model.PersonName);
            return(patch);
        }
Exemplo n.º 2
0
        public virtual ApiPersonServerRequestModel MapServerResponseToRequest(
            ApiPersonServerResponseModel response)
        {
            var request = new ApiPersonServerRequestModel();

            request.SetProperties(
                response.PersonName);
            return(request);
        }
Exemplo n.º 3
0
        public void MapModelToEntity()
        {
            var mapper = new DALPersonMapper();
            ApiPersonServerRequestModel model = new ApiPersonServerRequestModel();

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

            response.PersonName.Should().Be("A");
        }
Exemplo n.º 4
0
        public virtual ApiPersonServerResponseModel MapServerRequestToResponse(
            int personId,
            ApiPersonServerRequestModel request)
        {
            var response = new ApiPersonServerResponseModel();

            response.SetProperties(personId,
                                   request.PersonName);
            return(response);
        }
Exemplo n.º 5
0
        public virtual Person MapModelToEntity(
            int personId,
            ApiPersonServerRequestModel model
            )
        {
            Person item = new Person();

            item.SetProperties(
                personId,
                model.PersonName);
            return(item);
        }
Exemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiPersonServerResponseModel> > Create(
            ApiPersonServerRequestModel model)
        {
            CreateResponse <ApiPersonServerResponseModel> response = ValidationResponseFactory <ApiPersonServerResponseModel> .CreateResponse(await this.PersonModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Person record = this.DalPersonMapper.MapModelToEntity(default(int), model);
                record = await this.PersonRepository.Create(record);

                response.SetRecord(this.DalPersonMapper.MapEntityToModel(record));
                await this.mediator.Publish(new PersonCreatedNotification(response.Record));
            }

            return(response);
        }
Exemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiPersonServerResponseModel> > Update(
            int personId,
            ApiPersonServerRequestModel model)
        {
            var validationResult = await this.PersonModelValidator.ValidateUpdateAsync(personId, model);

            if (validationResult.IsValid)
            {
                Person record = this.DalPersonMapper.MapModelToEntity(personId, model);
                await this.PersonRepository.Update(record);

                record = await this.PersonRepository.Get(personId);

                ApiPersonServerResponseModel apiModel = this.DalPersonMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PersonUpdatedNotification(apiModel));

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