Example #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 ApiPetClientRequestModel MapServerResponseToClientRequest(
            ApiPetServerResponseModel response)
        {
            var request = new ApiPetClientRequestModel();

            request.SetProperties(
                response.AcquiredDate,
                response.BreedId,
                response.Description,
                response.PenId,
                response.Price);
            return(request);
        }
        public virtual ApiPetServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPetServerRequestModel request)
        {
            var response = new ApiPetServerResponseModel();

            response.SetProperties(id,
                                   request.AcquiredDate,
                                   request.BreedId,
                                   request.Description,
                                   request.PenId,
                                   request.Price);
            return(response);
        }
Example #4
0
        public void MapEntityToModel()
        {
            var mapper = new DALPetMapper();
            Pet item   = new Pet();

            item.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A", 1, 1m);
            ApiPetServerResponseModel response = mapper.MapEntityToModel(item);

            response.AcquiredDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.BreedId.Should().Be(1);
            response.Description.Should().Be("A");
            response.Id.Should().Be(1);
            response.PenId.Should().Be(1);
            response.Price.Should().Be(1m);
        }
Example #5
0
        public virtual ApiSaleServerResponseModel MapEntityToModel(
            Sale item)
        {
            var model = new ApiSaleServerResponseModel();

            model.SetProperties(item.Id,
                                item.Amount,
                                item.FirstName,
                                item.LastName,
                                item.PaymentTypeId,
                                item.PetId,
                                item.Phone);
            if (item.PaymentTypeIdNavigation != null)
            {
                var paymentTypeIdModel = new ApiPaymentTypeServerResponseModel();
                paymentTypeIdModel.SetProperties(
                    item.PaymentTypeIdNavigation.Id,
                    item.PaymentTypeIdNavigation.Name);

                model.SetPaymentTypeIdNavigation(paymentTypeIdModel);
            }

            if (item.PetIdNavigation != null)
            {
                var petIdModel = new ApiPetServerResponseModel();
                petIdModel.SetProperties(
                    item.PetIdNavigation.Id,
                    item.PetIdNavigation.AcquiredDate,
                    item.PetIdNavigation.BreedId,
                    item.PetIdNavigation.Description,
                    item.PetIdNavigation.PenId,
                    item.PetIdNavigation.Price);

                model.SetPetIdNavigation(petIdModel);
            }

            return(model);
        }
Example #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));
            }
        }
Example #7
0
 public PetUpdatedNotification(ApiPetServerResponseModel record)
 {
     this.Record = record;
 }
Example #8
0
 public void SetPetIdNavigation(ApiPetServerResponseModel value)
 {
     this.PetIdNavigation = value;
 }