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); }
public virtual ApiCityServerRequestModel MapServerResponseToRequest( ApiCityServerResponseModel response) { var request = new ApiCityServerRequestModel(); request.SetProperties( response.Name, response.ProvinceId); return(request); }
public virtual ApiCityServerResponseModel MapServerRequestToResponse( int id, ApiCityServerRequestModel request) { var response = new ApiCityServerResponseModel(); response.SetProperties(id, request.Name, request.ProvinceId); return(response); }
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); }
public virtual City MapModelToEntity( int id, ApiCityServerRequestModel model ) { City item = new City(); item.SetProperties( id, model.Name, model.ProvinceId); return(item); }
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); }
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)); } }