public async Task <IActionResult> NewsDetail(int Id)
        {
            string url  = _appSetting.UrlApi + "api/article/get-list?TopRow=1&ArticleID=" + Id + "&isHot=-1&Page=1&PageSize=1";
            var    list = await ApiService.GetAsync <RootObject <ArticleModel> >(url);

            var data = list.Items.FirstOrDefault();

            var _data = new ArticleDetail();

            if (data.MenuID == 10)
            {
                string urlImage  = _appSetting.UrlApi + "api/article/image/get?TopRow=1000&ArticleID=" + Id + "&Status=1&Page=1&PageSize=1000";
                var    listImage = await ApiService.GetAsync <RootObject <ArticleImage> >(urlImage);

                _data.ListImage = listImage.Items;
            }

            if (!String.IsNullOrEmpty(data.Detail))
            {
                data.Detail = data.Detail.Replace("<img ", "<img class=\"img-responsive\"");
            }

            _data.Detail = data;

            return(View(_data));
        }
 public ArticleVersionStatePopup(ArticleDetail parent)
 {
     InitializeComponent();
     _parentForm = parent;
     //d9ead3 green
     //F4CCCC
 }
Exemplo n.º 3
0
 public ArticleVersionStateInfo(ArticleDetail parent)
 {
     InitializeComponent();
     _parent = parent;
     uxVersionUpdated.Text    = parent.ArticleDetails.WordDocLastUpdatedBy;
     uxVersionUpdateDate.Text = SitecoreWordUtil.FormatUserName(parent.ArticleDetails.WordDocLastUpdateDate);
 }
Exemplo n.º 4
0
        public ActionResult GetArticleDetail(string id = "")
        {
            if (id.Equals(""))
            {
                return(View("Error"));
            }
            var article = BusinessConfig.MyArticleService.FindOneById(new Guid(id));

            if (article == null)
            {
                return(View("Error"));
            }
            var author = MyService.MyUserManager.FindByIdAsync(article.AuthorId).Result;
            var model  = new ArticleDetail()
            {
                Id             = article.Id,
                AuthorId       = article.AuthorId,
                AuthorAvatar   = author.Avatar,
                AuthorNickNmae = author.NickName,
                CreatedTime    = article.CreatedTime,
                Title          = article.Title,
                Body           = article.Body
            };

            if (AppUser != null && AppUser.Id.Equals(author.Id))
            {
                ViewBag.ShowEdit = true;
            }
            else
            {
                ViewBag.ShowEdit = false;
            }
            return(View(model));
        }
