Exemplo n.º 1
0
    public void Update_Recipe(object sender, EventArgs e)
    {
        LyricRepository lyric = new LyricRepository();

        lyric.UID = int.Parse(Request.Form["Userid"]);
        lyric.ID = (int)Util.Val(Request.QueryString["id"]);
        lyric.LyricName = Request.Form["Name"];
        lyric.Author = Request.Form["Author"];
        lyric.CatID = int.Parse(Request.Form["CategoryID"]);
        lyric.Ingredients = Request.Form["Ingredients"];
        lyric.Instructions = Request.Form["Instructions"];
        lyric.Hits = int.Parse(Request.Form["Hits"]);

        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>File format is invalid. Only gif, jpg, jpeg or png files are allowed.";
                lbvalenght.Visible = true;
                return;
            }
            // File size validation
            if (FileSize > constant.RecipeImageMaxSize)
            {
                lbvalenght.Text = "<br>File size exceed the maximun allowed 30000 bytes";
                lbvalenght.Visible = true;
                return;
            }
        }

        ImageUploadManager.UploadRecipeImage(lyric, PlaceHolder1, GetLyricImage.ImagePath, constant.RecipeImageMaxSize, true);

        if (lyric.Update(lyric) != 0)
        {
            JSLiteral.Text = Util.JSProcessingErrorAlert;
            return;
        }

        string strURLRedirect;
        strURLRedirect = "confirmdel.aspx?catname=" + lyric.LyricName + "&mode=update";

        lyric = null;

        Response.Redirect(strURLRedirect);
    }
Exemplo n.º 2
0
    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;
            }
        }
    }
Exemplo n.º 3
0
    //Handle the category delete
    public void Delete_Category(Object s, EventArgs e)
    {
        LyricRepository Category = new LyricRepository();

        Category.CatID = int.Parse(Request.Form["CategoryID"]);

        Caching.PurgeCacheItems("MainCourse_LyricCategory");
        Caching.PurgeCacheItems("Ethnic_LyricCategory");
        Caching.PurgeCacheItems("MainCourse_LyricCategory");
        Caching.PurgeCacheItems("Submission_RecipeCategory");

        //Notify user if error occured.
        if (Category.DeleteCategory(Category) != 0)
        {
            JSLiteral.Text = "Error occured while processing your submit.";
            return;
        }

        Category = null;

        Response.Redirect("confirmcatedit.aspx?catname=" + Request.Form["CategoryName"] + "&mode=del");
    }
Exemplo n.º 4
0
        public static void UploadRecipeImage(LyricRepository Lyric, PlaceHolder ph, string directory, int maxsize, bool IsEdit)
        {
            FileUpload ImageUpload = (FileUpload)(ph.FindControl("RecipeImageFileUpload"));

            if (ImageUpload.HasFile) //Check if there is a file
            {
                //Constant variables
                string Directory = directory;
                int maxFileSize = maxsize;

                int FileSize = ImageUpload.PostedFile.ContentLength; //Get th file lenght
                string contentType = ImageUpload.PostedFile.ContentType; // Get the file type
                string FileExist = Directory + ImageUpload.PostedFile.FileName; // Get the filename from the directory and compare
                string FileName = Path.GetFileNameWithoutExtension(ImageUpload.PostedFile.FileName); //Get the posted filename
                string FileExtention = Path.GetExtension(ImageUpload.PostedFile.FileName); //Get the posted file extension
                string FilePath;
                string FileNameWithExtension;

                //File type validation
                if (!contentType.Equals("image/gif") &&
                    !contentType.Equals("image/jpeg") &&
                    !contentType.Equals("image/jpg") &&
                    !contentType.Equals("image/png"))
                {
                    return;
                }
                // File size validation
                else if (FileSize > maxFileSize)
                {
                    return;
                }
                else
                {
                    //Check wether the image name already exist.
                    //If the image name already exist, append a random
                    //numeric and letter to ensure the image name is always unqiue.
                    if (File.Exists(HttpContext.Current.Server.MapPath(FileExist)))
                    {
                        //Create a random alpha numeric to make sure the updated image name is unique.
                        Random rand = new Random((int)DateTime.Now.Ticks);
                        int randnum = rand.Next(1, 10);
                        int CharCode = rand.Next(Convert.ToInt32('a'), Convert.ToInt32('z'));
                        char RandomChar = Convert.ToChar(CharCode);

                        //Get directory, the file name and the extension.
                        FilePath = string.Concat(Directory, FileName + randnum + RandomChar, "", FileExtention);

                        //Joined the filename and extension to insert into the database.
                        FileNameWithExtension = FileName + randnum + RandomChar + FileExtention;

                        //Initialize Add recipe object property to get the full image name
                        Lyric.LyricImage = FileNameWithExtension;

                        try
                        {
                            //Save the recipe image to the specified directory
                            //Make sure the "LyricImage" folder has write permission to upload image
                            ImageUpload.SaveAs(HttpContext.Current.Server.MapPath(FilePath));

                        }
                        catch
                        {

                        }
                    }
                    else
                    {
                        //Get directory, the file name and the extension.
                        FilePath = string.Concat(Directory, FileName, "", FileExtention);

                        //Joined the filename and extension to insert into the database.
                        FileNameWithExtension = FileName + FileExtention;

                        //Initialize Add recipe object property to get the full image name
                        Lyric.LyricImage = FileNameWithExtension;

                        try
                        {
                            //Save the recipe image to the specified directory
                            //Make sure the "LyricImage" folder has write permission to upload image
                            ImageUpload.SaveAs(HttpContext.Current.Server.MapPath(FilePath));

                        }
                        catch
                        {

                        }
                    }
                }
            }
            else
            {
                if (!IsEdit)
                {
                    //If there is no image to be uploaded, then assign an empty string to the property
                    Lyric.LyricImage = string.Empty;
                }
                else
                {
                    //This section is executed if the input file is empty.
                    //Then it check if an image filename exist in the database.
                    //If it exist, just update it with the same value, else update it with an empty string.
                    IDataReader dr = Blogic.ActionProcedureDataProvider.GetLyricImageFileNameForUpdate(Lyric.ID);

                    dr.Read();

                    if (dr["LyricImage"] != DBNull.Value)
                    {
                        Lyric.LyricImage = (string)dr["LyricImage"];
                    }
                    else
                    {
                        Lyric.LyricImage = string.Empty;
                    }

                    dr.Close();
                }
            }
        }
