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

            patch.Replace(x => x.AcceptedAnswerId, model.AcceptedAnswerId);
            patch.Replace(x => x.AnswerCount, model.AnswerCount);
            patch.Replace(x => x.Body, model.Body);
            patch.Replace(x => x.ClosedDate, model.ClosedDate);
            patch.Replace(x => x.CommentCount, model.CommentCount);
            patch.Replace(x => x.CommunityOwnedDate, model.CommunityOwnedDate);
            patch.Replace(x => x.CreationDate, model.CreationDate);
            patch.Replace(x => x.FavoriteCount, model.FavoriteCount);
            patch.Replace(x => x.LastActivityDate, model.LastActivityDate);
            patch.Replace(x => x.LastEditDate, model.LastEditDate);
            patch.Replace(x => x.LastEditorDisplayName, model.LastEditorDisplayName);
            patch.Replace(x => x.LastEditorUserId, model.LastEditorUserId);
            patch.Replace(x => x.OwnerUserId, model.OwnerUserId);
            patch.Replace(x => x.ParentId, model.ParentId);
            patch.Replace(x => x.PostTypeId, model.PostTypeId);
            patch.Replace(x => x.Score, model.Score);
            patch.Replace(x => x.Tag, model.Tag);
            patch.Replace(x => x.Title, model.Title);
            patch.Replace(x => x.ViewCount, model.ViewCount);
            return(patch);
        }
        public virtual ApiPostServerRequestModel MapServerResponseToRequest(
            ApiPostServerResponseModel response)
        {
            var request = new ApiPostServerRequestModel();

            request.SetProperties(
                response.AcceptedAnswerId,
                response.AnswerCount,
                response.Body,
                response.ClosedDate,
                response.CommentCount,
                response.CommunityOwnedDate,
                response.CreationDate,
                response.FavoriteCount,
                response.LastActivityDate,
                response.LastEditDate,
                response.LastEditorDisplayName,
                response.LastEditorUserId,
                response.OwnerUserId,
                response.ParentId,
                response.PostTypeId,
                response.Score,
                response.Tag,
                response.Title,
                response.ViewCount);
            return(request);
        }
示例#3
0
        public void MapModelToEntity()
        {
            var mapper = new DALPostMapper();
            ApiPostServerRequestModel model = new ApiPostServerRequestModel();

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

            response.AcceptedAnswerId.Should().Be(1);
            response.AnswerCount.Should().Be(1);
            response.Body.Should().Be("A");
            response.ClosedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.CommentCount.Should().Be(1);
            response.CommunityOwnedDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.FavoriteCount.Should().Be(1);
            response.LastActivityDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LastEditDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LastEditorDisplayName.Should().Be("A");
            response.LastEditorUserId.Should().Be(1);
            response.OwnerUserId.Should().Be(1);
            response.ParentId.Should().Be(1);
            response.PostTypeId.Should().Be(1);
            response.Score.Should().Be(1);
            response.Tag.Should().Be("A");
            response.Title.Should().Be("A");
            response.ViewCount.Should().Be(1);
        }
示例#4
0
        public virtual Post MapModelToEntity(
            int id,
            ApiPostServerRequestModel model
            )
        {
            Post item = new Post();

            item.SetProperties(
                id,
                model.AcceptedAnswerId,
                model.AnswerCount,
                model.Body,
                model.ClosedDate,
                model.CommentCount,
                model.CommunityOwnedDate,
                model.CreationDate,
                model.FavoriteCount,
                model.LastActivityDate,
                model.LastEditDate,
                model.LastEditorDisplayName,
                model.LastEditorUserId,
                model.OwnerUserId,
                model.ParentId,
                model.PostTypeId,
                model.Score,
                model.Tag,
                model.Title,
                model.ViewCount);
            return(item);
        }
示例#5
0
        public virtual async Task <CreateResponse <ApiPostServerResponseModel> > Create(
            ApiPostServerRequestModel model)
        {
            CreateResponse <ApiPostServerResponseModel> response = ValidationResponseFactory <ApiPostServerResponseModel> .CreateResponse(await this.PostModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Post record = this.DalPostMapper.MapModelToEntity(default(int), model);
                record = await this.PostRepository.Create(record);

                response.SetRecord(this.DalPostMapper.MapEntityToModel(record));
                await this.mediator.Publish(new PostCreatedNotification(response.Record));
            }

            return(response);
        }
示例#6
0
        public virtual async Task <UpdateResponse <ApiPostServerResponseModel> > Update(
            int id,
            ApiPostServerRequestModel model)
        {
            var validationResult = await this.PostModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Post record = this.DalPostMapper.MapModelToEntity(id, model);
                await this.PostRepository.Update(record);

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

                ApiPostServerResponseModel apiModel = this.DalPostMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PostUpdatedNotification(apiModel));

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