protected void Page_Load(object sender, EventArgs e) { /*create a session for security and timeout of 5 mins*/ Session.Timeout = 5; if (Session["UserName"] != null) { LblUsername.Text += Session["UserName"].ToString(); TxtOwnerEmailID.Text = Session["EmailID"].ToString(); using (BookSaleEntities Entities = new BookSaleEntities()) { String email = (String)Session["EmailID"]; if (!Entities.Books.Where(b => b.Owner.email_id == email).Any()) { EmptyBooksAdded.Visible = true; } else { EmptyBooksAdded.Visible = false; grdYourBookSale.DataSource = Entities.Books.Where(b => b.Owner.email_id == email).ToList(); grdYourBookSale.DataBind(); } if (!IsPostBack) { RadioListDepartment.DataSource = Entities.Departments.ToList(); RadioListDepartment.DataBind(); } } } else { Response.Redirect("index.aspx"); } }
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"); } } }
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(); } } }
protected void getBookToNegotiate() { using (BookSaleEntities Entities = new BookSaleEntities()) { Book book = Entities.Books.Find(int.Parse(Request["bid"])); TxtBookName.Text = book.BookName; TxtDeptName.Text = book.Department.Name; TxtCost.Text = book.Cost.ToString(); } }
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"); }
protected void getBooks_Click(object sender, EventArgs e) { using (BookSaleEntities Entities = new BookSaleEntities()) { String email = (String)Session["EmailID"]; string department = ddlDepartment.SelectedValue; /*fill grid with the book of the department selected in dropdown list*/ if (!Entities.Books.Where(b => b.Department.Name == department && b.Owner.email_id != email).Any()) { NoBookForDept.Visible = true; } else { NoBookForDept.Visible = false; grdBookSale.DataSource = Entities.Books.Where(b => b.Department.Name == department && b.Owner.email_id != email).ToList(); grdBookSale.DataBind(); } } }
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"); }
protected void Page_Load(object sender, EventArgs e) { /*create a session for security and timeout of 5 mins*/ Session.Timeout = 5; if (Session["UserName"] != null) { LblUsername.Text += Session["UserName"].ToString(); if (!IsPostBack) { using (BookSaleEntities Entities = new BookSaleEntities()) { /*fill grid with the book the user already negotiated with*/ String email = (String)Session["EmailID"]; /*fill dropdown with department available*/ ddlDepartment.DataSource = Entities.Departments.ToList(); ddlDepartment.DataBind(); ddlDepartment.Items.Insert(0, new ListItem("-- Select Department --", "-1")); if (!Entities.Books.Where(b => b.Negotiator.email_id == email).Any()) { EmptyNegotiatedBooks.Visible = true; } else { EmptyNegotiatedBooks.Visible = false; grdNegotiated.DataSource = Entities.Books.Where(b => b.Negotiator.email_id == email).ToList(); grdNegotiated.DataBind(); } } } } else { Response.Redirect("index.aspx"); } }
protected void BtnLogin_Click(object sender, EventArgs e) { using (BookSaleEntities Entities = new BookSaleEntities()) { pnlInvalidUser.Visible = false; /*check for user name with corresponding password in the database*/ User user = Entities.Users.FirstOrDefault(u => u.username.ToLower() == TxtUsername.Text.ToLower()); if (user != null) { if (PasswordHash.ValidatePassword(TxtPassword.Text, user.password)) { Session["EmailID"] = user.email_id; Session["UserName"] = user.username; Response.Redirect("home.aspx"); } } else { pnlInvalidUser.Visible = true; } } }