protected void Save_Click(object sender, EventArgs e) { Stories _stor = new Stories(this.ConnectionString); _stor.Title = HttpUtility.HtmlEncode(txt_Title.Text); _stor.Story = HttpUtility.HtmlEncode(txt_Story.Text); _stor.Status = (Int32)Enums.enumStatuses.Pending; _stor.CategoryId = Convert.ToInt32(dd_Category.SelectedValue); string _imgType = ""; if (fu_Image.HasFile) { _stor.YouTubeLink = ""; _imgType = fu_Image.FileName.Split('.')[1]; _stor.ImgType = _imgType; } else { if (Regex.IsMatch(txt_YouTube.Text, @"^<object[\s\S]+</object>$")) { _stor.YouTubeLink = GetYouTubeLink(); _stor.ImgType = ""; } } if (_stor.Save()) { if (fu_Image.HasFile) { System.Drawing.Image _img = CoreLibrary.Utility.ImageUtility.FixedSize(fu_Image.FileContent, Convert.ToInt32(ConfigurationManager.AppSettings["ImageStoryWidth"]), Convert.ToInt32(ConfigurationManager.AppSettings["ImageStoryHight"]), System.Drawing.Color.Black); String _path = ConfigurationManager.AppSettings["StoriesImagesPath"]; _path = Server.MapPath(String.Format(_path, _stor.ID.ToString(), _imgType)); _img.Save(_path); _img.Dispose(); } Response.Redirect("Default.aspx"); } else { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", "alert('An unexpected error has occurred. Please try again..');", true); } }
protected void Publish_Click(Object sender, EventArgs e) { Stories _st = null; foreach (GridViewRow I in dgStories.Rows) { Label _id = (Label)I.FindControl("lbl_StorId"); if (_id != null) { DropDownList _ddst = (DropDownList)I.FindControl("dd_Status"); _st = new Stories(this.ConnectionString); _st.LitePopulate(_id.Text, false); if (!_st.Status.ToString().Equals(_ddst.SelectedValue)) { _st.Status = Convert.ToInt32(_ddst.SelectedValue); _st.Save(); } } } this.DataBind(); }
protected void Save_Click(object sender, EventArgs e) { Stories _stor = new Stories(this.ConnectionString); if (ViewState["storId"] != null) { _stor.LitePopulate(Convert.ToInt32(ViewState["storId"]), false); } if (IsValidStory(_stor)) { _stor.Title = HttpUtility.HtmlEncode(txt_Title.Text); _stor.Story = HttpUtility.HtmlEncode(txt_Story.Text); _stor.Status = Convert.ToInt32(dd_Status.SelectedValue); _stor.CategoryId = Convert.ToInt32(dd_Category.SelectedValue); String _imgType = null; if (ViewState["storId"] != null) { if (fu_Image.HasFile) { _stor.YouTubeLink = ""; _imgType = fu_Image.FileName.Split('.')[1]; _stor.ImgType = _imgType; } else { if (!String.IsNullOrEmpty(txt_YouTube.Text)) { _stor.YouTubeLink = GetYouTubeLink(); _stor.ImgType = ""; } } } else { if (fu_Image.HasFile) { _stor.YouTubeLink = ""; _imgType = fu_Image.FileName.Split('.')[1]; _stor.ImgType = _imgType; } else { _stor.YouTubeLink = GetYouTubeLink(); _stor.ImgType = ""; } } if (_stor.Save()) { if (fu_Image.HasFile) { String _path = Server.MapPath(String.Format(ConfigurationManager.AppSettings["StoriesImagesPath"], _stor.ID.ToString(), _imgType)); fu_Image.SaveAs(_path); } this.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", "alert('Record has been updated successfully.');self.location = 'StoriesList.aspx';", true); } else { lbl_Error.Text = "An unexpected error has occurred. Please try again."; lbl_Error.Visible = true; } } }