コード例 #1
0
ファイル: tao-thong-bao.aspx.cs プロジェクト: war-man/ANNsys
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string   username    = Request.Cookies["usernameLoginSystem"].Value;
            var      acc         = AccountController.GetByUsername(username);
            DateTime currentDate = DateTime.Now;
            int      cateID      = hdfParentID.Value.ToInt();

            if (cateID > 0)
            {
                int    CategoryID   = ddlCategory.Value.ToInt();
                var    category     = NotifyCategoryController.GetByID(CategoryID);
                string CategorySlug = category.Slug;
                string Title        = txtTitle.Text.Trim();
                string Slugs        = Slug.ConvertToSlug(txtSlug.Text.Trim());
                string Link         = txtLink.Text.Trim();
                string Content      = pContent.Content.ToString();
                string Summary      = HttpUtility.HtmlDecode(pSummary.Content.ToString());
                string Action       = ddlAction.SelectedValue.ToString();
                string ActionValue  = "";
                if (Action == "view_more")
                {
                    ActionValue = Slugs;
                }
                else if (Action == "show_web")
                {
                    ActionValue = Link;
                }
                bool AtHome = ddlAtHome.SelectedValue.ToBool();

                var newNotify = new NotifyNew()
                {
                    CategoryID   = CategoryID,
                    CategorySlug = CategorySlug,
                    Title        = Title,
                    Thumbnail    = "",
                    Summary      = Summary,
                    Content      = Content,
                    Action       = Action,
                    ActionValue  = ActionValue,
                    AtHome       = AtHome,
                    CreatedDate  = currentDate,
                    CreatedBy    = acc.Username,
                    ModifiedDate = currentDate,
                    ModifiedBy   = acc.Username,
                    AppUpdate    = currentDate
                };

                var post = NotifyController.Insert(newNotify);

                //Phần thêm ảnh đại diện
                string path  = "/uploads/images/posts/";
                string Image = "";
                if (PostPublicThumbnailImage.UploadedFiles.Count > 0)
                {
                    foreach (UploadedFile f in PostPublicThumbnailImage.UploadedFiles)
                    {
                        var o = path + "notify-" + post.ID.ToString() + "-" + Slug.ConvertToSlug(Path.GetFileName(f.FileName), isFile: true);
                        try
                        {
                            f.SaveAs(Server.MapPath(o));
                            Image = o;
                        }
                        catch { }
                    }
                }
                string updateImage = NotifyController.UpdateImage(post.ID, Image);

                if (post != null)
                {
                    PJUtils.ShowMessageBoxSwAlertCallFunction("Tạo thông báo thành công", "s", true, "redirectTo(" + post.ID.ToString() + ")", Page);
                }
            }
        }