public JsonPatchDocument <ApiPetServerRequestModel> CreatePatch(ApiPetServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiPetServerRequestModel>();

            patch.Replace(x => x.BreedId, model.BreedId);
            patch.Replace(x => x.ClientId, model.ClientId);
            patch.Replace(x => x.Name, model.Name);
            patch.Replace(x => x.Weight, model.Weight);
            return(patch);
        }
        public virtual ApiPetServerRequestModel MapServerResponseToRequest(
            ApiPetServerResponseModel response)
        {
            var request = new ApiPetServerRequestModel();

            request.SetProperties(
                response.BreedId,
                response.ClientId,
                response.Name,
                response.Weight);
            return(request);
        }
        public virtual ApiPetServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPetServerRequestModel request)
        {
            var response = new ApiPetServerResponseModel();

            response.SetProperties(id,
                                   request.BreedId,
                                   request.ClientId,
                                   request.Name,
                                   request.Weight);
            return(response);
        }
示例#4
0
        public void MapModelToEntity()
        {
            var mapper = new DALPetMapper();
            ApiPetServerRequestModel model = new ApiPetServerRequestModel();

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

            response.BreedId.Should().Be(1);
            response.ClientId.Should().Be(1);
            response.Name.Should().Be("A");
            response.Weight.Should().Be(1);
        }
示例#5
0
        public virtual Pet MapModelToEntity(
            int id,
            ApiPetServerRequestModel model
            )
        {
            Pet item = new Pet();

            item.SetProperties(
                id,
                model.BreedId,
                model.ClientId,
                model.Name,
                model.Weight);
            return(item);
        }
示例#6
0
        public virtual async Task <CreateResponse <ApiPetServerResponseModel> > Create(
            ApiPetServerRequestModel model)
        {
            CreateResponse <ApiPetServerResponseModel> response = ValidationResponseFactory <ApiPetServerResponseModel> .CreateResponse(await this.PetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Pet record = this.DalPetMapper.MapModelToEntity(default(int), model);
                record = await this.PetRepository.Create(record);

                response.SetRecord(this.DalPetMapper.MapEntityToModel(record));
                await this.mediator.Publish(new PetCreatedNotification(response.Record));
            }

            return(response);
        }
示例#7
0
        public virtual async Task <UpdateResponse <ApiPetServerResponseModel> > Update(
            int id,
            ApiPetServerRequestModel model)
        {
            var validationResult = await this.PetModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Pet record = this.DalPetMapper.MapModelToEntity(id, model);
                await this.PetRepository.Update(record);

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

                ApiPetServerResponseModel apiModel = this.DalPetMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PetUpdatedNotification(apiModel));

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