protected void btnUpload_Click(object sender, EventArgs e)
        {
            try
            {
                // Before attempting to save the file, verify
                // that the FileUpload control contains a file.
                if (fuPhoto.HasFile)
                {
                    // Call a helper method routine to save the file.
                    SaveFile(fuPhoto.PostedFile);
                    lblMessage.Text = "File uploaded";
                }
                else
                {
                    savePath = Server.MapPath("Images");
                    string fileName = "CoverNull.png";
                    string pathToCheck = Path.Combine(savePath, fileName);

                    Book book = new Book();
                    book.PhotoName = pathToCheck;
                    User user = new User();
                    user = (User)Session["User"];
                    book.Title = txtTitle.Text;
                    book.Price = txtPrice.Text;
                    book.BookTypeID = new Guid(ddlGenre.SelectedValue);
                    user.Books.List.Add(book);
                    user.Save();
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }
Beispiel #2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                User user = new User();
                user = user.Login(txtUserName.Text, txtPassword.Text);
                Session.Add("User", user);

                LinkButton lnkLogon = (LinkButton)Master.FindControl("lnkLogin");
                lnkLogon.Visible = false;

                LinkButton lnkExit = (LinkButton)Master.FindControl("lnkLogout");
                lnkExit.Visible = true;
                if (user.Version == 0)
                {
                    Response.Redirect("ChangePassword.aspx");
                }
                else
                {
                    Response.Redirect("Default.aspx");
                }
            }
            catch (ApplicationException ex)
            {
                lblStatus.Text = "Login failed, please try again.";
            }
            catch (Exception ex)
            {
                lblStatus.Text = ex.Message;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            book = (Book)Session["Book"];
            book.BookTypeID = new Guid(ddlGenre.SelectedValue);
            book.Title = txtTitle.Text;
            book.Price = txtPrice.Text;
            if (fuPhoto.HasFile)
            {

                savePath = Server.MapPath("Images");
                string fileName = fuPhoto.FileName;
                string pathToCheck = Path.Combine(savePath, fileName);

                book.PhotoName = pathToCheck;

            }
            else
            {
                savePath = Server.MapPath("Images");
                book.PhotoName = Path.Combine(savePath, book.ID + book.MimeType);
            }
            User user = new User();
            user = (User)Session["User"];
            user.Books.List.Add(book);
            user.Save();
        }
 protected void btnForgot_Click(object sender, EventArgs e)
 {
     User user = new User();
     if (user.Recover(txtEmail.Text))
     {
         Session.Add("User", user);
         lblQuestion.Text = user.GetQuestion();
         btnSend.Visible = true;
         btnForgot.Visible = false;
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            user = (User)Session["User"];
            ReviewList rl = new ReviewList();
            rl = rl.GetByUserID(user.ID);

            lblRegistered.Text = user.DateCreated.ToString();
            TimeSpan DateDiff = (d1 - user.DateCreated);
            double PostPerDay = user.UserBooks.Count / DateDiff.TotalDays;
            lblPostsMade.Text = rl.Count + " (" + Math.Round(PostPerDay, 2) + " per day)";
            lblBooksPosted.Text = user.UserBooks.Count.ToString();
        }
 protected void btnPost_Click(object sender, EventArgs e)
 {
     Review br = new Review();
     User user = new User();
     user = (User)Session["User"];
     br.Title = txtTitle.Text;
     br.BookReview = txtBody.Text;
     br.UserID = user.ID;
     br.BookID = book.ID;
     book.Reviews.List.Add(br);
     book.Save();
     Response.Redirect("default.aspx");
 }
 protected void btnChangePass_Click(object sender, EventArgs e)
 {
     if (txtCurrentPass.Text == user.Password.ToString())
     {
         if (txtNewPass.Text == txtConfirmPass.Text)
         {
             user = user.ChangePassword(txtNewPass.Text);
             Response.Redirect("Profile.aspx");
         }
         else
         {
             Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallMyFunction", "DoesNotMatch()", true);
         }
     }
     else
     {
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallMyFunction", "WrongCurrent()", true);
     }
 }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                User user = new User();
                user = user.Register(txtEmail.Text, txtFirstName.Text, txtLastName.Text, txtUserName.Text,
                    txtQuestion1.Text, txtAnswer1.Text, txtQuestion2.Text, txtAnswer2.Text, txtQuestion3.Text, txtAnswer3.Text);

                if (user == null)
                {
                    lblNameValidate.Text = "User name already taken";
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "CheckMail()", true);
                    Response.Redirect("Login.aspx?Login=first");
                }
            }
            catch (Exception ex)
            {
                lblNameValidate.Text = ex.Message;
            }
        }
        void SaveFile(HttpPostedFile file)
        {
            // Specify the path to save the uploaded file to.
             savePath = Server.MapPath("Images");

            // Get the name of the file to upload.
            string fileName = fuPhoto.FileName;

            // Create the path and file name to check for duplicates.
            string pathToCheck = Path.Combine(savePath, fileName);

            // Create a temporary file name to use for checking duplicates.
            string tempfileName = "";

            // Check to see if a file already exists with the
            // same name as the file to upload.
            if (System.IO.File.Exists(pathToCheck))
            {
                int counter = 2;
                while (System.IO.File.Exists(pathToCheck) == true)
                {
                    // if a file with this name already exists,
                    // prefix the filename with a number.
                    tempfileName = counter.ToString() + fileName;
                    pathToCheck = Path.Combine(savePath, tempfileName);
                    counter++;
                }

                fileName = tempfileName;

                // Notify the user that the file name was changed.
                lblMessage.Text = "A file with the same name already exists." +
                    "<br />Your file was saved as " + fileName;

                // Append the name of the file to upload to the path.
                savePath = Path.Combine(savePath, fileName);

                // Call the SaveAs method to save the uploaded
                // file to the specified directory.
                fuPhoto.SaveAs(savePath);

                Book book = new Book();
                book.PhotoName = savePath;
                User user = new User();
                user = (User)Session["User"];
                book.Title = txtTitle.Text;
                book.Price = txtPrice.Text;
                book.BookTypeID = new Guid(ddlGenre.SelectedValue);
                user.Books.List.Add(book);
                user.Save();
            }
            else
            {
                // Append the name of the file to upload to the path.
                savePath = Path.Combine(savePath, fileName);

                // Call the SaveAs method to save the uploaded
                // file to the specified directory.
                fuPhoto.SaveAs(savePath);

                ////XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                Book book = new Book();
                book.PhotoName = savePath;
                User user = new User();
                user = (User)Session["User"];
                book.Title = txtTitle.Text;
                book.Price = txtPrice.Text;
                book.BookTypeID = new Guid(ddlGenre.SelectedValue);
                user.Books.List.Add(book);
                user.Save();

                // Notify the user that the file was saved successfully.

                lblMessage.Text = "Your file was uploaded successfully.";
                //Response.Redirect("UploadPhoto.aspx");
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     user = (User)Session["User"];
 }