Пример #1
0
        protected void btnSaveblog_Click(object sender, EventArgs e)
        {
            try
            {
                BlogModel objBlogModel = new BlogModel();
                string    _imgname     = string.Empty;
                var       imgPath2     = string.Empty;

                var file = FileUpload.PostedFile;

                var      Title        = txtTitle.Text;
                var      Text         = txtText.Text;
                string   publishDate  = txtPublishDate.Text;
                int      Category     = Convert.ToInt32(ddlCategory.SelectedValue);
                string   updateid     = Updateid.Value;
                DateTime PublishDaate = Convert.ToDateTime(publishDate);

                if (file.ContentLength > 0)
                {
                    string fileName        = file.FileName;
                    string fileContentType = file.ContentType;
                    var    _ext            = Path.GetExtension(file.FileName);
                    _imgname = Guid.NewGuid().ToString();
                    var _comPath = Server.MapPath("/BlogImages/") + _imgname + _ext;
                    var imgPath  = "/BlogImages/" + _imgname + _ext;
                    imgPath2 = "/BlogImages/" + _imgname + _ext;
                    var path = _comPath;
                    file.SaveAs(path);

                    if (updateid == "")
                    {
                        objBlogModel.saveBlog(Title, Text, PublishDaate, Category, imgPath2, Convert.ToInt32(Session["LoginId"]));
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Blog saved sucessfully');window.location ='BlogList.aspx';", true);
                    }
                    else
                    {
                        objBlogModel.UpdateBlog(Title, Text, PublishDaate, Category, imgPath2, Convert.ToInt32(Session["LoginId"]), updateid);
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Blog Update sucessfully');window.location ='BlogList.aspx';", true);
                    }
                }
                if (updateid != "" && file.ContentLength == 0)
                {
                    objBlogModel.UpdateBlog(Title, Text, PublishDaate, Category, imgPath2, Convert.ToInt32(Session["LoginId"]), updateid);
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Blog Update sucessfully');window.location ='BlogList.aspx';", true);
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage.Text = ex.Message;
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(" + ex.Message + ")", true);
            }
        }