public JsonPatchDocument <ApiSaleServerRequestModel> CreatePatch(ApiSaleServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiSaleServerRequestModel>();

            patch.Replace(x => x.Amount, model.Amount);
            patch.Replace(x => x.FirstName, model.FirstName);
            patch.Replace(x => x.LastName, model.LastName);
            patch.Replace(x => x.PaymentTypeId, model.PaymentTypeId);
            patch.Replace(x => x.PetId, model.PetId);
            patch.Replace(x => x.Phone, model.Phone);
            return(patch);
        }
        public virtual ApiSaleServerRequestModel MapServerResponseToRequest(
            ApiSaleServerResponseModel response)
        {
            var request = new ApiSaleServerRequestModel();

            request.SetProperties(
                response.Amount,
                response.FirstName,
                response.LastName,
                response.PaymentTypeId,
                response.PetId,
                response.Phone);
            return(request);
        }
Example #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALSaleMapper();
            ApiSaleServerRequestModel model = new ApiSaleServerRequestModel();

            model.SetProperties(1m, "A", "A", 1, 1, "A");
            Sale response = mapper.MapModelToEntity(1, model);

            response.Amount.Should().Be(1m);
            response.FirstName.Should().Be("A");
            response.LastName.Should().Be("A");
            response.PaymentTypeId.Should().Be(1);
            response.PetId.Should().Be(1);
            response.Phone.Should().Be("A");
        }
        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);
        }
Example #5
0
        public virtual async Task <CreateResponse <ApiSaleServerResponseModel> > Create(
            ApiSaleServerRequestModel model)
        {
            CreateResponse <ApiSaleServerResponseModel> response = ValidationResponseFactory <ApiSaleServerResponseModel> .CreateResponse(await this.SaleModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Sale record = this.DalSaleMapper.MapModelToEntity(default(int), model);
                record = await this.SaleRepository.Create(record);

                response.SetRecord(this.DalSaleMapper.MapEntityToModel(record));
                await this.mediator.Publish(new SaleCreatedNotification(response.Record));
            }

            return(response);
        }
Example #6
0
        public virtual Sale MapModelToEntity(
            int id,
            ApiSaleServerRequestModel model
            )
        {
            Sale item = new Sale();

            item.SetProperties(
                id,
                model.Amount,
                model.FirstName,
                model.LastName,
                model.PaymentTypeId,
                model.PetId,
                model.Phone);
            return(item);
        }
Example #7
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));
            }
        }