Exemplo n.º 5
0
        public long Article_Edit(int ExeType, int ExeUserID, ArticleDetail article)
        {
            try
            {
                var oCommand = new SqlCommand("[cms].[SP_Article_Edit]");
                oCommand.CommandType = CommandType.StoredProcedure;
                oCommand.Parameters.Add(new SqlParameter("@_ExeType", ExeType));
                oCommand.Parameters.Add(new SqlParameter("@_ExeUserID", ExeUserID));
                oCommand.Parameters.Add(new SqlParameter("@_ArticleID", article.ArticleId));
                oCommand.Parameters.Add(new SqlParameter("@_Title", article.Title));
                oCommand.Parameters.Add(new SqlParameter("@_Status", article.Status));
                oCommand.Parameters.Add(new SqlParameter("@_Summary", article.Summary));
                oCommand.Parameters.Add(new SqlParameter("@_Banner1", article.Banner1));
                oCommand.Parameters.Add(new SqlParameter("@_Content", article.Content));
                oCommand.Parameters.Add(new SqlParameter("@_ArticleLink", article.ArticleLink));
                oCommand.Parameters.Add(new SqlParameter("@_MainCateId", article.Main_CateId));
                oCommand.Parameters.Add(new SqlParameter("@_Tags", article.Tags));
                oCommand.Parameters.Add(new SqlParameter("@_PublicTime", article.PublicTime));
                oCommand.Parameters.Add(new SqlParameter("@_OrderID", article.OrderID));

                var p_ResponseStatus = new SqlParameter("@_ResponseStatus", SqlDbType.BigInt);
                p_ResponseStatus.Direction = ParameterDirection.Output;
                oCommand.Parameters.Add(p_ResponseStatus);

                db.ExecuteNonQuery(oCommand);

                return(p_ResponseStatus.SqlValue.ToString() != "Null" ? (long)p_ResponseStatus.Value : 0);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
                return(-69);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// The Method would open up and initialze the Article Information Plugin window. You can use this to set Taxonomy items, Article MetaData etc.
        /// </summary>
        private void OpenArticleInformation()
        {
            try
            {
                ArticleDetail.Open();

                if (GetArticleNumber() != null)
                {
                    CheckoutStatus checkedOut = SitecoreClient.GetLockedStatus(GetArticleNumber());
                    if (checkedOut.User == SitecoreUser.GetUser().Username)
                    {
                        SaveToSitecoreBtn.Enabled  = true;
                        ArticlePreviewMenu.Enabled = true;
                    }
                    else
                    {
                        SaveToSitecoreBtn.Enabled  = false;
                        ArticlePreviewMenu.Enabled = false;
                    }
                }
            }
            catch (UnauthorizedAccessException uax)
            {
                Globals.SitecoreAddin.LogException("ESRibbon.OpenArticleInformation: Error loading the article information window! Unauthorized access to API handler. Asking user to login again", uax);
                MessageBox.Show(Constants.SESSIONTIMEOUTERRORMESSAGE);
            }
            catch (Exception ex)
            {
                Globals.SitecoreAddin.LogException("ESRibbon.OpenArticleInformation: Error loading the article information window!", ex);
                MessageBox.Show
                    (@"An error has occurred while attempting to display the article information window. Please restart Word and try again." +
                    Environment.NewLine + Environment.NewLine +
                    @"If the problem persists, contact your system administrator.", @"Informa", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult> ArticleAdd(ArticleDetail article)
        {
            #region 验证
            if (!ModelState.IsValid)
            {
                return(View(article));
            }

            var lisTags = new List <Tag>();
            foreach (var s in article.Tags)
            {
                lisTags.Add(Db.Tag.FirstOrDefault(i => i.Id == s));
            }
            if (lisTags.Count == 0)
            {
                return(Json(new ManageJsonResult()
                {
                    Code = 2,
                    Msg = "请选择标签!"
                }));
            }


            if (string.IsNullOrEmpty(article.Img))
            {
                return(Json(new ManageJsonResult()
                {
                    Code = 3,
                    Msg = "请上传缩略图!!"
                }));
            }
            #endregion
            _articleRepository.InsertArt(new Article
            {
                IsShow      = true,
                Title       = article.Title,
                Img         = article.Img,
                Content     = article.Content,
                PublishTime = DateTime.Now,
                Pviews      = 0,
                CategoryId  = article.CategoryId,
                Summary     = article.Summary,
                UserId      = CurUserInfo.UserId,
                Tags        = lisTags,
                CollectTime = DateTime.Now.ToString("G"),
                CollectUser = CurUserInfo.UserName
            });

            var r = await _unitOfWork.SaveChangesAsync() > 0;


            return(Json(new ManageJsonResult()
            {
                Code = r ? 0 : 1,
                Msg = r? "ok" : "SaveChanges失败!"
            }));
        }
Exemplo n.º 8
0
        public async Task <ActionResult> ArticleEdit(ArticleDetail article)
        {
            if (!ModelState.IsValid)
            {
                return(View(article));
            }

            if (article.Tags.Count == 0)
            {
                return(Json(new ManageJsonResult()
                {
                    Code = 2,
                    Msg = "请勾选标签!"
                }));
            }

            if (string.IsNullOrEmpty(article.Img))
            {
                return(Json(new ManageJsonResult()
                {
                    Code = 3,
                    Msg = "请上传缩略图!!"
                }));
            }

            var tempart = _articleRepository.GetArticles().FirstOrDefault(i => i.Id == article.Id);

            if (tempart == null)
            {
                return(Json(new ManageJsonResult()
                {
                    Code = 404,
                    Msg = "没有找到数据!"
                }));
            }
            tempart.Tags.Clear();
            Mapper.Map(article, tempart);


            var lisTags = new List <Tag>();

            foreach (var s in article.Tags)
            {
                lisTags.Add(_tagsRepository.GetTags().FirstOrDefault(i => i.Id == s));
            }
            tempart.Tags          = lisTags;
            tempart.LastMdifyTime = DateTime.Now;

            var r = await _unitOfWork.SaveChangesAsync() > 0;

            return(Json(new ManageJsonResult()
            {
                Code = r ? 0 : 1,
                Msg = r ? "ok" : "SaveChanges失败!"
            }));
        }
Exemplo n.º 9
0
        public ActionResult ByCategory(Category category)
        {
            Article article = articles.First(a => a.Category == category);

            ArticleDetail articleDetail = new ArticleDetail();

            articleDetail.InjectFrom(article);

            return(View("Index", articleDetail));
        }
Exemplo n.º 10
0
        public ActionResult ById(int id)
        {
            Article article = articles.Find(id);

            ArticleDetail articleDetail = new ArticleDetail();

            articleDetail.InjectFrom(article);

            return(View("Index", articleDetail));
        }
Exemplo n.º 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Validate admin session username and password by comparing them to the admin user database record.
            UserNameVal.ValidateAdminUserNameandPass();

            //Get admin username from the sessioan variable and place it in the label.
            lblusername.Text = "Welcome Admin:&nbsp;" + UserNameVal.AdminUsername;

            if (Request.QueryString["prevedit"] != null)
            {
                btn1.Visible = false;
                btn2.Visible = true;
            }
            else
            {
                btn1.Visible = true;
                btn2.Visible = false;
            }

            //Instantiate database field
            ArticleDetail Article = new ArticleDetail();

            Article.WhatPageID = (int)Util.Val(Request.QueryString["show"]); //Parameter 2 = we are dealing with the admin/updatearticle.aspx.
            Article.ID         = (int)Util.Val(Request.QueryString["aid"]);

            //Fill up database fields
            Article.fillup();

            string categoryname;
            categoryname = Article.Category;

            lbtitle.Text    = Article.Title;
            lbcatname2.Text = Article.Category;
            Title.Value     = Article.Title;
            Content.Value   = Util.FormatText(Article.Content);
            Summary.Value   = Util.FormatText(Article.Summary);
            Keyword.Value   = Article.Keyword;
            Author.Value    = Article.Author;
            CAT_ID.Value    = Article.CatID.ToString();

            //Release allocated memory
            myBL    = null;
            Util    = null;
            Article = null;
        }
    }
Exemplo n.º 12
0
        public ActionResult Chitiet(int id)
        {
            int            totalPage           = 0;
            IArticle       dbArticle           = ADODAOFactory.Instance().CreateArticleDao();
            List <Article> listNewArticle      = dbArticle.GetListArticleNew(1, 4, out totalPage);
            List <Article> listArticleMostView = dbArticle.GetListArticleMostView(1, 4, out totalPage);

            ArticleDetail article = dbArticle.GetArticleDetail(id);

            List <Article> listArticleByTag = dbArticle.GetArticleByTag(article.Tags, 1, 6, out totalPage);

            ViewBag.listNewArticle      = listNewArticle;
            ViewBag.listArticleMostView = listArticleMostView;
            ViewBag.listArticleByTag    = listArticleByTag;

            return(PartialView(article));
        }
Exemplo n.º 13
0
 public ArticleWorkflowInfo(ArticleDetail parent)
 {
     InitializeComponent();
     uxWorkflowState.Text = parent?.ArticleDetails?.ArticleWorkflowState != null ?
                            parent.ArticleDetails.ArticleWorkflowState.DisplayName : "N/A";
     if (parent != null && parent._Live)
     {
         label3.Visible     = true;
         uxPublishedOn.Text =
             parent.ArticleDetails.WebPublicationDate.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US"));
     }
     else
     {
         label3.Visible        = false;
         uxPublishedOn.Visible = false;
     }
 }
Exemplo n.º 14
0
        private void refreshState()
        {
            try
            {
                var documentCustomProperties = new DocumentCustomProperties(SitecoreAddin.ActiveDocument);
                using (ArticleDetailFieldsUpdateDisabler disabler = new ArticleDetailFieldsUpdateDisabler())
                {
                    var updatedArticleDetail = new ArticleDetail();

                    var localDocVersion    = documentCustomProperties.WordSitecoreVersionNumber;
                    var sitecoreDocVersion = SitecoreClient.GetWordVersionNumber(_parentForm.ArticleDetails.ArticleGuid);

                    if (sitecoreDocVersion > localDocVersion)
                    {
                        Color color = (Color) new ColorConverter().ConvertFromString("#F4CCCC");
                        this.BackColor = color;
                        lblTitle.Text  = "This document is Outdated";
                    }
                    else
                    {
                        Color color = (Color) new ColorConverter().ConvertFromString("#d9ead3");
                        this.BackColor = color;
                        lblTitle.Text  = "This document is Up to Date";
                    }

                    var user = SitecoreClient.GetFullNameAndEmail(updatedArticleDetail.ArticleDetails.WordDocLastUpdatedBy);

                    lblBy.Text = user[0];

                    DateTime dt;
                    if (updatedArticleDetail.ArticleDetails != null && DateTime.TryParse(updatedArticleDetail.ArticleDetails.WordDocLastUpdateDate, out dt))
                    {
                        lblUpdatedOn.Text = dt.ToLocalTime().ToString(CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        lblUpdatedOn.Text = _parentForm.ArticleDetails.WordDocLastUpdateDate.ToString(CultureInfo.InvariantCulture);
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.SitecoreAddin.LogException("refreshState ex: " + ex.ToString());
            }
        }
Exemplo n.º 15
0
        private void uxRefresh_Click(object sender, EventArgs e)
        {
            if (_parent == null || _parent.ArticleDetails == null)
            {
                return;
            }


            var updatedArticleDetail = new ArticleDetail();

            if (Convert.ToDateTime(_parent.ArticleDetails.WordDocLastUpdateDate) >=
                Convert.ToDateTime(updatedArticleDetail.ArticleDetails.WordDocLastUpdateDate))
            {
                return;
            }
            uxVersionUpdated.Text    = updatedArticleDetail.ArticleDetails.WordDocLastUpdatedBy;
            uxVersionUpdateDate.Text = SitecoreWordUtil.FormatUserName(Convert.ToDateTime(updatedArticleDetail.ArticleDetails.WordDocLastUpdateDate).ToLocalTime().ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 16
0
        public static ArchiveInSql ConvertArchiveInSql(ArticleDetail model)
        {
            if (model != null)
            {
                var r = new ArchiveInSql();

                //映射处理
                var map = new TypeMapping<ArticleDetail, ArchiveInSql>();
                map.AutoMap();
                map.CopyLeftToRight(model, r);

                r.TaxonomyId = r.Categorys.Union(r.Tags).Distinct().Select(e => e.Key).ToList();

                return r;
            }

            return null;
        }
Exemplo n.º 17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Instantiate utility/common object
        Utility Util = new Utility();

        Article.WhatPageID = constant.intArticleDetails;
        Article.ID         = (int)Util.Val(Request.QueryString["aid"]);

        //Fill up article database fields
        Article.fillup();

        lblwordcount.Text = Utility.WordCount(Article.Content).ToString();

        lbtitle.Text       = Article.Title;
        lbcontent.Text     = Article.Content;
        lbhits.Text        = string.Format("{0:#,###}", Article.Hits);
        lbauthor.Text      = Article.Author;
        lblrating.Text     = Article.Rating;
        lblvotescount.Text = Article.NoRates;
        starimage.ImageUrl = Utility.GetStarImage(Article.Rating);
        lbldate.Text       = string.Format("{0:MMMM dd, yyyy}", Article.Date);

        //Save to Favorite/Bookmark URL.
        strBookmarkURL = Bookmark.URL;

        strArtTitle    = Article.Title;
        strCatName     = Article.Category;
        ArtCatId       = Article.CatID;
        ArticleSection = constant.intArticle;

        //Get page title and keyword
        GetMetaTitleTagKeywords(strArtTitle, strCatName);

        //Get cooking article user rating
        GetUserCookingArticleRating();

        //Release allocated memory
        Util    = null;
        Article = null;
    }
Exemplo n.º 18
0
        void OpenArticleInformationWindowIfNeeded(Word.Document doc)
        {
            var props = new DocumentCustomProperties(doc);

            if (props.PluginName != Constants.InformaPluginName)
            {
                return;
            }
            string articleNumber = props.ArticleNumber;

            if (!string.IsNullOrEmpty(articleNumber))
            {
                Log("Document opened with article number: " + articleNumber);
                if (!SitecoreUser.GetUser().IsLoggedIn)
                {
                    ArticleDetail.Open(true);
                }
                else
                {
                    CheckoutStatus checkedOut = SitecoreClient.GetLockedStatus(articleNumber);
                    if (checkedOut.User == SitecoreUser.GetUser().Username)
                    {
                        DocumentProtection.Unprotect(props);
                        return;
                    }
                    if (!checkedOut.Locked)
                    {
                        if (DialogFactory.PromptAutoLock() == DialogResult.Yes &&
                            SitecoreClient.CheckOutArticle(articleNumber, SitecoreUser.GetUser().Username))
                        {
                            DocumentProtection.Unprotect(props);
                        }
                    }
                    else
                    {
                        ArticleDetail.Open();
                    }
                }
            }
        }
Exemplo n.º 19
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Instantiate utility object
        Utility Util = new Utility();

        //Instantiate database field
        ArticleDetail Article = new ArticleDetail();

        Article.WhatPageID = constant.intArticleDetails; //Parameter 1 = we are dealing with the articledetail.aspx.
        Article.ID         = (int)Util.Val(Request.QueryString["aid"]);

        //Fill up article database fields
        Article.fillup();

        lbtitle.Text   = Article.Title;
        lbcontent.Text = Article.Content;
        strArtTitle    = "Printing " + Article.Title + " article";

        //Release allocated memory
        Util    = null;
        Article = null;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Instantiate utility object
        Utility Util = new Utility();

        //Instantiate database field
        ArticleDetail Article = new ArticleDetail();

        Article.WhatPageID = constant.intArticleDetails; //Parameter 1 = we are dealing with the articledetail.aspx.
        Article.ID = (int)Util.Val(Request.QueryString["aid"]);

        //Fill up article database fields
        Article.fillup();

        lbtitle.Text = Article.Title;
        lbcontent.Text = Article.Content;
        strArtTitle = "Printing " + Article.Title + " article";

        //Release allocated memory
        Util = null;
        Article = null;
    }
Exemplo n.º 21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Validate admin session username and password by comparing them to the admin user database record.
            UserNameVal.ValidateAdminUserNameandPass();

            //Get admin username from the session variable and place it in the label.
            lblusername.Text = "Welcome Admin:&nbsp;" + UserNameVal.AdminUsername;

            Article.WhatPageID = constant.intArticleAdminPreview;
            Article.ID         = (int)Util.Val(Request.QueryString["aid"]);

            Article.fillup();

            lbtitle.Text     = Article.Title;
            lbartdetail.Text = Article.Content;

            //Release allocated memory
            Util    = null;
            Article = null;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Validate admin session username and password by comparing them to the admin user database record.
            UserNameVal.ValidateAdminUserNameandPass();

            //Get admin username from the session variable and place it in the label.
            lblusername.Text = "Welcome Admin:&nbsp;" + UserNameVal.AdminUsername;

            Article.WhatPageID = constant.intArticleAdminPreview;
            Article.ID = (int)Util.Val(Request.QueryString["aid"]);

            Article.fillup();

            lbtitle.Text = Article.Title;
            lbartdetail.Text = Article.Content;

            //Release allocated memory
            Util = null;
            Article = null;
        }
    }
Exemplo n.º 23
0
        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="request"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task <ApiResult> AddArticleAsync(AddArticleRequest request, long userId)
        {
            var response = new ApiResult();

            try
            {
                var defaultCategoryId = default(long);

                var user = await _userRepository.TableNotTracking
                           .FirstOrDefaultAsync(item => item.Id == userId && item.Status == 1);

                if (user == null)
                {
                    response.Code    = Code.Error;
                    response.Message = "查无用户";
                    return(response);
                }
                //有传分类Id直接赋值
                if (request.CategoryId.HasValue)
                {
                    defaultCategoryId = request.CategoryId.Value;
                }
                else
                {
                    //没有传分类Id,获取默认分类。若不存在默认分类请新建
                    var category = await _categoryRepository.TableNotTracking
                                   .FirstOrDefaultAsync(item => item.UserId == userId && item.Status == 1 && item.IsDefault == 1);

                    if (category == null)
                    {
                        var newCategory = new Category(true)
                        {
                            IsDefault    = 1,
                            Status       = 1,
                            CategoryName = "默认分类",
                            CreateTime   = DateTime.Now,
                            UserId       = userId,
                            Creator      = user.UserName
                        };
                        await _categoryRepository.InsertAsync(newCategory);

                        category = newCategory;
                    }
                    defaultCategoryId = category.Id;
                }

                var article = new Article(true)
                {
                    Title      = request.Title,
                    Describe   = request.Describe,
                    CategoryId = defaultCategoryId,
                    Status     = 1,
                    CreateTime = DateTime.Now,
                    Creator    = user.UserName,
                    UserId     = userId
                };

                var detail = new ArticleDetail(true)
                {
                    ArticleId   = article.Id,
                    Content     = request.Content,
                    ContentType = request.ContentType,
                    CreateTime  = DateTime.Now,
                    Creator     = user.UserName,
                    Status      = 1
                };

                await _articleRepository.InsertAsync(article);

                await _articleDetailRepository.InsertAsync(detail);

                await _work.SaveChangesAsync();

                response.Code    = Code.Ok;
                response.Message = "添加成功";
                return(response);
            }
            catch (Exception ex)
            {
                _logger.LogError($"添加文章异常;method={nameof(AddArticleAsync)};param={request?.ToJson()};exception messges={ex.Message}");
                response.Code    = Code.Error;
                response.Message = $"添加文章异常:{ex.Message}";
                return(response);
            }
        }
 public void LinkToParent(ArticleDetail parent)
 {
     _parent = parent;
     pageArticleInformationControl.LinkToParent(parent);
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Instantiate utility/common object
        Utility Util = new Utility();

        Article.WhatPageID = constant.intArticleDetails;
        Article.ID = (int)Util.Val(Request.QueryString["aid"]);

        //Fill up article database fields
        Article.fillup();

        lblwordcount.Text = Utility.WordCount(Article.Content).ToString();

        lbtitle.Text = Article.Title;
        lbcontent.Text = Article.Content;
        lbhits.Text = string.Format("{0:#,###}", Article.Hits);
        lbauthor.Text = Article.Author;
        lblrating.Text = Article.Rating;
        lblvotescount.Text = Article.NoRates;
        starimage.ImageUrl = Utility.GetStarImage(Article.Rating);
        lbldate.Text = string.Format("{0:MMMM dd, yyyy}", Article.Date);

        //Save to Favorite/Bookmark URL.
        strBookmarkURL = Bookmark.URL;

        strArtTitle = Article.Title;
        strCatName = Article.Category;
        ArtCatId = Article.CatID;
        ArticleSection = constant.intArticle;

        //Get page title and keyword
        GetMetaTitleTagKeywords(strArtTitle, strCatName);

        //Get cooking article user rating
        GetUserCookingArticleRating();

        //Release allocated memory
        Util = null;
        Article = null;
    }
Exemplo n.º 26
0
 public void LinkToParent(ArticleDetail parent)
 {
     _parent = parent;
     _articleInformationControl = _parent.articleDetailsPageSelector.pageArticleInformationControl;
 }
Exemplo n.º 27
0
 public void LinkToParent(ArticleDetail parent)
 {
     _parent = parent;
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Validate admin session username and password by comparing them to the admin user database record.
            UserNameVal.ValidateAdminUserNameandPass();

            //Get admin username from the sessioan variable and place it in the label.
            lblusername.Text = "Welcome Admin:&nbsp;" + UserNameVal.AdminUsername;

            if (Request.QueryString["prevedit"] != null)
            {
                btn1.Visible = false;
                btn2.Visible = true;
            }
            else
            {
                btn1.Visible = true;
                btn2.Visible = false;
            }

            //Instantiate database field
            ArticleDetail Article = new ArticleDetail();

            Article.WhatPageID = (int)Util.Val(Request.QueryString["show"]); //Parameter 2 = we are dealing with the admin/updatearticle.aspx.
            Article.ID = (int)Util.Val(Request.QueryString["aid"]);

            //Fill up database fields
            Article.fillup();

            string categoryname;
            categoryname = Article.Category;

            lbtitle.Text = Article.Title;
            lbcatname2.Text = Article.Category;
            Title.Value = Article.Title;
            Content.Value = Util.FormatText(Article.Content);
            Summary.Value = Util.FormatText(Article.Summary);
            Keyword.Value = Article.Keyword;
            Author.Value = Article.Author;
            CAT_ID.Value = Article.CatID.ToString();

            //Release allocated memory
            myBL = null;
            Util = null;
            Article = null;
        }
    }
Exemplo n.º 29
0
        public JsonResult SaveArticle()
        {
            bool   result = false;
            string msg    = "";

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    string data     = Request["data"];
                    string deleteId = Request["deleteId"];

                    int nodeId  = 0;
                    int _orders = 1;

                    ViewArticle <ViewModifyArticle> article = DataJsonSerializer <ViewArticle <ViewModifyArticle> > .JsonToEntity(data);

                    List <string> decodeList = new List <string>();

                    var imageList = article.detailList.Where(p => p.Type == "image");
                    var videoList = article.detailList.Where(p => p.Type == "video");
                    foreach (ViewModifyArticle detail in article.detailList)
                    {
                        string detailId      = detail.detailId;
                        string detailType    = detail.Type;
                        string detailContent = HttpUtility.UrlDecode(detail.Content);

                        //添加主标题
                        if (detailType == "title")
                        {
                            Node dbNode = db.Nodes.Find(int.Parse(detail.detailId));

                            nodeId          = int.Parse(detailId);
                            dbNode.nodeName = detailContent;
                            if (imageList.Count() > 0)
                            {
                                dbNode.url = HttpUtility.UrlDecode(imageList.ToList()[0].Content);
                            }
                            else
                            {
                                dbNode.url = "";//默认图片
                            }
                            if (videoList.Count() > 0)
                            {
                                dbNode.isVideo = 1;
                            }
                            else
                            {
                                dbNode.isVideo = 0;
                            }
                            if (article.detailList.Count > 1)
                            {
                                dbNode.isUsable = 1;
                            }
                            else
                            {
                                dbNode.isUsable = 0;
                            }

                            db.SaveChanges();
                        }
                        else
                        {
                            if (detail.detailId == "")
                            {
                                ArticleDetail details = new ArticleDetail();

                                details.nodeId         = nodeId;
                                details.detailType     = detailType;
                                details.detailContent  = detailContent;
                                details.souceFileName  = HttpUtility.UrlDecode(detail.sourceFileName);
                                details.orders         = _orders;
                                details.lastUpdateDate = DateTime.Now;

                                db.ArticleDetail.Add(details);
                            }
                            else
                            {
                                ArticleDetail details = db.ArticleDetail.Find(int.Parse(detail.detailId));

                                if ((details.detailType == "image" || details.detailType == "video") && details.detailContent != detailContent)
                                {
                                    Util.DeleteBlog(details.detailContent);//新文件与原文件不是同一文件,则删除旧文件
                                }

                                details.detailContent  = detailContent;
                                details.souceFileName  = HttpUtility.UrlDecode(detail.sourceFileName);
                                details.orders         = _orders;
                                details.lastUpdateDate = DateTime.Now;
                            }
                            db.SaveChanges();

                            _orders++;
                        }
                    }

                    if (deleteId != "")
                    {
                        string[] delIdAry = deleteId.TrimEnd('|').Split('|');
                        foreach (string detailId in delIdAry)
                        {
                            ArticleDetail detail = db.ArticleDetail.Find(int.Parse(detailId));

                            if (detail.detailType == "image" || detail.detailType == "video")
                            {
                                Util.DeleteBlog(detail.detailContent);//删除文件
                            }

                            db.ArticleDetail.Remove(detail);
                            db.SaveChanges();
                        }
                    }

                    scope.Complete();

                    result = true;
                    msg    = "保存成功";
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
                finally
                {
                    scope.Dispose();
                }
            }

            return(Json(new { Result = result, Msg = msg }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 30
0
        public JsonResult AddNewArticle()
        {
            bool   result = false;
            string msg    = "";
            int    nodeId = 0;

            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    string parentId  = Request["parentId"];
                    string data      = Request["data"];
                    int    _parentId = int.Parse(parentId);
                    int    _orders   = 1;

                    ViewArticle <ViewArticleDetail> article = DataJsonSerializer <ViewArticle <ViewArticleDetail> > .JsonToEntity(data);

                    List <string> decodeList = new List <string>();

                    var imageList = article.detailList.Where(p => p.Type == "image");
                    var videoList = article.detailList.Where(p => p.Type == "video");
                    foreach (ViewArticleDetail detail in article.detailList)
                    {
                        string detailType    = detail.Type;
                        string detailContent = HttpUtility.UrlDecode(detail.Content);

                        //添加主标题
                        if (detailType == "title")
                        {
                            Node dbNode = new Node();

                            dbNode.parentId = _parentId;
                            dbNode.nodeName = detailContent;
                            if (imageList.Count() > 0)
                            {
                                dbNode.url = HttpUtility.UrlDecode(imageList.ToList()[0].Content);
                            }
                            else
                            {
                                dbNode.url = "";//默认图片
                            }
                            dbNode.isArticle = 1;
                            if (videoList.Count() > 0)
                            {
                                dbNode.isVideo = 1;
                            }
                            if (article.detailList.Count > 1)
                            {
                                dbNode.isUsable = 1;
                            }
                            else
                            {
                                dbNode.isUsable = 0;
                            }
                            dbNode.createPerson = t_userName;
                            dbNode.createDate   = DateTime.Now;

                            db.Nodes.Add(dbNode);
                            db.SaveChanges();

                            nodeId = dbNode.nodeId; //数据库生成的Id
                        }
                        else
                        {
                            ArticleDetail details = new ArticleDetail();

                            details.nodeId         = nodeId;
                            details.detailType     = detailType;
                            details.detailContent  = detailContent;
                            details.souceFileName  = HttpUtility.UrlDecode(detail.sourceFileName);
                            details.orders         = _orders;
                            details.lastUpdateDate = DateTime.Now;

                            db.ArticleDetail.Add(details);
                            db.SaveChanges();

                            _orders++;
                        }
                    }
                    scope.Complete();

                    result = true;
                    msg    = "保存成功";
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
                finally
                {
                    scope.Dispose();
                }
            }

            return(Json(new { Result = result, Msg = msg, nodeId = nodeId }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 31
0
        public ArticleDetail GetDetail(int ArticleID)
        {
            var res = new ArticleDetail
            {
                ArticleEntity = _ctx.Articles.Find(ArticleID),
                ScoredPhrases = new List <ScoredPhrase>()
            };

            if (res.ArticleEntity == null)
            {
                return(null);
            }
            var    phrases = ShingleLogic.FindPhrases(res.ArticleEntity);
            string text    = res.ArticleEntity.Text();
            var    scores  = new double[text.Length];

            foreach (string phrase in phrases)
            {
                var sh = _ctx.Shingles.FirstOrDefault(s => s.text == phrase);
                if (sh == null)
                {
                    continue;
                }
                var sa = _ctx.ShingleActions.FirstOrDefault(x => x.shingleID == sh.ID && x.interval == 30);
                if (sa == null)
                {
                    continue;
                }
                if (sa.down == null || sa.up == null)
                {
                    continue;
                }
                float score = (sa.up.Value + sa.down.Value - 2) * 100;
                if (!res.ScoredPhrases.Any(p => p.Phrase == phrase))
                {
                    res.ScoredPhrases.Add(new ScoredPhrase {
                        Score = score, Phrase = phrase, Color = GetColor(score), ShingleID = sh.ID
                    });
                }
                int wordIndex = text.IndexOf(phrase, StringComparison.OrdinalIgnoreCase);
                if (wordIndex >= 0)
                {
                    for (int i = wordIndex; i < wordIndex + sh.text.Length; i++)
                    {
                        scores[i] += score;
                    }
                }
            }

            res.Colored = new List <ColoredText>();
            for (int i = 0; i < text.Length; i++)
            {
                string newColor = GetColor(scores[i]);
                if (res.Colored.Count == 0 || res.Colored.Last().Color != newColor)
                {
                    res.Colored.Add(new ColoredText {
                        Color = newColor, Text = text.Substring(i, 1)
                    });
                }
                else
                {
                    res.Colored[res.Colored.Count - 1] = new ColoredText
                    {
                        Color = newColor,
                        Text  = res.Colored[res.Colored.Count - 1].Text + text.Substring(i, 1)
                    };
                }
            }
            return(res);
        }