Exemplo n.º 5
0
    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;
            }
        }
    }
Exemplo n.º 6
0
    //Handle the delete button click event
    public void Delete_Recipes(object sender, DataGridCommandEventArgs e)
    {
        if ((e.CommandName == "Delete"))
        {
            TableCell iIdNumber2 = e.Item.Cells[0];
            TableCell iIRecipename = e.Item.Cells[1];

            #region Delete Lyric Image
            //Delete the recipe image if the recipe has an image.

            try
            {
                IDataReader dr = Blogic.ActionProcedureDataProvider.GetLyricImageFileNameForUpdate(int.Parse(iIdNumber2.Text));

                dr.Read();

                if (dr["LyricImage"] != DBNull.Value)
                {
                    System.IO.File.Delete(Server.MapPath(GetLyricImage.ImagePath + dr["LyricImage"].ToString()));
                }

                dr.Close();
            }
            catch
            {
            }
            #endregion

            //Refresh cached data
            Caching.PurgeCacheItems("MainCourse_LyricCategory");
            Caching.PurgeCacheItems("Ethnic_LyricCategory");
            Caching.PurgeCacheItems("MainCourse_LyricCategory");
            Caching.PurgeCacheItems("Newest_LyricsSideMenu_");

            LyricRepository Lyric = new LyricRepository();

            Lyric.ID = int.Parse(iIdNumber2.Text);

            //Perform delete recipe
            Lyric.Delete(Lyric);

            Lyric = null;

            //Redirect to confirm delete page
            strURLRedirect = "confirmdel.aspx?catname=" + iIRecipename.Text + "&mode=del";
            Server.Transfer(strURLRedirect);
        }
    }
Exemplo n.º 7
0
    public void Update_Recipe(Object s, EventArgs e)
    {
        if (Page.IsValid && Authentication.IsUserAuthenticated)
        {
            LyricRepository lyric = new LyricRepository();

            lyric.UID = UserIdentity.UserID;
            lyric.ID = (int)Util.Val(Request.QueryString["id"]);
            lyric.LyricName = Util.FormatTextForInput(Request.Form[Name.UniqueID]);
            lyric.CatID = int.Parse(Request.Form[CategoryID.UniqueID]);
            lyric.Ingredients = Request.Form[Ingredients.UniqueID];
            lyric.Instructions = Request.Form[Instructions.UniqueID];
            lyric.Hits = int.Parse(Request.Form[Hits.UniqueID]);

            lyric.UrlMusic = Util.FormatTextForInput(Request.Form[UrlMusic.UniqueID]);
            lyric.UrlChacha = Util.FormatTextForInput(Request.Form[UrlChacha.UniqueID]);
            lyric.UrlZing = Util.FormatTextForInput(Request.Form[UrlZing.UniqueID]);
            lyric.UrlYoutube = Util.FormatTextForInput(Request.Form[UrlYoutube.UniqueID]);

            #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;
            }
            //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;
                return;
            }
            //Ingredients maximum of 500 char allowed - can be increase to max 1000 characters.
            //if (Lyric.Ingredients.Length > 1500)
            //{
            //    lbvalenght.Text = "<br>Error: Ingredients is too long. Max of 1000 characters.";
            //    lbvalenght.Visible = true;
            //    return;
            //}
            //Instruction maximum of 750 char allowed - can be increase to max 2000 characters.
            //if (Lyric.Instructions.Length > 2000)
            //{
            //    lbvalenght.Text = "<br>Error: Instructions is too long. Max of 2000 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>File format is invalid. Only gif, jpg, jpeg or png files are allowed.";
                    lbvalenght.Visible = true;
                    return;
                }
                // File size validation
                if (FileSize > constant.RecipeImageMaxSize)
                {
                    lbvalenght.Text = "<br>File size exceed the maximun allowed 30000 bytes";
                    lbvalenght.Visible = true;
                    return;
                }
            }

            ImageUploadManager.UploadRecipeImage(lyric, PlaceHolder1, GetLyricImage.ImagePathDetail, constant.RecipeImageMaxSize, true);

            //Refresh cache
            Caching.PurgeCacheItems("MainCourse_LyricCategory");
            Caching.PurgeCacheItems("Ethnic_LyricCategory");
            Caching.PurgeCacheItems("MainCourse_LyricCategory");
            Caching.PurgeCacheItems("Newest_LyricsSideMenu_");

            if (lyric.Update(lyric) != 0)
            {
                JSLiteral.Text = Util.JSProcessingErrorAlert;
                return;
            }

            lyric = null;

            Response.Redirect("confirmaddeditlyric.aspx?mode=Updated&recipename=" + Request.Form[Name.UniqueID] + "&id=" + int.Parse(Request.QueryString["id"]));
        }
    }