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

            patch.Replace(x => x.Active, model.Active);
            patch.Replace(x => x.Description, model.Description);
            patch.Replace(x => x.Name, model.Name);
            patch.Replace(x => x.Price, model.Price);
            patch.Replace(x => x.Quantity, model.Quantity);
            return(patch);
        }
        public virtual ApiProductServerRequestModel MapServerResponseToRequest(
            ApiProductServerResponseModel response)
        {
            var request = new ApiProductServerRequestModel();

            request.SetProperties(
                response.Active,
                response.Description,
                response.Name,
                response.Price,
                response.Quantity);
            return(request);
        }
        public virtual ApiProductServerResponseModel MapServerRequestToResponse(
            int id,
            ApiProductServerRequestModel request)
        {
            var response = new ApiProductServerResponseModel();

            response.SetProperties(id,
                                   request.Active,
                                   request.Description,
                                   request.Name,
                                   request.Price,
                                   request.Quantity);
            return(response);
        }
Ejemplo n.º 4
0
        public void MapModelToEntity()
        {
            var mapper = new DALProductMapper();
            ApiProductServerRequestModel model = new ApiProductServerRequestModel();

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

            response.Active.Should().Be(true);
            response.Description.Should().Be("A");
            response.Name.Should().Be("A");
            response.Price.Should().Be(1m);
            response.Quantity.Should().Be(1);
        }
Ejemplo n.º 5
0
        public virtual Product MapModelToEntity(
            int id,
            ApiProductServerRequestModel model
            )
        {
            Product item = new Product();

            item.SetProperties(
                id,
                model.Active,
                model.Description,
                model.Name,
                model.Price,
                model.Quantity);
            return(item);
        }
Ejemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiProductServerResponseModel> > Create(
            ApiProductServerRequestModel model)
        {
            CreateResponse <ApiProductServerResponseModel> response = ValidationResponseFactory <ApiProductServerResponseModel> .CreateResponse(await this.ProductModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Product record = this.DalProductMapper.MapModelToEntity(default(int), model);
                record = await this.ProductRepository.Create(record);

                response.SetRecord(this.DalProductMapper.MapEntityToModel(record));
                await this.mediator.Publish(new ProductCreatedNotification(response.Record));
            }

            return(response);
        }
Ejemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiProductServerResponseModel> > Update(
            int id,
            ApiProductServerRequestModel model)
        {
            var validationResult = await this.ProductModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Product record = this.DalProductMapper.MapModelToEntity(id, model);
                await this.ProductRepository.Update(record);

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

                ApiProductServerResponseModel apiModel = this.DalProductMapper.MapEntityToModel(record);
                await this.mediator.Publish(new ProductUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiProductServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiProductServerResponseModel> .UpdateResponse(validationResult));
            }
        }