Esempio 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);
        }
        public virtual ApiSaleClientRequestModel MapServerResponseToClientRequest(
            ApiSaleServerResponseModel response)
        {
            var request = new ApiSaleClientRequestModel();

            request.SetProperties(
                response.Amount,
                response.CutomerId,
                response.Note,
                response.PetId,
                response.SaleDate,
                response.SalesPersonId);
            return(request);
        }
        public virtual ApiSaleServerResponseModel MapServerRequestToResponse(
            int id,
            ApiSaleServerRequestModel request)
        {
            var response = new ApiSaleServerResponseModel();

            response.SetProperties(id,
                                   request.Amount,
                                   request.CutomerId,
                                   request.Note,
                                   request.PetId,
                                   request.SaleDate,
                                   request.SalesPersonId);
            return(response);
        }
Esempio n. 4
0
        public void MapEntityToModel()
        {
            var  mapper = new DALSaleMapper();
            Sale item   = new Sale();

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

            response.Amount.Should().Be(1m);
            response.CutomerId.Should().Be(1);
            response.Id.Should().Be(1);
            response.Note.Should().Be("A");
            response.PetId.Should().Be(1);
            response.SaleDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.SalesPersonId.Should().Be(1);
        }
Esempio 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));
            }
        }
Esempio n. 6
0
 public SaleUpdatedNotification(ApiSaleServerResponseModel record)
 {
     this.Record = record;
 }