コード例 #1
0
        public JsonPatchDocument <ApiCountryServerRequestModel> CreatePatch(ApiCountryServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiCountryServerRequestModel>();

            patch.Replace(x => x.Name, model.Name);
            return(patch);
        }
コード例 #2
0
        public virtual ApiCountryServerRequestModel MapServerResponseToRequest(
            ApiCountryServerResponseModel response)
        {
            var request = new ApiCountryServerRequestModel();

            request.SetProperties(
                response.Name);
            return(request);
        }
コード例 #3
0
        public virtual ApiCountryServerResponseModel MapServerRequestToResponse(
            int id,
            ApiCountryServerRequestModel request)
        {
            var response = new ApiCountryServerResponseModel();

            response.SetProperties(id,
                                   request.Name);
            return(response);
        }
コード例 #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALCountryMapper();
            ApiCountryServerRequestModel model = new ApiCountryServerRequestModel();

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

            response.Name.Should().Be("A");
        }
コード例 #5
0
        public virtual Country MapModelToEntity(
            int id,
            ApiCountryServerRequestModel model
            )
        {
            Country item = new Country();

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
コード例 #6
0
        public virtual async Task <CreateResponse <ApiCountryServerResponseModel> > Create(
            ApiCountryServerRequestModel model)
        {
            CreateResponse <ApiCountryServerResponseModel> response = ValidationResponseFactory <ApiCountryServerResponseModel> .CreateResponse(await this.CountryModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Country record = this.DalCountryMapper.MapModelToEntity(default(int), model);
                record = await this.CountryRepository.Create(record);

                response.SetRecord(this.DalCountryMapper.MapEntityToModel(record));
                await this.mediator.Publish(new CountryCreatedNotification(response.Record));
            }

            return(response);
        }
コード例 #7
0
        public virtual async Task <UpdateResponse <ApiCountryServerResponseModel> > Update(
            int id,
            ApiCountryServerRequestModel model)
        {
            var validationResult = await this.CountryModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Country record = this.DalCountryMapper.MapModelToEntity(id, model);
                await this.CountryRepository.Update(record);

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

                ApiCountryServerResponseModel apiModel = this.DalCountryMapper.MapEntityToModel(record);
                await this.mediator.Publish(new CountryUpdatedNotification(apiModel));

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