Exemplo n.º 1
0
        public async Task <IActionResult> OnPostAdd()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            if (Path.GetExtension(Image.FileName).Equals(".png") || Path.GetExtension(Image.FileName).Equals(".jpeg") || Path.GetExtension(Image.FileName).Equals(".jpg") ||
                Path.GetExtension(Image.FileName).Equals(".gif") || Path.GetExtension(Image.FileName).Equals(".bmp"))
            {
                BinaryReader reader = new BinaryReader(Image.OpenReadStream());
                if (categories != null)
                {
                    Article.Categories = categories.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                }
                Article.Author = _userManager.GetUserName(User);
                Article.Image  = reader.ReadBytes((int)Image.Length);
                await _articleController.Add(Article, User);

                return(RedirectToPage("/Index"));
            }
            else
            {
                throw new Exception("You can only add pictures!");
            }
        }
        public async Task <IActionResult> OnPostAdd()
        {
            Article.Author = User.Identity.Name;
            await _articleController.Add(Article);

            return(RedirectToPage("/Index"));
        }
        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            ArticleId = Convert.ToInt32(e.CommandArgument);
            ArticleInfo objArticle = ArticleController.Get(ArticleId);

            switch (e.CommandName)
            {
            case "Select":
                BindArticle(ArticleId);
                SetButtonStatus("Select");
                break;

            case "Copy":
                ArticleInfo objNewArticle = objArticle;
                objNewArticle.UserId = UserId;
                ArticleId            = ArticleController.Add(objNewArticle);
                BindArticleList();
                BindArticle(ArticleId);
                SetButtonStatus("Select");
                break;

            case "Del":
                ArticleController.Delete(ArticleId);
                ArticleId = -1;
                BindArticleList();
                break;

            case "Auth":
                ArticleController.UpdateAuthed(ArticleId, !objArticle.Authed);
                BindArticleList();
                break;

            case "Active":
                ArticleController.UpdateActive(ArticleId, !objArticle.Active);
                BindArticleList();
                break;

            case "Featured":
                ArticleController.UpdateFeatured(ArticleId, !objArticle.Featured);
                BindArticleList();
                break;

            case "Draft":
                ArticleController.UpdateDraft(ArticleId, !objArticle.Draft);
                BindArticleList();
                break;

            default:
                break;
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var name        = ArticleName.Text;
            var type        = Type.Text;
            var description = Description.Text;
            var sum         = ParseDouble(Sum.Text);

            ArticleName.Text = String.Empty;
            Type.Text        = String.Empty;
            Description.Text = String.Empty;
            Sum.Text         = String.Empty;

            var articleController = new ArticleController();

            articleController.Add(name, type, description, sum);
        }
