public void Add_Recipe(Object s, EventArgs e) { if (Authentication.IsUserAuthenticated) { if (Page.IsValid) { Utility Util = new Utility(); int categoryid = int.Parse(Request.Form[CategoryID.UniqueID]); IDataReader dr = Blogic.ActionProcedureDataProvider.GetSpiderLyrics(categoryid); while (dr.Read()) { LyricRepository lyric = new LyricRepository(); //Filters harmful scripts from input string. if (dr["Title"] != DBNull.Value) { lyric.LyricName = (string)dr["Title"].ToString().Trim(); } if (dr["Author"] != DBNull.Value) { lyric.Author = (string)dr["Author"].ToString().Trim(); } if (dr["Lyric"] != DBNull.Value) { lyric.Ingredients = (string)dr["Lyric"].ToString().Trim(); } lyric.CatID = int.Parse(Request.Form[CategoryID.UniqueID]); lyric.Instructions = ""; lyric.UID = UserIdentity.UserID; lyric.Add(lyric); lyric = null; } //EmailRecipeSubmissionNotificationToAdministrator(Lyric.LyricName); Response.Redirect("confirmaddeditlyric.aspx?mode=Added"); Util = null; } } }
public void Add_Recipe(Object s, EventArgs e) { if (Authentication.IsUserAuthenticated) { if (Page.IsValid) { Utility Util = new Utility(); LyricRepository lyric = new LyricRepository(); //Filters harmful scripts from input string. lyric.LyricName = Util.FormatTextForInput(Request.Form[Name.UniqueID]); lyric.Author = Util.FormatTextForInput(Request.Form[Author.UniqueID]); lyric.CatID = int.Parse(Request.Form[CategoryID.UniqueID]); lyric.Ingredients = Util.FormatTextForInput(Request.Form[Ingredients.UniqueID]); lyric.Instructions = Util.FormatTextForInput(Request.Form[Instructions.UniqueID]); lyric.UID = UserIdentity.UserID; #region Form Input Validator //Validate for empty recipe name if (lyric.LyricName.Length == 0) { lbvalenght.Text = "<br>Error: lyric Name is empty, please enter a recipe name."; lbvalenght.Visible = true; return; } if (lyric.CatID == 0) { lbvalenght.Text = "<br>Error: You must select a category where you want your recipe to show."; lbvalenght.Visible = true; return; } //Validate for empty author name if (lyric.Author.Length == 0) { lbvalenght.Text = "<br>Error: Author Name is empty, please enter the author name"; lbvalenght.Visible = true; return; } //Validate for empty ingredients if (lyric.Ingredients.Length == 0) { lbvalenght.Text = "<br>Error: Ingredients is empty, please enter an ingredients."; lbvalenght.Visible = true; return; } //Validate for empty instruction if (lyric.Instructions.Length == 0) { lbvalenght.Text = "<br>Error: Instructions is empty, please enter an instruction."; lbvalenght.Visible = true; return; } //lyric name maximum of 50 char allowed if (lyric.LyricName.Length > 50) { lbvalenght.Text = "<br>Error: lyric Name is too long. Max of 50 characters."; lbvalenght.Visible = true; Name.Value = ""; return; } //Author name maximum of 25 char allowed if (lyric.Author.Length > 25) { lbvalenght.Text = "<br>Error: Author Name is too long. Max of 25 characters."; lbvalenght.Visible = true; Author.Value = ""; return; } //Ingredients maximum of 1000 char allowed - can be increase to max of 1000 char. //if (lyric.Ingredients.Length > 500) //{ // lbvalenght.Text = "<br>Error: Ingredients is too long. Max of 500 characters."; // lbvalenght.Visible = true; // return; //} //Instruction maximum of 750 char allowed - can be increase to max of 2000 char //if (lyric.Instructions.Length > 750) //{ // lbvalenght.Text = "<br>Error: Instructions is too long. Max of 700 characters."; // lbvalenght.Visible = true; // return; //} #endregion if (RecipeImageFileUpload.HasFile) { int FileSize = RecipeImageFileUpload.PostedFile.ContentLength; string contentType = RecipeImageFileUpload.PostedFile.ContentType; //File type validation if (!contentType.Equals("image/gif") && !contentType.Equals("image/jpeg") && !contentType.Equals("image/jpg") && !contentType.Equals("image/png")) { lbvalenght.Text = "<br>Định dạng file không đúng. chỉ cho phép định dạng file: gif, jpg, jpeg or png."; lbvalenght.Visible = true; return; } // File size validation if (FileSize > constant.RecipeImageMaxSize) { lbvalenght.Text = "<br>Kích thước file cho phép không quá 30000 bytes"; lbvalenght.Visible = true; return; } } ImageUploadManager.UploadRecipeImage(lyric, PlaceHolder1, GetLyricImage.ImagePathDetail, constant.RecipeImageMaxSize, false); if (lyric.Add(lyric) != 0) { JSLiteral.Text = "Quá trình sử lý thất bại."; return; } EmailRecipeSubmissionNotificationToAdministrator(lyric.LyricName); lyric = null; Response.Redirect("confirmaddeditlyric.aspx?mode=Added"); Util = null; } } }