private void AddUser(User usr) { if (ConnectionClass.AddUser(usr)) { Session["login"] = usr.Name; Session["type"] = usr.Type; User tempUsr = ConnectionClass.GetUser(usr.Name, usr.Password); Session["id"] = tempUsr.Id; lblErr.Text = ""; Response.Redirect("~/Default.aspx"); } else { lblErr.Text = "Failed to add user. Try to enter different name."; } }
// order the product for user // function that takes money from client doesn't exist for yet // redirect to client orders page public static string BuyItem(int ProductID, int userID, string addres) { // place for fields validation Item item = ConnectionClass.GetProductByID(ProductID); if (item == null || item.Quantity <= 0) { return("Cannot buy this product. Please try other one."); } User user = ConnectionClass.GetUserByID(userID); Ordder order = new Ordder(1, user.Id, ProductID, 1, item.Price, DateTime.Now.ToString("d.M.yyyy"), addres); ConnectionClass.AddOrder(order); ConnectionClass.ReduceQuantity(ProductID); // function that draws money from client //Response.Redirect("/Orders.aspx"); return(""); }
// this method creates html tables for each item that gets from data base private void FillPage() { LinkedList <Item> items = ConnectionClass.GetLastAdded(); string sb = ""; if (items != null) { foreach (Item it in items) { sb += @"<table class='desktopTable'>" + "<tr><th rowspan='3' width='150px'><a href='/Buy.aspx?id=" + it.ID + "'><img runat='server' src='" + it.Image + "' /></a></th>" + "<th width='50px'>Name: </td><td>" + it.Type + " " + it.Name + "</td>" + "<th rowspan='3' width='50px'>" + "<button type='button' onclick='redirect(" + it.ID + ")' name='buy' value='" + it.ID + "' class='css3button'>buy</button>" + "</th></tr><tr><th>Price: </th><td>" + it.Price + " $</td></tr>" + "<tr><th>Description: </th><td>" + it.Description + "</td></tr></table>"; } } lblOutput.Text = sb; }