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

            patch.Replace(x => x.Comment, model.Comment);
            patch.Replace(x => x.CreationDate, model.CreationDate);
            patch.Replace(x => x.PostHistoryTypeId, model.PostHistoryTypeId);
            patch.Replace(x => x.PostId, model.PostId);
            patch.Replace(x => x.RevisionGUID, model.RevisionGUID);
            patch.Replace(x => x.Text, model.Text);
            patch.Replace(x => x.UserDisplayName, model.UserDisplayName);
            patch.Replace(x => x.UserId, model.UserId);
            return(patch);
        }
Example #2
0
        public virtual async Task <CreateResponse <ApiPostHistoryServerResponseModel> > Create(
            ApiPostHistoryServerRequestModel model)
        {
            CreateResponse <ApiPostHistoryServerResponseModel> response = ValidationResponseFactory <ApiPostHistoryServerResponseModel> .CreateResponse(await this.PostHistoryModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                PostHistory record = this.DalPostHistoryMapper.MapModelToEntity(default(int), model);
                record = await this.PostHistoryRepository.Create(record);

                response.SetRecord(this.DalPostHistoryMapper.MapEntityToModel(record));
                await this.mediator.Publish(new PostHistoryCreatedNotification(response.Record));
            }

            return(response);
        }
        public virtual ApiPostHistoryServerRequestModel MapServerResponseToRequest(
            ApiPostHistoryServerResponseModel response)
        {
            var request = new ApiPostHistoryServerRequestModel();

            request.SetProperties(
                response.Comment,
                response.CreationDate,
                response.PostHistoryTypeId,
                response.PostId,
                response.RevisionGUID,
                response.Text,
                response.UserDisplayName,
                response.UserId);
            return(request);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALPostHistoryMapper();
            ApiPostHistoryServerRequestModel model = new ApiPostHistoryServerRequestModel();

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

            response.Comment.Should().Be("A");
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.PostHistoryTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RevisionGUID.Should().Be("A");
            response.Text.Should().Be("A");
            response.UserDisplayName.Should().Be("A");
            response.UserId.Should().Be(1);
        }
        public virtual PostHistory MapModelToEntity(
            int id,
            ApiPostHistoryServerRequestModel model
            )
        {
            PostHistory item = new PostHistory();

            item.SetProperties(
                id,
                model.Comment,
                model.CreationDate,
                model.PostHistoryTypeId,
                model.PostId,
                model.RevisionGUID,
                model.Text,
                model.UserDisplayName,
                model.UserId);
            return(item);
        }
Example #6
0
        public virtual async Task <UpdateResponse <ApiPostHistoryServerResponseModel> > Update(
            int id,
            ApiPostHistoryServerRequestModel model)
        {
            var validationResult = await this.PostHistoryModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                PostHistory record = this.DalPostHistoryMapper.MapModelToEntity(id, model);
                await this.PostHistoryRepository.Update(record);

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

                ApiPostHistoryServerResponseModel apiModel = this.DalPostHistoryMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PostHistoryUpdatedNotification(apiModel));

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