Exemple #1
0
        public virtual ApiCommentClientRequestModel MapServerResponseToClientRequest(
            ApiCommentServerResponseModel response)
        {
            var request = new ApiCommentClientRequestModel();

            request.SetProperties(
                response.CreationDate,
                response.PostId,
                response.Score,
                response.Text,
                response.UserId);
            return(request);
        }
Exemple #2
0
        public virtual ApiCommentServerResponseModel MapServerRequestToResponse(
            int id,
            ApiCommentServerRequestModel request)
        {
            var response = new ApiCommentServerResponseModel();

            response.SetProperties(id,
                                   request.CreationDate,
                                   request.PostId,
                                   request.Score,
                                   request.Text,
                                   request.UserId);
            return(response);
        }
        public void MapEntityToModel()
        {
            var     mapper = new DALCommentMapper();
            Comment item   = new Comment();

            item.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1);
            ApiCommentServerResponseModel response = mapper.MapEntityToModel(item);

            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Id.Should().Be(1);
            response.PostId.Should().Be(1);
            response.Score.Should().Be(1);
            response.Text.Should().Be("A");
            response.UserId.Should().Be(1);
        }
Exemple #4
0
        public virtual async Task <UpdateResponse <ApiCommentServerResponseModel> > Update(
            int id,
            ApiCommentServerRequestModel model)
        {
            var validationResult = await this.CommentModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Comment record = this.DalCommentMapper.MapModelToEntity(id, model);
                await this.CommentRepository.Update(record);

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

                ApiCommentServerResponseModel apiModel = this.DalCommentMapper.MapEntityToModel(record);
                await this.mediator.Publish(new CommentUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiCommentServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiCommentServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Exemple #5
0
        public virtual ApiCommentServerResponseModel MapEntityToModel(
            Comment item)
        {
            var model = new ApiCommentServerResponseModel();

            model.SetProperties(item.Id,
                                item.CreationDate,
                                item.PostId,
                                item.Score,
                                item.Text,
                                item.UserId);
            if (item.PostIdNavigation != null)
            {
                var postIdModel = new ApiPostServerResponseModel();
                postIdModel.SetProperties(
                    item.PostIdNavigation.Id,
                    item.PostIdNavigation.AcceptedAnswerId,
                    item.PostIdNavigation.AnswerCount,
                    item.PostIdNavigation.Body,
                    item.PostIdNavigation.ClosedDate,
                    item.PostIdNavigation.CommentCount,
                    item.PostIdNavigation.CommunityOwnedDate,
                    item.PostIdNavigation.CreationDate,
                    item.PostIdNavigation.FavoriteCount,
                    item.PostIdNavigation.LastActivityDate,
                    item.PostIdNavigation.LastEditDate,
                    item.PostIdNavigation.LastEditorDisplayName,
                    item.PostIdNavigation.LastEditorUserId,
                    item.PostIdNavigation.OwnerUserId,
                    item.PostIdNavigation.ParentId,
                    item.PostIdNavigation.PostTypeId,
                    item.PostIdNavigation.Score,
                    item.PostIdNavigation.Tag,
                    item.PostIdNavigation.Title,
                    item.PostIdNavigation.ViewCount);

                model.SetPostIdNavigation(postIdModel);
            }

            if (item.UserIdNavigation != null)
            {
                var userIdModel = new ApiUserServerResponseModel();
                userIdModel.SetProperties(
                    item.UserIdNavigation.Id,
                    item.UserIdNavigation.AboutMe,
                    item.UserIdNavigation.AccountId,
                    item.UserIdNavigation.Age,
                    item.UserIdNavigation.CreationDate,
                    item.UserIdNavigation.DisplayName,
                    item.UserIdNavigation.DownVote,
                    item.UserIdNavigation.EmailHash,
                    item.UserIdNavigation.LastAccessDate,
                    item.UserIdNavigation.Location,
                    item.UserIdNavigation.Reputation,
                    item.UserIdNavigation.UpVote,
                    item.UserIdNavigation.View,
                    item.UserIdNavigation.WebsiteUrl);

                model.SetUserIdNavigation(userIdModel);
            }

            return(model);
        }
Exemple #6
0
 public CommentUpdatedNotification(ApiCommentServerResponseModel record)
 {
     this.Record = record;
 }