Ejemplo n.º 1
0
        public virtual ApiSaleClientRequestModel MapServerResponseToClientRequest(
            ApiSaleServerResponseModel response)
        {
            var request = new ApiSaleClientRequestModel();

            request.SetProperties(
                response.Amount,
                response.FirstName,
                response.LastName,
                response.PaymentTypeId,
                response.PetId,
                response.Phone);
            return(request);
        }
Ejemplo n.º 2
0
        public virtual ApiSaleServerResponseModel MapServerRequestToResponse(
            int id,
            ApiSaleServerRequestModel request)
        {
            var response = new ApiSaleServerResponseModel();

            response.SetProperties(id,
                                   request.Amount,
                                   request.FirstName,
                                   request.LastName,
                                   request.PaymentTypeId,
                                   request.PetId,
                                   request.Phone);
            return(response);
        }
Ejemplo n.º 3
0
        public void MapEntityToModel()
        {
            var  mapper = new DALSaleMapper();
            Sale item   = new Sale();

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

            response.Amount.Should().Be(1m);
            response.FirstName.Should().Be("A");
            response.Id.Should().Be(1);
            response.LastName.Should().Be("A");
            response.PaymentTypeId.Should().Be(1);
            response.PetId.Should().Be(1);
            response.Phone.Should().Be("A");
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public virtual async Task <UpdateResponse <ApiSaleServerResponseModel> > Update(
            int id,
            ApiSaleServerRequestModel model)
        {
            var validationResult = await this.SaleModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Sale record = this.DalSaleMapper.MapModelToEntity(id, model);
                await this.SaleRepository.Update(record);

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

                ApiSaleServerResponseModel apiModel = this.DalSaleMapper.MapEntityToModel(record);
                await this.mediator.Publish(new SaleUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiSaleServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiSaleServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Ejemplo n.º 6
0
 public SaleUpdatedNotification(ApiSaleServerResponseModel record)
 {
     this.Record = record;
 }