Ejemplo n.º 1
0
        public JsonPatchDocument <ApiSaleServerRequestModel> CreatePatch(ApiSaleServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiSaleServerRequestModel>();

            patch.Replace(x => x.CustomerId, model.CustomerId);
            patch.Replace(x => x.Date, model.Date);
            return(patch);
        }
Ejemplo n.º 2
0
        public virtual ApiSaleServerRequestModel MapServerResponseToRequest(
            ApiSaleServerResponseModel response)
        {
            var request = new ApiSaleServerRequestModel();

            request.SetProperties(
                response.CustomerId,
                response.Date);
            return(request);
        }
Ejemplo n.º 3
0
        public virtual ApiSaleServerResponseModel MapServerRequestToResponse(
            int id,
            ApiSaleServerRequestModel request)
        {
            var response = new ApiSaleServerResponseModel();

            response.SetProperties(id,
                                   request.CustomerId,
                                   request.Date);
            return(response);
        }
Ejemplo n.º 4
0
        public void MapModelToEntity()
        {
            var mapper = new DALSaleMapper();
            ApiSaleServerRequestModel model = new ApiSaleServerRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"));
            Sale response = mapper.MapModelToEntity(1, model);

            response.CustomerId.Should().Be(1);
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
        }
Ejemplo n.º 5
0
        public virtual Sale MapModelToEntity(
            int id,
            ApiSaleServerRequestModel model
            )
        {
            Sale item = new Sale();

            item.SetProperties(
                id,
                model.CustomerId,
                model.Date);
            return(item);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 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));
            }
        }