Example #1
0
        public virtual ApiPostLinkClientRequestModel MapServerResponseToClientRequest(
            ApiPostLinkServerResponseModel response)
        {
            var request = new ApiPostLinkClientRequestModel();

            request.SetProperties(
                response.CreationDate,
                response.LinkTypeId,
                response.PostId,
                response.RelatedPostId);
            return(request);
        }
Example #2
0
        public virtual ApiPostLinkServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPostLinkServerRequestModel request)
        {
            var response = new ApiPostLinkServerResponseModel();

            response.SetProperties(id,
                                   request.CreationDate,
                                   request.LinkTypeId,
                                   request.PostId,
                                   request.RelatedPostId);
            return(response);
        }
Example #3
0
        public void MapEntityToModel()
        {
            var      mapper = new DALPostLinkMapper();
            PostLink item   = new PostLink();

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

            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Id.Should().Be(1);
            response.LinkTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RelatedPostId.Should().Be(1);
        }
Example #4
0
        public virtual async Task <UpdateResponse <ApiPostLinkServerResponseModel> > Update(
            int id,
            ApiPostLinkServerRequestModel model)
        {
            var validationResult = await this.PostLinkModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                PostLink record = this.DalPostLinkMapper.MapModelToEntity(id, model);
                await this.PostLinkRepository.Update(record);

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

                ApiPostLinkServerResponseModel apiModel = this.DalPostLinkMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PostLinkUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiPostLinkServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiPostLinkServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Example #5
0
 public PostLinkUpdatedNotification(ApiPostLinkServerResponseModel record)
 {
     this.Record = record;
 }
Example #6
0
        public virtual ApiPostLinkServerResponseModel MapEntityToModel(
            PostLink item)
        {
            var model = new ApiPostLinkServerResponseModel();

            model.SetProperties(item.Id,
                                item.CreationDate,
                                item.LinkTypeId,
                                item.PostId,
                                item.RelatedPostId);
            if (item.LinkTypeIdNavigation != null)
            {
                var linkTypeIdModel = new ApiLinkTypeServerResponseModel();
                linkTypeIdModel.SetProperties(
                    item.LinkTypeIdNavigation.Id,
                    item.LinkTypeIdNavigation.RwType);

                model.SetLinkTypeIdNavigation(linkTypeIdModel);
            }

            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.RelatedPostIdNavigation != null)
            {
                var relatedPostIdModel = new ApiPostServerResponseModel();
                relatedPostIdModel.SetProperties(
                    item.RelatedPostIdNavigation.Id,
                    item.RelatedPostIdNavigation.AcceptedAnswerId,
                    item.RelatedPostIdNavigation.AnswerCount,
                    item.RelatedPostIdNavigation.Body,
                    item.RelatedPostIdNavigation.ClosedDate,
                    item.RelatedPostIdNavigation.CommentCount,
                    item.RelatedPostIdNavigation.CommunityOwnedDate,
                    item.RelatedPostIdNavigation.CreationDate,
                    item.RelatedPostIdNavigation.FavoriteCount,
                    item.RelatedPostIdNavigation.LastActivityDate,
                    item.RelatedPostIdNavigation.LastEditDate,
                    item.RelatedPostIdNavigation.LastEditorDisplayName,
                    item.RelatedPostIdNavigation.LastEditorUserId,
                    item.RelatedPostIdNavigation.OwnerUserId,
                    item.RelatedPostIdNavigation.ParentId,
                    item.RelatedPostIdNavigation.PostTypeId,
                    item.RelatedPostIdNavigation.Score,
                    item.RelatedPostIdNavigation.Tag,
                    item.RelatedPostIdNavigation.Title,
                    item.RelatedPostIdNavigation.ViewCount);

                model.SetRelatedPostIdNavigation(relatedPostIdModel);
            }

            return(model);
        }