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

            patch.Replace(x => x.SelfReferenceId, model.SelfReferenceId);
            patch.Replace(x => x.SelfReferenceId2, model.SelfReferenceId2);
            return(patch);
        }
        public virtual ApiSelfReferenceServerRequestModel MapServerResponseToRequest(
            ApiSelfReferenceServerResponseModel response)
        {
            var request = new ApiSelfReferenceServerRequestModel();

            request.SetProperties(
                response.SelfReferenceId,
                response.SelfReferenceId2);
            return(request);
        }
Beispiel #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALSelfReferenceMapper();
            ApiSelfReferenceServerRequestModel model = new ApiSelfReferenceServerRequestModel();

            model.SetProperties(1, 1);
            SelfReference response = mapper.MapModelToEntity(1, model);

            response.SelfReferenceId.Should().Be(1);
            response.SelfReferenceId2.Should().Be(1);
        }
Beispiel #4
0
        public virtual SelfReference MapModelToEntity(
            int id,
            ApiSelfReferenceServerRequestModel model
            )
        {
            SelfReference item = new SelfReference();

            item.SetProperties(
                id,
                model.SelfReferenceId,
                model.SelfReferenceId2);
            return(item);
        }
Beispiel #5
0
        public virtual async Task <CreateResponse <ApiSelfReferenceServerResponseModel> > Create(
            ApiSelfReferenceServerRequestModel model)
        {
            CreateResponse <ApiSelfReferenceServerResponseModel> response = ValidationResponseFactory <ApiSelfReferenceServerResponseModel> .CreateResponse(await this.SelfReferenceModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                SelfReference record = this.DalSelfReferenceMapper.MapModelToEntity(default(int), model);
                record = await this.SelfReferenceRepository.Create(record);

                response.SetRecord(this.DalSelfReferenceMapper.MapEntityToModel(record));
                await this.mediator.Publish(new SelfReferenceCreatedNotification(response.Record));
            }

            return(response);
        }
Beispiel #6
0
        public virtual async Task <UpdateResponse <ApiSelfReferenceServerResponseModel> > Update(
            int id,
            ApiSelfReferenceServerRequestModel model)
        {
            var validationResult = await this.SelfReferenceModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                SelfReference record = this.DalSelfReferenceMapper.MapModelToEntity(id, model);
                await this.SelfReferenceRepository.Update(record);

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

                ApiSelfReferenceServerResponseModel apiModel = this.DalSelfReferenceMapper.MapEntityToModel(record);
                await this.mediator.Publish(new SelfReferenceUpdatedNotification(apiModel));

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