Exemplo n.º 5
0
        public void AddTest()
        {
            //Arrange
            var name              = Guid.NewGuid().ToString();
            var type              = Guid.NewGuid().ToString();
            var description       = Guid.NewGuid().ToString();
            var rnd               = new Random();
            var price             = rnd.Next(50, 500);
            var articleController = new ArticleController();

            //Act
            articleController.Add(name, type, description, price);

            //Assert
            Assert.AreEqual(name, articleController.LoadFromDB().First().Name);
        }
        private void UpdateArticle()
        {
            ArticleInfo objArticle = new ArticleInfo();

            objArticle.Id       = ArticleId;
            objArticle.PortalId = PortalId;

            //Normal
            objArticle.Title  = txtTitle.Text;
            objArticle.Author = txtAuthor.Text;
            objArticle.Source = txtSource.Text;
            objArticle.Quote  = chkQuote.Checked;
            objArticle.Draft  = chkDraft.Checked;

            objArticle.LinkUrl  = ctlLinkUrl.Url;
            objArticle.PinOrder = Convert.ToInt32(txtPinOrder.Text);
            //other
            if (ArticlePortalSettings.General.Portal_ArticleRequireApproval == true)
            {
                objArticle.Authed = chkAuthed.Checked;
            }
            else
            {
                objArticle.Authed = true;
            }
            objArticle.Featured = chkFeatured.Checked;
            objArticle.Active   = chkActive.Checked;

            objArticle.Thumbnail        = "";
            objArticle.Image            = UserInfo.IsInRole(PortalSettings.AdministratorRoleName)?ctlImage.Url : ctlUserImage.Url;
            objArticle.ImageDescription = txtImageDescription.Text;


            if (objArticle.Image.StartsWith("FileID="))
            {
                FileController fc = new FileController();
                DotNetNuke.Services.FileSystem.FileInfo      fi        = new DotNetNuke.Services.FileSystem.FileInfo();
                DotNetNuke.Entities.Portals.PortalController ctlPortal = new DotNetNuke.Entities.Portals.PortalController();
                DotNetNuke.Entities.Portals.PortalInfo       pi        = ctlPortal.GetPortal(PortalId);

                fi = GetFileInfoById(objArticle.Image);
                if (fi != null && System.IO.File.Exists(fi.PhysicalPath))
                {
                    objArticle.Thumbnail = DotNetNuke.Common.Globals.ApplicationPath + "/" + pi.HomeDirectory + "/" + fi.Folder + fi.FileName;
                    System.IO.FileInfo physicalFile = new System.IO.FileInfo(fi.PhysicalPath);

                    if (!fi.FileName.ToLower().StartsWith("thumb_"))                                                 //文件没有以"thumb_"开头,则先查找是否存在以thumb_ 开头的同名图片
                    {
                        if (System.IO.File.Exists(physicalFile.DirectoryName + "\\" + "thumb_" + physicalFile.Name)) //存在该文件,则自动指向
                        {
                            objArticle.Thumbnail = DotNetNuke.Common.Globals.ApplicationPath + "/" + pi.HomeDirectory + "/" + fi.Folder + "thumb_" + fi.FileName;
                        }
                        else//不存在,则生成该文件,然后指向
                        {
                            if (ArticlePortalSettings.General.Portal_ArticleGenerateThumb)
                            {
                                Utils.ResizeImage(fi.PhysicalPath, ArticlePortalSettings.General.Portal_ArticleThumbnailSize, physicalFile.DirectoryName + "\\" + "thumb_" + physicalFile.Name);
                                objArticle.Thumbnail = DotNetNuke.Common.Globals.ApplicationPath + "/" + pi.HomeDirectory + "/" + fi.Folder + "thumb_" + fi.FileName;
                            }
                        }
                    }
                }
            }
            //Add Categories
            objArticle.Categories = RecursiveHelper.GetAspNetTreeCheckList(tvCategory);

            //Add Tags
            objArticle.Tags = "";
            TagInfo    objTag  = new TagInfo();
            List <int> tagList = new List <int>();

            if (txtTag1.Text.Trim() != "")
            {
                objTag = TagController.GetByTag(txtTag1.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag1.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag2.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 1)
            {
                objTag = TagController.GetByTag(txtTag2.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag2.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag3.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 2)
            {
                objTag = TagController.GetByTag(txtTag3.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag3.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag4.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 3)
            {
                objTag = TagController.GetByTag(txtTag4.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag4.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag5.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 4)
            {
                objTag = TagController.GetByTag(txtTag5.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag5.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag6.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 5)
            {
                objTag = TagController.GetByTag(txtTag6.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag6.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag7.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 6)
            {
                objTag = TagController.GetByTag(txtTag7.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag7.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag8.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 7)
            {
                objTag = TagController.GetByTag(txtTag8.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag8.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag9.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 8)
            {
                objTag = TagController.GetByTag(txtTag9.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag9.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            if (txtTag10.Text.Trim() != "" && ArticlePortalSettings.General.Portal_ArticleTagSelectCount > 9)
            {
                objTag = TagController.GetByTag(txtTag10.Text.Trim());
                if (objTag == null)
                {
                    objTag          = new TagInfo();
                    objTag.PortalId = PortalId;
                    objTag.UserId   = UserId;
                    objTag.Tag      = txtTag10.Text.Trim();
                    objTag.Id       = TagController.Add(objTag);
                }
                tagList.Add(objTag.Id);
            }
            var newTaglist = (from p in tagList select p).Distinct();//remove the  repeated tag item.

            foreach (int item in newTaglist)
            {
                objArticle.Tags += item.ToString() + ",";
            }
            objArticle.Tags = Utils.RemoveSeperator(objArticle.Tags, ",");
            //Tags end

            //date
            if ((txtPublishDate.Text != null) && (txtPublishDate.Text != ""))
            {
                objArticle.PublishDate = Convert.ToDateTime(txtPublishDate.Text);
            }
            else
            {
                objArticle.PublishDate = DateTime.Now;
            }
            if (txtExpireDate.Text != "")
            {
                objArticle.ExpireDate = Convert.ToDateTime(txtExpireDate.Text);
            }

            objArticle.ViewRoles = Utils.GetCheckedItems(cblViewRoles, PortalSettings.AdministratorRoleId);
            //Rating
            objArticle.AllowRating = chkAllowRating.Checked;
            objArticle.RatingRoles = Utils.GetCheckedItems(cblRatingRoles, PortalSettings.AdministratorRoleId);

            //Recommend
            objArticle.AllowRecommend = chkAllowRecommend.Checked;
            objArticle.RecommendRoles = Utils.GetCheckedItems(cblRecommendRoles, PortalSettings.AdministratorRoleId);


            //Comment
            objArticle.AllowComment    = chkAllowComment.Checked;
            objArticle.CommentRoles    = Utils.GetCheckedItems(cblCommentRoles, PortalSettings.AdministratorRoleId);
            objArticle.AutoAuthComment = chkAutoAuthComment.Checked;
            //Download roles
            objArticle.DownloadRoles = Utils.GetCheckedItems(cblDownloadRoles, PortalSettings.AdministratorRoleId);

            objArticle.Summary = LocalUtils.RemoveAllHtmlTags(txtSummary.Text);
            objArticle.Article = txtDetail.Text;
            objArticle.UserId  = UserId;
            //Now processing attachment
            int newArticleId = -1;

            if (ArticleId == -1)
            {
                newArticleId = ArticleController.Add(objArticle);
            }
            else
            {
                ArticleController.Update(objArticle);
                newArticleId = ArticleId;
                AttachmentController.DeleteByArticle(ArticleId); //delete attachment first.
            }
            AttachmentInfo ai = new AttachmentInfo();

            foreach (AttachmentInfo item in AttachmentList)
            {
                ai.ArticleId = newArticleId;
                ai.FilePath  = item.FilePath;
                AttachmentController.Add(ai);
            }
            //Reset all
            ArticleId               = -1;
            AttachmentList          = new List <AttachmentInfo>();
            gvAttachment.DataSource = AttachmentList;
            gvAttachment.DataBind();
        }