protected void btnPost_Click(object sender, EventArgs e)
        {
            string title   = txtTitle.Text.Trim();
            string content = edContent.Content.Trim();

            if (title.Length > 0 && content.Length > 0)
            {
                TopicInfoDto topic = new TopicInfoDto();
                topic.IssuedById = CurrentUserContext.User.UserId;
                topic.Title      = title;

                PostInfoDto post = new PostInfoDto();
                post.Content    = content;
                post.IssuedById = CurrentUserContext.User.UserId;

                IFacadeUpdateResult <TopicData> result = SaveCreatedTopic(topic, post);
                if (result.IsSuccessful)
                {
                    Response.Redirect(GetUrl(TopicList.PageUrl), true);
                }
                else
                {
                    ProcUpdateResult(result.ValidationResult, result.Exception);
                }
            }
        }
Esempio n. 2
0
        public PostInfoDto GetByID(int pid)
        {
            var         ss          = dbService.GetDbConnection().GetAll <Posts>().Where(m => m.Id == 5);
            PostInfoDto postInfoDto = new PostInfoDto();

            postInfoDto.post       = GetPostsInclude(dbService.Query <Posts>().Where(m => m.Id == pid).ToList()).FirstOrDefault();
            postInfoDto.PostReplys = GetPostReplysByPostId(pid);            //new


            // 把当前的点击率缓存下来pid

            //

            #region 推翻了
            //// 每次做一个操作的,时候,吧当前的key 写到集合里面,.方便我后续刷盘的时候使用
            //// 会记录每次操作的点击量修改的主题,如果知道同步时间的话
            //cacheClientDB.AddItemToSet(ConfigManger.Clicks_AllKeys, ConfigManger.Clicks + pid);

            ////这是详情页的
            //postInfoDto.post.Clicks = (int)cacheClientDB.Increment(ConfigManger.Clicks + pid, 1);
            //// todo  后面考虑要不要把这,,)字段持久化到数据库,当前表中的字段要不要拆出来
            #endregion
            cacheClientDB.IncrementItemInSortedSet(ConfigManger.Clicks, pid.ToString(), 1);
            postInfoDto.post.Clicks = (int)cacheClientDB.GetItemScoreInSortedSet(ConfigManger.Clicks, pid.ToString());

            return(postInfoDto);
        }
Esempio n. 3
0
        public IFacadeUpdateResult <TopicData> CreateTopic(TopicInfoDto topic, PostInfoDto post)
        {
            // Save topic
            UnitOfWork.BeginTransaction();
            FacadeUpdateResult <TopicData> result = TopicSystem.SaveNewTopic(topic);

            if (result.IsSuccessful)
            {
                UnitOfWork.CommitTransaction();
                TopicData savedTopic = result.Result;
                // set post.TopicId
                post.TopicId = savedTopic.Id;
                // Save Post
                PostSystem postSystem = new PostSystem(UnitOfWork);
                UnitOfWork.BeginTransaction();
                IFacadeUpdateResult <PostData> resultPost = postSystem.SaveNewPost(post);
                if (resultPost.IsSuccessful)
                {
                    UnitOfWork.CommitTransaction();
                }
                else
                {
                    UnitOfWork.RollbackTransaction();
                }
            }
            else
            {
                UnitOfWork.RollbackTransaction();
            }

            return(result);
        }
 private IFacadeUpdateResult <TopicData> SaveCreatedTopic(TopicInfoDto topic, PostInfoDto post)
 {
     using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
     {
         TopicFacade facade = new TopicFacade(uow);
         IFacadeUpdateResult <TopicData> result = facade.CreateTopic(topic, post);
         return(result);
     }
 }
Esempio n. 5
0
 private IFacadeUpdateResult <PostData> SavePost(PostInfoDto post)
 {
     using (IUnitOfWork uow = UnitOfWorkFactory.Instance.Start(DataStoreResolver.CRMDataStoreKey))
     {
         PostFacade facade = new PostFacade(uow);
         IFacadeUpdateResult <PostData> result = facade.SavePost(post);
         return(result);
     }
 }
Esempio n. 6
0
        protected void btnPost_Click(object sender, EventArgs e)
        {
            string content = edContent.Content.Trim();

            if (content.Length > 0)
            {
                PostInfoDto post = new PostInfoDto();
                post.TopicId    = CurrentInstance.TopicId;
                post.Content    = content;
                post.IssuedById = CurrentUserContext.User.UserId;

                IFacadeUpdateResult <PostData> result = SavePost(post);
                if (result.IsSuccessful)
                {
                    Response.Redirect(ReturnUrl, true);
                }
                else
                {
                    ProcUpdateResult(result.ValidationResult, result.Exception);
                }
            }
        }
        // Mapeador personalizado para devolver la lista de posts
        private List <PostInfoDto> PostInfoDtoMapper(List <Post> posts)
        {
            // Creamos el objeto lista que vamos a devolver
            List <PostInfoDto> result = new List <PostInfoDto>();

            // Recorremos la lista de post obtenida por parámetros
            foreach (var post in posts)
            {
                // Creamos y asignamos propiedados a un nuevo PostInfoDto
                PostInfoDto item = new PostInfoDto
                {
                    Id       = post.Id,
                    User     = _mapper.Map <UserInfoDto>(post.User),
                    Picture  = post.Picture,
                    Comments = new List <CommentInfoDto>()
                };

                // Obtenemos el total de likes desde el repositorio de likes
                item.Likes = _likesRepository.GetByPost(item.Id);

                // Obtenemos el total de comentarios desde PostComments
                item.TotalComments = post.PostsComments.Count();

                // Componemos el CommentInfoDto de los comentarios que se añadira al dto de PostInfoDto
                foreach (PostComment postComment in post.PostsComments)
                {
                    CommentInfoDto comment = new CommentInfoDto
                    {
                        Id     = postComment.Comment.Id,
                        Login  = postComment.Comment.User.Login,
                        Remark = postComment.Comment.Remark
                    };
                    item.Comments.Add(comment);
                }
                result.Add(item);
            }

            return(result);
        }
Esempio n. 8
0
        internal IFacadeUpdateResult <PostData> SaveNewPost(PostInfoDto dto)
        {
            ArgumentValidator.IsNotNull("dto", dto);

            FacadeUpdateResult <PostData> result = new FacadeUpdateResult <PostData>();
            IPostService service  = UnitOfWork.GetService <IPostService>();
            Post         instance = RetrieveOrNew <PostData, Post, IPostService>(result.ValidationResult, dto.PostId);

            if (result.IsSuccessful)
            {
                instance.TopicId    = dto.TopicId;
                instance.Title      = dto.Title;
                instance.Content    = dto.Content;
                instance.IssuedById = dto.IssuedById;
                instance.Attachment = dto.Attachment;

                var saveQuery = service.Save(instance);

                result.AttachResult(instance.RetrieveData <PostData>());
                result.Merge(saveQuery);
            }

            return(result);
        }
Esempio n. 9
0
        public string GetPostedTime(object obj)
        {
            PostInfoDto item = (PostInfoDto)obj;

            return(string.Format("{0} {1}", TextOfPostedOn, item.IssuedTime.ToString(WebContext.Current.ApplicationOption.DateTimeFormat)));
        }