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

            patch.Replace(x => x.Name, model.Name);
            return(patch);
        }
Exemplo n.º 2
0
        public virtual ApiPenServerRequestModel MapServerResponseToRequest(
            ApiPenServerResponseModel response)
        {
            var request = new ApiPenServerRequestModel();

            request.SetProperties(
                response.Name);
            return(request);
        }
Exemplo n.º 3
0
        public void MapModelToEntity()
        {
            var mapper = new DALPenMapper();
            ApiPenServerRequestModel model = new ApiPenServerRequestModel();

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

            response.Name.Should().Be("A");
        }
Exemplo n.º 4
0
        public virtual ApiPenServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPenServerRequestModel request)
        {
            var response = new ApiPenServerResponseModel();

            response.SetProperties(id,
                                   request.Name);
            return(response);
        }
Exemplo n.º 5
0
        public virtual Pen MapModelToEntity(
            int id,
            ApiPenServerRequestModel model
            )
        {
            Pen item = new Pen();

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
Exemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiPenServerResponseModel> > Create(
            ApiPenServerRequestModel model)
        {
            CreateResponse <ApiPenServerResponseModel> response = ValidationResponseFactory <ApiPenServerResponseModel> .CreateResponse(await this.PenModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Pen record = this.DalPenMapper.MapModelToEntity(default(int), model);
                record = await this.PenRepository.Create(record);

                response.SetRecord(this.DalPenMapper.MapEntityToModel(record));
                await this.mediator.Publish(new PenCreatedNotification(response.Record));
            }

            return(response);
        }
Exemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiPenServerResponseModel> > Update(
            int id,
            ApiPenServerRequestModel model)
        {
            var validationResult = await this.PenModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Pen record = this.DalPenMapper.MapModelToEntity(id, model);
                await this.PenRepository.Update(record);

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

                ApiPenServerResponseModel apiModel = this.DalPenMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PenUpdatedNotification(apiModel));

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