public JsonPatchDocument <ApiBreedServerRequestModel> CreatePatch(ApiBreedServerRequestModel model) { var patch = new JsonPatchDocument <ApiBreedServerRequestModel>(); patch.Replace(x => x.Name, model.Name); patch.Replace(x => x.SpeciesId, model.SpeciesId); return(patch); }
public virtual ApiBreedServerRequestModel MapServerResponseToRequest( ApiBreedServerResponseModel response) { var request = new ApiBreedServerRequestModel(); request.SetProperties( response.Name, response.SpeciesId); return(request); }
public virtual ApiBreedServerResponseModel MapServerRequestToResponse( int id, ApiBreedServerRequestModel request) { var response = new ApiBreedServerResponseModel(); response.SetProperties(id, request.Name, request.SpeciesId); return(response); }
public void MapModelToEntity() { var mapper = new DALBreedMapper(); ApiBreedServerRequestModel model = new ApiBreedServerRequestModel(); model.SetProperties("A", 1); Breed response = mapper.MapModelToEntity(1, model); response.Name.Should().Be("A"); response.SpeciesId.Should().Be(1); }
public virtual Breed MapModelToEntity( int id, ApiBreedServerRequestModel model ) { Breed item = new Breed(); item.SetProperties( id, model.Name, model.SpeciesId); return(item); }
public virtual async Task <CreateResponse <ApiBreedServerResponseModel> > Create( ApiBreedServerRequestModel model) { CreateResponse <ApiBreedServerResponseModel> response = ValidationResponseFactory <ApiBreedServerResponseModel> .CreateResponse(await this.BreedModelValidator.ValidateCreateAsync(model)); if (response.Success) { Breed record = this.DalBreedMapper.MapModelToEntity(default(int), model); record = await this.BreedRepository.Create(record); response.SetRecord(this.DalBreedMapper.MapEntityToModel(record)); await this.mediator.Publish(new BreedCreatedNotification(response.Record)); } return(response); }
public virtual async Task <UpdateResponse <ApiBreedServerResponseModel> > Update( int id, ApiBreedServerRequestModel model) { var validationResult = await this.BreedModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { Breed record = this.DalBreedMapper.MapModelToEntity(id, model); await this.BreedRepository.Update(record); record = await this.BreedRepository.Get(id); ApiBreedServerResponseModel apiModel = this.DalBreedMapper.MapEntityToModel(record); await this.mediator.Publish(new BreedUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiBreedServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiBreedServerResponseModel> .UpdateResponse(validationResult)); } }