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

            patch.Replace(x => x.NextChainId, model.NextChainId);
            patch.Replace(x => x.PreviousChainId, model.PreviousChainId);
            return(patch);
        }
        public virtual ApiClaspServerRequestModel MapServerResponseToRequest(
            ApiClaspServerResponseModel response)
        {
            var request = new ApiClaspServerRequestModel();

            request.SetProperties(
                response.NextChainId,
                response.PreviousChainId);
            return(request);
        }
Ejemplo n.º 3
0
        public void MapModelToEntity()
        {
            var mapper = new DALClaspMapper();
            ApiClaspServerRequestModel model = new ApiClaspServerRequestModel();

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

            response.NextChainId.Should().Be(1);
            response.PreviousChainId.Should().Be(1);
        }
        public virtual ApiClaspServerResponseModel MapServerRequestToResponse(
            int id,
            ApiClaspServerRequestModel request)
        {
            var response = new ApiClaspServerResponseModel();

            response.SetProperties(id,
                                   request.NextChainId,
                                   request.PreviousChainId);
            return(response);
        }
Ejemplo n.º 5
0
        public virtual Clasp MapModelToEntity(
            int id,
            ApiClaspServerRequestModel model
            )
        {
            Clasp item = new Clasp();

            item.SetProperties(
                id,
                model.NextChainId,
                model.PreviousChainId);
            return(item);
        }
Ejemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiClaspServerResponseModel> > Create(
            ApiClaspServerRequestModel model)
        {
            CreateResponse <ApiClaspServerResponseModel> response = ValidationResponseFactory <ApiClaspServerResponseModel> .CreateResponse(await this.ClaspModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Clasp record = this.DalClaspMapper.MapModelToEntity(default(int), model);
                record = await this.ClaspRepository.Create(record);

                response.SetRecord(this.DalClaspMapper.MapEntityToModel(record));
                await this.mediator.Publish(new ClaspCreatedNotification(response.Record));
            }

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

            if (validationResult.IsValid)
            {
                Clasp record = this.DalClaspMapper.MapModelToEntity(id, model);
                await this.ClaspRepository.Update(record);

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

                ApiClaspServerResponseModel apiModel = this.DalClaspMapper.MapEntityToModel(record);
                await this.mediator.Publish(new ClaspUpdatedNotification(apiModel));

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