コード例 #1
0
        public JsonResult DelFavorites(string inArticleID)
        {
            JsonResult json = new JsonResult();

            if (string.IsNullOrEmpty(inArticleID))
            {
                json.Data = new { result = false, msg = "取消收藏失败" };
                return(json);
            }

            try
            {
                if (Session["LoginUser"] is ViewModels.VMUser vUser)
                {
                    bool   result = LFavorites.DeleteFavorite(Convert.ToInt64(inArticleID), vUser.UID) > 0;
                    string msg    = result ? "" : "取消收藏失败";

                    json.Data = new { result, msg };
                }
            }
            catch (Exception ex)
            {
                json.Data = new { result = false, msg = "取消收藏失败" };
            }

            return(json);
        }
コード例 #2
0
        public JsonResult AddFavorites(string inArticleID, string inTitle)
        {
            JsonResult json = new JsonResult();

            try
            {
                if (string.IsNullOrEmpty(inArticleID))
                {
                    json.Data = new { result = false, msg = "收藏失败" };
                    return(json);
                }

                if (Session["LoginUser"] is ViewModels.VMUser vUser)
                {
                    Model.MFavorites model = new Model.MFavorites
                    {
                        ArticleID     = Convert.ToInt64(inArticleID),
                        UID           = vUser.UID,
                        FaTitle       = inTitle,
                        FavoritesTime = DateTime.Now
                    };

                    bool   result = LFavorites.CreateFavorite(model) > 0;
                    string msg    = result ? "" : "收藏失败";

                    json.Data = new { result, msg };
                }
                else
                {
                    json.Data = new { result = false, msg = "notlogin" };
                }
            }
            catch (Exception ex)
            {
                json.Data = new { result = false, msg = "收藏失败" };
            }

            return(json);
        }
コード例 #3
0
        public ActionResult FavoritesList(string search = "")
        {
            List <ViewModels.VMFavorites> vList = new List <ViewModels.VMFavorites>();

            ViewBag.Name    = string.Empty;
            ViewBag.IsLogin = false;
            ViewBag.Search  = search;

            if (Session["LoginUser"] is ViewModels.VMUser vUser)
            {
                var list = string.IsNullOrEmpty(search) ? LFavorites.GetFavorites(vUser.UID) : LFavorites.SearchFav(search, vUser.UID);

                foreach (var item in list)
                {
                    ViewModels.VMFavorites vModel = new ViewModels.VMFavorites
                    {
                        FaID          = item.FaID,
                        ArticleID     = item.ArticleID,
                        FavoritesTime = item.FavoritesTime.ToShortDateString(),
                        FaTitle       = item.FaTitle
                    };
                    vList.Add(vModel);
                }

                ViewBag.Name    = vUser.UserName;
                ViewBag.IsLogin = true;
            }

            ViewBag.VCount = LVisitorCount.GetVisitorCount().Count;

            if (State)
            {
                return(View("MobileFavoritesList", vList));
            }

            return(View(vList));
        }
コード例 #4
0
        public ActionResult ArticleInfo(long inArticleID)
        {
            Model.MContent       model  = LContent.GetArticle(inArticleID);
            ViewModels.VMArticle vModel = new ViewModels.VMArticle();

            if (model != null)
            {
                vModel.ArticleID   = model.ArticleID;
                vModel.Title       = model.Title;
                vModel.DomainID    = model.DomainID;
                vModel.ReleaseTime = ConvertLongToDateTime(model.ReleaseTime).ToShortDateString();
                vModel.Conten      = model.Conten;

                ViewBag.IsLogin = false;
                ViewBag.Name    = string.Empty;

                ViewBag.CatName = GetCatName(vModel.DomainID);

                ViewBag.VCount = LVisitorCount.GetVisitorCount().Count;

                //获取session,判断是否为空
                if (Session["LoginUser"] is ViewModels.VMUser vUser)
                {
                    vModel.IsFavorites = LFavorites.ExistFavorites(vModel.ArticleID, vUser.UID);

                    Model.MFootmarks footmarks = new Model.MFootmarks
                    {
                        UID       = vUser.UID,
                        ArticleID = vModel.ArticleID,
                        MarkTime  = DateTime.Now,
                        FmTitle   = vModel.Title
                    };

                    string fmID = LFootmarks.ExistFootmark(vUser.UID, vModel.ArticleID);
                    if (string.IsNullOrEmpty(fmID))
                    {
                        LFootmarks.CreateFootmark(footmarks);
                    }
                    else
                    {
                        footmarks.FmID = Convert.ToInt32(fmID);
                        LFootmarks.UpdateFootmark(footmarks);
                    }

                    ViewBag.IsLogin = true;
                    ViewBag.Name    = vUser.UserName;
                }
            }

            #region 推荐文章&商品
            var raList = LContent.GetRandomArticles(3, vModel.DomainID);
            List <ViewModels.VMArticle> vRaList = new List <ViewModels.VMArticle>();
            foreach (var item in raList)
            {
                ViewModels.VMArticle ar = new ViewModels.VMArticle
                {
                    ArticleID   = item.ArticleID,
                    Title       = item.Title,
                    DomainID    = item.DomainID,
                    ReleaseTime = ConvertLongToDateTime(item.ReleaseTime).ToShortDateString(),
                    ImgSrc      = GetSrc(item.Conten)
                };
                vRaList.Add(ar);
            }
            ViewData["RelatedArticle"] = vRaList;
            ViewData["Items"]          = TuiJian(vModel.Title);
            #endregion

            if (State)
            {
                return(View("MobileArticleInfo", vModel));
            }

            return(View(vModel));
        }