Ejemplo n.º 1
0
 /// <summary>
 /// 添加收藏
 /// </summary>
 /// <param name="favorite"></param>
 /// <returns></returns>
 public DomainResult AddFavorite(Entity.FxAggregate.Favorite favorite)
 {
     using (var context = new FxAggregateContext())
     {
         var fav = GetFavorite(favorite.ChannelCatagroy, favorite.InfoId, favorite.UserAccount);
         if (fav != null)
         {
             return(new DomainResult(false)
             {
                 ResultMsg = "您已对此帖子进行收藏了"
             });
         }
         var info = aggregateInfoService.GetInfoByCatatgroyAndId(favorite.ChannelCatagroy, favorite.InfoId);
         if (info == null || aggregateInfoService.IsValid(info) == false)
         {
             return(new DomainResult(false)
             {
                 ResultMsg = "您不能对此帖子进行收藏(可能已删除或者未发布)"
             });
         }
         else
         {
             context.Favorites.Add(favorite);
             context.SaveChanges();
             return(DomainResult.GetDefault());
         }
     }
 }
        /// <summary>
        /// 发送私信
        /// </summary>
        /// <param name="infoId">帖子Id</param>
        /// <param name="channelCatagroy">频道</param>
        /// <param name="privateTxt">私信内容</param>
        /// <returns>View</returns>
        public ActionResult PrivateMessage(int infoId, int channelCatagroy, string privateTxt)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Json("私信发送失败,您没有登录,请先登陆", JsonRequestBehavior.DenyGet));
            }
            if (Request.IsAjaxRequest() && infoId > 0 && channelCatagroy >= 0)
            {
                var info = aggregateInfoService.GetInfoByCatatgroyAndId(channelCatagroy, infoId);
                if (info != null && aggregateInfoService.IsValid(info) == true)
                {
                    privateMessageService.AddPrivateMessage(new Entity.FxAggregate.PrivateMessage()
                    {
                        ChannelCatagroy  = channelCatagroy,
                        InterestingEmail = User.Identity.Name,
                        UserAccount      = info.UserAccount,
                        SourceId         = infoId,
                        Title            = info.PublishTitle,
                        Message          = privateTxt
                    });

                    var glo = System.Web.Mvc.DependencyResolver.Current.GetService <GlobalCache>();
                    glo.PrivateMessageCountAdd(info.UserAccount);
                    glo.PrivateMessageTodayCountAdd(info.UserAccount);
                    return(Json("私信发送成功", JsonRequestBehavior.DenyGet));
                }
                else
                {
                    return(Json("私信发送失败", JsonRequestBehavior.DenyGet));
                }
            }
            else
            {
                return(new ContentResult()
                {
                    Content = "Access Forbidden!"
                });
            }
        }