protected void CreateUserWizard1_FinishButtonClick(object sender, LoginCancelEventArgs e)
        {
            var myuserID = System.Web.Security.Membership.GetUser(CreateUserWizard1.UserName).ProviderUserKey;

            //make sure there is no user with that email address
            using (var db = new textbookbasicEntitiesContext())
            {
                var email = (CreateUserWizard1.FindControl("Email") as Literal).Text;

                if (db.sellers.Any(y => y.email == email))
                {
                    e.Cancel = true;
                    CreateUserWizard1.FinishDestinationPageUrl = String.Empty;
                }


                //insert info into database
                db.sellers.Add(
                    new seller()
                {
                    userID      = (Guid)myuserID,
                    firstName   = (CreateUserWizard1.FindControl("firstname") as Literal).Text,
                    lastName    = (CreateUserWizard1.FindControl("lastname") as Literal).Text,
                    campus      = Convert.ToInt32((CreateUserWizard1.FindControl("campus") as DropDownList).SelectedValue),
                    userType    = 1,
                    email       = (CreateUserWizard1.FindControl("Email") as Literal).Text,
                    prefContact = Convert.ToInt32((CreateUserWizard1.FindControl("prefcontact") as DropDownList).SelectedValue),
                    contactInfo = (CreateUserWizard1.FindControl("contactinfo") as Literal).Text,
                });

                db.SaveChanges();
            }
        }
Esempio n. 2
0
 protected void Prerender(object sender, EventArgs e)
 {
     using (var db = new textbookbasicEntitiesContext())
     {
         if (searchBox.Text != "")
         {
             ListView2.DataSource = db.books.Where(v => v.ISBN.Contains(searchBox.Text) || v.Title.Contains(searchBox.Text)).ToList();
         }
         else
         {
             ListView2.DataSource = db.books.ToList();
         }
         ListView2.DataBind();
     }
 }
        protected void CreateUserWizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            var myuserID = System.Web.Security.Membership.GetUser(CreateUserWizard1.UserName).ProviderUserKey;

            //make sure there is no user with that email address
            using (var db = new textbookbasicEntitiesContext())
            {
                var emailadd = (CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email") as TextBox).Text;

                if (db.sellers.Any(y => y.email == emailadd))
                {
                    e.Cancel = true;
                    CreateUserWizard1.FinishDestinationPageUrl = String.Empty;
                    System.Web.Security.Membership.DeleteUser(CreateUserWizard1.UserName);
                    (CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("complete") as Literal).Text = "there was an error";
                }
                //get data
                var          userID       = (Guid)myuserID;
                TextBox      firstNametxt = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("firstname") as TextBox;
                TextBox      lastNametxt  = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("lastname") as TextBox;
                DropDownList campusd      = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("campus") as DropDownList;

                DropDownList prefContactd   = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("prefcontact") as DropDownList;
                TextBox      contactInfotxt = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("contactinfo") as TextBox;

                if (userID == null || firstNametxt == null || lastNametxt == null || campusd == null || prefContactd == null || contactInfotxt == null)
                {
                    throw new Exception("something didnt casrt right");
                }


                //insert info into database
                db.sellers.Add(
                    new seller()
                {
                    userID      = (Guid)myuserID,
                    firstName   = firstNametxt.Text,
                    lastName    = lastNametxt.Text,
                    campus      = Convert.ToInt32(campusd.SelectedValue),
                    userType    = 1,
                    email       = emailadd,
                    prefContact = Convert.ToInt32((CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("prefcontact") as DropDownList).SelectedValue),
                    contactInfo = (CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("contactinfo") as Literal).Text,
                });

                db.SaveChanges();
            }
        }
        //before user created check that no user with that email
        protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
        {
            using (var db = new textbookbasicEntitiesContext())
            {
                var email = (TextBox)(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email"));
                if (email == null)
                {
                    throw new Exception();
                }
                string emailadd = email.Text;

                if (db.sellers.Any(y => y.email == emailadd))
                {
                    e.Cancel = true;
                    CreateUserWizard1.FinishDestinationPageUrl = String.Empty;
                    // throw new Exception();
                }
            }
        }
        protected void addBook_button_Click(object sender, EventArgs e)
        {
            string path      = null;
            string shortpath = null;

            if (FileUpload1.HasFile)
            //file is up to 4mb
            {     //make sure file is image and in right format
                try
                { //check content is image
                    if (FileUpload1.PostedFile.ContentType.ToLower() != "image/jpg" &&
                        FileUpload1.PostedFile.ContentType.ToLower() != "image/jpeg" &&
                        FileUpload1.PostedFile.ContentType.ToLower() != "image/gif" &&
                        FileUpload1.PostedFile.ContentType.ToLower() != "image/png")
                    {
                        //ERROR
                        throw new Exception("not image");
                    }
                    //check if file extension is not one of above (you can rename extension so do other check first)
                    else if (Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower() != ".jpg" &&
                             Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower() != ".png" &&
                             Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower() != ".gif" &&
                             Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower() != ".jpeg")
                    {
                        //ERROR
                        throw new Exception("not an image");
                    }

                    path = Server.MapPath("~/img/books/") +
                           Path.GetFileName(FileUpload1.PostedFile.FileName);
                    shortpath = "~/img/books/" + Path.GetFileName(FileUpload1.PostedFile.FileName);
                    FileUpload1.SaveAs(path);

                    Label1.Text = "File name: " +
                                  path + "<br/>" +
                                  FileUpload1.PostedFile.ContentLength + " kb<br/>" +
                                  "Content type: " +
                                  FileUpload1.PostedFile.ContentType;
                }
                catch (Exception ex)
                {
                    Label1.Text = "ERROR: " + ex.Message.ToString();
                }
            }
            else
            {
                Label1.Text = "You have not specified a file.";
            }


            using (var db = new textbookbasicEntitiesContext())
            {
                var currUser = (Guid)(System.Web.Security.Membership.GetUser().ProviderUserKey);
                int x;
                db.books.Add(new book()
                {
                    ISBN   = isbn.Text,
                    Title  = titletb.Text,
                    Author = author.Text,
                    //allowed to have null
                    Edition  = Int32.TryParse(edition.Text, out x)? (int?)x:null,
                    imageurl = shortpath ?? "~/img/books/na.jpg",
                    sellerID = currUser
                }
                             );


                //  try
                //  {

                db.SaveChanges();
                Response.Redirect("searchBooks.aspx");
                //  }
                //  catch(Exception o)
                //  {

                //  }
            }
        }