Beispiel #1
0
        public virtual ApiPetServerResponseModel MapEntityToModel(
            Pet item)
        {
            var model = new ApiPetServerResponseModel();

            model.SetProperties(item.Id,
                                item.AcquiredDate,
                                item.BreedId,
                                item.Description,
                                item.PenId,
                                item.Price);
            if (item.BreedIdNavigation != null)
            {
                var breedIdModel = new ApiBreedServerResponseModel();
                breedIdModel.SetProperties(
                    item.BreedIdNavigation.Id,
                    item.BreedIdNavigation.Name,
                    item.BreedIdNavigation.SpeciesId);

                model.SetBreedIdNavigation(breedIdModel);
            }

            if (item.PenIdNavigation != null)
            {
                var penIdModel = new ApiPenServerResponseModel();
                penIdModel.SetProperties(
                    item.PenIdNavigation.Id,
                    item.PenIdNavigation.Name);

                model.SetPenIdNavigation(penIdModel);
            }

            return(model);
        }
        public virtual ApiBreedClientRequestModel MapServerResponseToClientRequest(
            ApiBreedServerResponseModel response)
        {
            var request = new ApiBreedClientRequestModel();

            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);
        }
Beispiel #4
0
        public void MapEntityToModel()
        {
            var   mapper = new DALBreedMapper();
            Breed item   = new Breed();

            item.SetProperties(1, "A", 1);
            ApiBreedServerResponseModel response = mapper.MapEntityToModel(item);

            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
            response.SpeciesId.Should().Be(1);
        }
Beispiel #5
0
        public virtual ApiBreedServerResponseModel MapEntityToModel(
            Breed item)
        {
            var model = new ApiBreedServerResponseModel();

            model.SetProperties(item.Id,
                                item.Name,
                                item.SpeciesId);
            if (item.SpeciesIdNavigation != null)
            {
                var speciesIdModel = new ApiSpeciesServerResponseModel();
                speciesIdModel.SetProperties(
                    item.SpeciesIdNavigation.Id,
                    item.SpeciesIdNavigation.Name);

                model.SetSpeciesIdNavigation(speciesIdModel);
            }

            return(model);
        }
Beispiel #6
0
        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));
            }
        }
 public void SetBreedIdNavigation(ApiBreedServerResponseModel value)
 {
     this.BreedIdNavigation = value;
 }
Beispiel #8
0
 public BreedUpdatedNotification(ApiBreedServerResponseModel record)
 {
     this.Record = record;
 }