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

            patch.Replace(x => x.BountyAmount, model.BountyAmount);
            patch.Replace(x => x.CreationDate, model.CreationDate);
            patch.Replace(x => x.PostId, model.PostId);
            patch.Replace(x => x.UserId, model.UserId);
            patch.Replace(x => x.VoteTypeId, model.VoteTypeId);
            return(patch);
        }
Example #2
0
        public virtual ApiVoteServerRequestModel MapServerResponseToRequest(
            ApiVoteServerResponseModel response)
        {
            var request = new ApiVoteServerRequestModel();

            request.SetProperties(
                response.BountyAmount,
                response.CreationDate,
                response.PostId,
                response.UserId,
                response.VoteTypeId);
            return(request);
        }
Example #3
0
        public virtual ApiVoteServerResponseModel MapServerRequestToResponse(
            int id,
            ApiVoteServerRequestModel request)
        {
            var response = new ApiVoteServerResponseModel();

            response.SetProperties(id,
                                   request.BountyAmount,
                                   request.CreationDate,
                                   request.PostId,
                                   request.UserId,
                                   request.VoteTypeId);
            return(response);
        }
Example #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALVoteMapper();
            ApiVoteServerRequestModel model = new ApiVoteServerRequestModel();

            model.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, 1);
            Vote response = mapper.MapModelToEntity(1, model);

            response.BountyAmount.Should().Be(1);
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostId.Should().Be(1);
            response.UserId.Should().Be(1);
            response.VoteTypeId.Should().Be(1);
        }
Example #5
0
        public virtual Vote MapModelToEntity(
            int id,
            ApiVoteServerRequestModel model
            )
        {
            Vote item = new Vote();

            item.SetProperties(
                id,
                model.BountyAmount,
                model.CreationDate,
                model.PostId,
                model.UserId,
                model.VoteTypeId);
            return(item);
        }
Example #6
0
        public virtual async Task <CreateResponse <ApiVoteServerResponseModel> > Create(
            ApiVoteServerRequestModel model)
        {
            CreateResponse <ApiVoteServerResponseModel> response = ValidationResponseFactory <ApiVoteServerResponseModel> .CreateResponse(await this.VoteModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Vote record = this.DalVoteMapper.MapModelToEntity(default(int), model);
                record = await this.VoteRepository.Create(record);

                response.SetRecord(this.DalVoteMapper.MapEntityToModel(record));
                await this.mediator.Publish(new VoteCreatedNotification(response.Record));
            }

            return(response);
        }
Example #7
0
        public virtual async Task <UpdateResponse <ApiVoteServerResponseModel> > Update(
            int id,
            ApiVoteServerRequestModel model)
        {
            var validationResult = await this.VoteModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Vote record = this.DalVoteMapper.MapModelToEntity(id, model);
                await this.VoteRepository.Update(record);

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

                ApiVoteServerResponseModel apiModel = this.DalVoteMapper.MapEntityToModel(record);
                await this.mediator.Publish(new VoteUpdatedNotification(apiModel));

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