protected void Btn_Submit_Click(object sender, EventArgs e)
        {
            using (BookSaleEntities Entities = new BookSaleEntities())
            {
                /*check database whether the user already exists*/
                if (Entities.Users.FirstOrDefault(u => u.username.ToLower() == TxtUserName.Text.ToLower()) != null)
                {
                    pnlUserNameError.Visible = true;
                }
                else
                {
                    User user = new User();

                    user.username     = TxtUserName.Text;
                    user.password     = PasswordHash.CreateHash(TxtPassword.Text);
                    user.email_id     = TxtEmailId.Text;
                    user.phone_number = TxtPhoneNumber.Text;
                    Entities.Users.Add(user);

                    Entities.SaveChanges();

                    Response.Redirect("index.aspx");
                }
            }
        }
示例#2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            pnlNegotiateCostHigher.Visible = false;
            pnlNegotiateCostLower.Visible  = false;

            using (BookSaleEntities Entities = new BookSaleEntities())
            {
                Book book = Entities.Books.Find(int.Parse(Request["bid"]));

                /*only one maximum negotiation amount will be shown to the owner of the book,
                 * so check the amount entered by the user to be higher than the current negotiationcost*/
                if (int.Parse(TxtNegotiateCost.Text) > book.NegotiatingCost)
                {
                    if (int.Parse(TxtNegotiateCost.Text) > book.Cost)
                    {
                        book.NegotiatingCost = int.Parse(TxtNegotiateCost.Text);

                        string username = Session["UserName"].ToString();
                        book.Negotiator = Entities.Users.First(u => u.username == username);

                        Entities.SaveChanges();
                        Response.Redirect("buy.aspx");
                    }
                    else
                    {
                        pnlNegotiateCostLower.Visible = true;
                    }
                }
                else
                {
                    pnlNegotiateCostHigher.Visible = true;
                    lblNegotiate.Text = book.NegotiatingCost.ToString();
                }
            }
        }
示例#3
0
        protected void grdYourBookSale_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            /*delete the selected booksale row from the grid*/
            using (BookSaleEntities Entities = new BookSaleEntities())
            {
                int  bookId = Convert.ToInt32(grdYourBookSale.DataKeys[e.RowIndex].Values["id"]);
                Book book   = Entities.Books.FirstOrDefault(u => u.id == bookId);

                Entities.Books.Remove(book);
                Entities.SaveChanges();
            }

            //refresh the grid
            Response.Redirect("sell.aspx");
        }
示例#4
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            /*add the new book in the table*/
            using (BookSaleEntities Entities = new BookSaleEntities())
            {
                Book objBookSale = new Book();

                string username = Session["UserName"].ToString();
                objBookSale.Owner           = Entities.Users.First(u => u.username == username);
                objBookSale.Department      = Entities.Departments.Find(Int64.Parse(RadioListDepartment.SelectedValue));
                objBookSale.BookName        = TxtBookName.Text;
                objBookSale.Cost            = int.Parse(TxtCost.Text);
                objBookSale.NegotiatingCost = 0;

                Entities.Books.Add(objBookSale);
                Entities.SaveChanges();
            }


            //redirect to the updated suppliers list
            Response.Redirect("home.aspx");
        }