示例#1
0
    /* NEW RECIPE */

    protected void addRecipeInRecipes()
    {
        string insertRecipe = "INSERT INTO Recipes (UserID, Title, Description, Servings, TimePreparation, ImageURL, Status, CategoryID, Mark, NComments) " +
                              "VALUES (@Uid,@title, @desc, @servs, @time, @imgName, @st, @Cid, @mark, @ncomm)";
        SqlCommand cmdRecipe = new SqlCommand(insertRecipe, conn);

        cmdRecipe.Parameters.AddWithValue("@Uid", UserID.ToString());
        cmdRecipe.Parameters.AddWithValue("@title", recipetitle.Text.Trim());
        cmdRecipe.Parameters.AddWithValue("@desc", TextBox2.Text.Trim());
        cmdRecipe.Parameters.AddWithValue("@servs", Convert.ToInt16(numberservings.Text.Trim()));
        cmdRecipe.Parameters.AddWithValue("@time", preptime.Text.Trim());
        cmdRecipe.Parameters.AddWithValue("@st", "False"); // treba admin da go approve
        cmdRecipe.Parameters.AddWithValue("@Cid", categoryChooser.SelectedValue);
        cmdRecipe.Parameters.AddWithValue("@mark", 0);
        cmdRecipe.Parameters.AddWithValue("@ncomm", 0);


        // recipe image
        if (recipePicFile.HasFile)
        {
            string   profilePic = recipePicFile.FileName;
            string[] chopped    = profilePic.Split('.');
            string   extension  = chopped.ElementAt(chopped.Count() - 1);

            // ja zacuvuvam original vo tmp
            // tie sto si gi stavivme manuelno kje ni bidat so recipe id,
            // drugive so guid

            Guid   guid = Guid.NewGuid();
            string path = Server.MapPath("~/Images/recipesImages/tmp/" + guid + "." + extension);
            recipePicFile.PostedFile.SaveAs(path);

            // resizing 350-350
            System.Drawing.Image img       = System.Drawing.Image.FromFile(path);
            ImageFormat          imgFormat = img.RawFormat;
//________________________________________________________________________________________________________________________________SERVICE____________________
            SizeScaleService ssService = new SizeScaleService();

            List <float> scaledSize = ssService.scaleSize(450, 450, img.Width, img.Height);
            //________________________________________________________________________________________________________________________________SERVICE____________________

            Bitmap newImg   = new Bitmap(img, (int)scaledSize[0], (int)scaledSize[1]);
            string destPath = Server.MapPath("~/Images/recipesImages/" + guid + "." + extension);
            newImg.Save(destPath, imgFormat);


            //// izbrishi od tmp originalna
            //if (System.IO.File.Exists(path))
            //{
            //    System.IO.File.Delete(path);
            //}

            cmdRecipe.Parameters.AddWithValue("@imgName", guid + "." + extension);

            Debug.WriteLine("*************** IMAGE *******************");
        }
        else
        {
            Debug.WriteLine("*************** NO IMAGE *******************");
        }

        try
        {
            conn.Open();
            cmdRecipe.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
        finally
        {
            conn.Close();
        }
    }
示例#2
0
    protected void updateProfile(object sender, EventArgs e)
    {
        bool   newPic    = false;
        string extension = "";

        // update napravi na slikata t.s. starata ja stavame vo tmp (ako se sluci greska pri apdejtuvanje da ne se izgubi)
        // novata ja zacuvuvame kaj sto treba i potoa starata ja brisheme od tmp
        if (fileUploadPic.HasFile)
        {
            newPic = true;
            string   profilePic = fileUploadPic.FileName;
            string[] chopped    = profilePic.Split('.');
            extension = chopped.ElementAt(chopped.Count() - 1);

            string path         = Server.MapPath("~/User/ProfilePictures/" + User.Identity.Name + "." + extension);
            string pathStandard = Server.MapPath("~/User/ProfilePictures/standard/" + User.Identity.Name + "." + extension);
            string pathThumb    = Server.MapPath("~/User/ProfilePictures/thumbs/" + User.Identity.Name + "." + extension);

            // starata originalna ja brisham
            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }
            else if (System.IO.File.Exists(pathStandard))
            {
                System.IO.File.Delete(pathStandard);
            }
            else if (System.IO.File.Exists(pathThumb))
            {
                System.IO.File.Delete(pathThumb);
            }

            // ja zacuvuvam originalnata nova
            fileUploadPic.PostedFile.SaveAs(path);

            // resizing thumbs
            System.Drawing.Image img       = System.Drawing.Image.FromFile(path);
            ImageFormat          imgFormat = img.RawFormat;
            //___________________________________________________________________________________________________________________________________SERVICE____________________

            SizeScaleService ssService = new SizeScaleService();


            List <float> scaledSize = ssService.scaleSize(200, 200, img.Width, img.Height);
            Bitmap       newImg     = new Bitmap(img, (int)scaledSize[0], (int)scaledSize[1]);
            string       destPath   = Server.MapPath("~/User/ProfilePictures/thumbs/" + User.Identity.Name + "." + extension);
            newImg.Save(destPath, imgFormat);

            // resizing standard
            img       = System.Drawing.Image.FromFile(path);
            imgFormat = img.RawFormat;

            ssService.scaleSize(300, 300, img.Width, img.Height);
            //___________________________________________________________________________________________________________________________________SERVICE____________________
            newImg   = new Bitmap(img, (int)scaledSize[0], (int)scaledSize[1]);
            destPath = Server.MapPath("~/User/ProfilePictures/standard/" + User.Identity.Name + "." + extension);
            newImg.Save(destPath, imgFormat);

            // sega na serverska strana zacuvana mi e novata slika
        }


        string updateCmd = "UPDATE aspnet_Users SET ProfilePicture=@ProfilePicture, " +
                           "Expertise=@Expertise, AboutMe=@AboutMe, Facebook=@Facebook, " +
                           "Twitter=@Twitter, Linkedin=@Linkedin, Youtube=@Youtube, " +
                           "Skype=@Skype WHERE UserId=@UserId";

        SqlCommand cmd = new SqlCommand(updateCmd, conn);

        if (newPic)
        {
            cmd.Parameters.AddWithValue("ProfilePicture", User.Identity.Name + "." + extension);
        }
        else
        {
            // istata ostanuva
            cmd.Parameters.AddWithValue("ProfilePicture", data["ProfilePicture"].ToString());
        }

        if (culExpertise.SelectedItem != null)
        {
            cmd.Parameters.AddWithValue("Expertise", culExpertise.SelectedItem.Text);
        }
        else
        {
            cmd.Parameters.AddWithValue("Expertise", DBNull.Value);
        }

        Debug.WriteLine("ABOUT ME: " + aboutMe.Text);
        if (aboutMe.Text.Trim() != "")
        {
            cmd.Parameters.AddWithValue("AboutMe", aboutMe.Text.Trim());
        }
        else
        {
            cmd.Parameters.AddWithValue("AboutMe", DBNull.Value);
        }

        if (fb.Text.Trim() != "")
        {
            cmd.Parameters.AddWithValue("Facebook", fb.Text.Trim());
        }
        else
        {
            cmd.Parameters.AddWithValue("Facebook", DBNull.Value);
        }

        if (twitter.Text.Trim() != "")
        {
            cmd.Parameters.AddWithValue("Twitter", twitter.Text.Trim());
        }
        else
        {
            cmd.Parameters.AddWithValue("Twitter", DBNull.Value);
        }

        if (linkedin.Text.Trim() != "")
        {
            cmd.Parameters.AddWithValue("Linkedin", linkedin.Text.Trim());
        }
        else
        {
            cmd.Parameters.AddWithValue("Linkedin", DBNull.Value);
        }

        if (youtube.Text.Trim() != "")
        {
            cmd.Parameters.AddWithValue("Youtube", youtube.Text.Trim());
        }
        else
        {
            cmd.Parameters.AddWithValue("Youtube", DBNull.Value);
        }

        if (skype.Text.Trim() != "")
        {
            cmd.Parameters.AddWithValue("Skype", skype.Text.Trim());
        }
        else
        {
            cmd.Parameters.AddWithValue("Skype", DBNull.Value);
        }

        cmd.Parameters.AddWithValue("UserId", UserID);

        try
        {
            conn.Open();
            int result = cmd.ExecuteNonQuery();
            Debug.WriteLine("AFTER UPDATE: " + result);
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
        finally
        {
            conn.Close();
        }

        loadProfileInfo(userId);
    }