예제 #1
0
        public JsonPatchDocument <ApiVoteTypeServerRequestModel> CreatePatch(ApiVoteTypeServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiVoteTypeServerRequestModel>();

            patch.Replace(x => x.Name, model.Name);
            return(patch);
        }
예제 #2
0
        public virtual ApiVoteTypeServerRequestModel MapServerResponseToRequest(
            ApiVoteTypeServerResponseModel response)
        {
            var request = new ApiVoteTypeServerRequestModel();

            request.SetProperties(
                response.Name);
            return(request);
        }
예제 #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALVoteTypeMapper();
            ApiVoteTypeServerRequestModel model = new ApiVoteTypeServerRequestModel();

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

            response.Name.Should().Be("A");
        }
예제 #4
0
        public virtual ApiVoteTypeServerResponseModel MapServerRequestToResponse(
            int id,
            ApiVoteTypeServerRequestModel request)
        {
            var response = new ApiVoteTypeServerResponseModel();

            response.SetProperties(id,
                                   request.Name);
            return(response);
        }
예제 #5
0
        public virtual VoteType MapModelToEntity(
            int id,
            ApiVoteTypeServerRequestModel model
            )
        {
            VoteType item = new VoteType();

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
예제 #6
0
        public virtual async Task <CreateResponse <ApiVoteTypeServerResponseModel> > Create(
            ApiVoteTypeServerRequestModel model)
        {
            CreateResponse <ApiVoteTypeServerResponseModel> response = ValidationResponseFactory <ApiVoteTypeServerResponseModel> .CreateResponse(await this.VoteTypeModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                VoteType record = this.DalVoteTypeMapper.MapModelToEntity(default(int), model);
                record = await this.VoteTypeRepository.Create(record);

                response.SetRecord(this.DalVoteTypeMapper.MapEntityToModel(record));
                await this.mediator.Publish(new VoteTypeCreatedNotification(response.Record));
            }

            return(response);
        }
예제 #7
0
        public virtual async Task <UpdateResponse <ApiVoteTypeServerResponseModel> > Update(
            int id,
            ApiVoteTypeServerRequestModel model)
        {
            var validationResult = await this.VoteTypeModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                VoteType record = this.DalVoteTypeMapper.MapModelToEntity(id, model);
                await this.VoteTypeRepository.Update(record);

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

                ApiVoteTypeServerResponseModel apiModel = this.DalVoteTypeMapper.MapEntityToModel(record);
                await this.mediator.Publish(new VoteTypeUpdatedNotification(apiModel));

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