Ejemplo n.º 1
0
        public virtual ApiSaleServerResponseModel MapEntityToModel(
            Sale item)
        {
            var model = new ApiSaleServerResponseModel();

            model.SetProperties(item.Id,
                                item.Amount,
                                item.CutomerId,
                                item.Note,
                                item.PetId,
                                item.SaleDate,
                                item.SalesPersonId);
            if (item.PetIdNavigation != null)
            {
                var petIdModel = new ApiPetServerResponseModel();
                petIdModel.SetProperties(
                    item.PetIdNavigation.Id,
                    item.PetIdNavigation.BreedId,
                    item.PetIdNavigation.ClientId,
                    item.PetIdNavigation.Name,
                    item.PetIdNavigation.Weight);

                model.SetPetIdNavigation(petIdModel);
            }

            return(model);
        }
Ejemplo n.º 2
0
        public virtual ApiPetClientRequestModel MapServerResponseToClientRequest(
            ApiPetServerResponseModel response)
        {
            var request = new ApiPetClientRequestModel();

            request.SetProperties(
                response.BreedId,
                response.ClientId,
                response.Name,
                response.Weight);
            return(request);
        }
Ejemplo n.º 3
0
        public virtual ApiPetServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPetServerRequestModel request)
        {
            var response = new ApiPetServerResponseModel();

            response.SetProperties(id,
                                   request.BreedId,
                                   request.ClientId,
                                   request.Name,
                                   request.Weight);
            return(response);
        }
Ejemplo n.º 4
0
        public void MapEntityToModel()
        {
            var mapper = new DALPetMapper();
            Pet item   = new Pet();

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

            response.BreedId.Should().Be(1);
            response.ClientId.Should().Be(1);
            response.Id.Should().Be(1);
            response.Name.Should().Be("A");
            response.Weight.Should().Be(1);
        }
Ejemplo n.º 5
0
        public virtual ApiPetServerResponseModel MapEntityToModel(
            Pet item)
        {
            var model = new ApiPetServerResponseModel();

            model.SetProperties(item.Id,
                                item.BreedId,
                                item.ClientId,
                                item.Name,
                                item.Weight);
            if (item.BreedIdNavigation != null)
            {
                var breedIdModel = new ApiBreedServerResponseModel();
                breedIdModel.SetProperties(
                    item.BreedIdNavigation.Id,
                    item.BreedIdNavigation.Name,
                    item.BreedIdNavigation.SpeciesId);

                model.SetBreedIdNavigation(breedIdModel);
            }

            return(model);
        }
Ejemplo n.º 6
0
        public virtual async Task <UpdateResponse <ApiPetServerResponseModel> > Update(
            int id,
            ApiPetServerRequestModel model)
        {
            var validationResult = await this.PetModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Pet record = this.DalPetMapper.MapModelToEntity(id, model);
                await this.PetRepository.Update(record);

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

                ApiPetServerResponseModel apiModel = this.DalPetMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PetUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiPetServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiPetServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Ejemplo n.º 7
0
 public void SetPetIdNavigation(ApiPetServerResponseModel value)
 {
     this.PetIdNavigation = value;
 }
Ejemplo n.º 8
0
 public PetUpdatedNotification(ApiPetServerResponseModel record)
 {
     this.Record = record;
 }