Exemple #1
0
        public JsonPatchDocument <ApiPenServerRequestModel> CreatePatch(ApiPenServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiPenServerRequestModel>();

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

            request.SetProperties(
                response.Name);
            return(request);
        }
Exemple #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");
        }
Exemple #4
0
        public virtual ApiPenServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPenServerRequestModel request)
        {
            var response = new ApiPenServerResponseModel();

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

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
Exemple #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);
        }
Exemple #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));
            }
        }