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

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

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

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

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

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

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

            if (response.Success)
            {
                City record = this.DalCityMapper.MapModelToEntity(default(int), model);
                record = await this.CityRepository.Create(record);

                response.SetRecord(this.DalCityMapper.MapEntityToModel(record));
                await this.mediator.Publish(new CityCreatedNotification(response.Record));
            }

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

            if (validationResult.IsValid)
            {
                City record = this.DalCityMapper.MapModelToEntity(id, model);
                await this.CityRepository.Update(record);

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

                ApiCityServerResponseModel apiModel = this.DalCityMapper.MapEntityToModel(record);
                await this.mediator.Publish(new CityUpdatedNotification(apiModel));

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