protected void AddOrderToDB(CartItem ci, int order_code) { UthDataContext db = new UthDataContext(); UthOrder order = new UthOrder(); //get current user order.cust_id = db.UthCustomers.Single(c => c.cust_mail.Equals(User.Identity.Name)).cust_id; order.ord_code = order_code; order.ord_date = DateTime.Now; order.ord_delivered = false; order.ord_quantity = ci.Quantity; order.prod_id = ci.ProductId; db.UthOrders.InsertOnSubmit(order); UthProduct product = db.UthProducts.Single(p => p.prod_id == ci.ProductId); //substract <quantity> units from stock for this product //we can't have negative values in stock! int tempstock = product.prod_stock - order.ord_quantity; if (product.prod_stock > 0 && tempstock > 0) { product.prod_stock = tempstock; } //write changes db.SubmitChanges(); }
private object LoadTopSellers(int howMany) { UthDataContext db = new UthDataContext(); //select all prod_ids into new table x, //join x with p in t (a key), //join t with m in order to create //the top 3 of products most bought by ALL clients (not PER) return((from p in db.UthProducts join x in (from o in db.UthOrders join p in db.UthProducts on o.prod_id equals p.prod_id group o by o.prod_id into t select t) on p.prod_id equals x.Key join m in db.UthManufacters on p.man_id equals m.man_id orderby x.Count() descending select new AuxProduct { ImageId = p.img_id, Name = p.prod_name, Price = p.prod_price, Manufacter = m.man_name, Model = p.prod_model, Id = p.prod_id }).Take(howMany)); }
private void InitDdlFilterCategory() { UthDataContext db = new UthDataContext(); ddlFilterCategory.DataSource = db.UthCategories.Select(c => c).OrderBy(c => c.cat_name); ddlFilterCategory.DataBind(); ddlFilterCategory.Items.Insert(0, new ListItem("All Categories", "0")); }
private IQueryable <UthProduct> LoadProdDetail(int prodId) { UthDataContext db = new UthDataContext(); return(from p in db.UthProducts where p.prod_id == prodId select p); }
private void InitDdlFilterManufacter() { UthDataContext db = new UthDataContext(); ddlFilterManufacter.DataSource = db.UthManufacters.Select(m => m).OrderBy(m => m.man_name); ddlFilterManufacter.DataBind(); ddlFilterManufacter.Items.Insert(0, new ListItem("All Manufacters", "0")); }
private object LoadCategoriesForLinks() { UthDataContext db = new UthDataContext(); return(from c in db.UthCategories orderby c.cat_name select new { cat_url = "Search.aspx?ucid=" + c.cat_id, cat_name = c.cat_name }); }
/// <summary> /// Returns the next available orderId /// </summary> /// <returns>the next available orderId</returns> internal static int GetNextOrderId() { UthDataContext db = new UthDataContext(); int[] i = (from o in db.UthOrders orderby o.ord_code descending select o.ord_code).Take(1).ToArray(); return(i[0] + 1); }
private void InitLvFeatProd() { UthDataContext db = new UthDataContext(); lvFeatProd.DataSource = (from p in db.UthProducts orderby db.Random() select p).Take(6); lvFeatProd.DataBind(); }
private void InitBlCatNavBar() { UthDataContext db = new UthDataContext(); var v = db.UthCategories.OrderBy(c => c.cat_name); blCatNavBar.DataSource = LoadCategoriesForLinks(); blCatNavBar.DataBind(); blCatNavBar.Items.Insert(0, new ListItem("All Categories", "Search.aspx?ucid=-1")); }
/// <summary> /// Checks if a given user exists in database /// </summary> /// <returns></returns> internal static bool AuthenticateCustomer(string mail, string password) { UthDataContext db = new UthDataContext(); var v = db.UthCustomers.Where(s => s.cust_mail.Equals(mail) && s.cust_password.Equals(password)); if (v.Count() == 1) { return(true); } return(false); }
internal static IQueryable <UthCategory> SearchCategories(params int[] ids) { var predicate = SearchEngine.False <UthCategory>(); UthDataContext db = new UthDataContext(); foreach (int id in ids) { int temp = id; predicate = predicate.Or(x => x.cat_id.Equals(temp)); } return(db.UthCategories.Where(predicate).OrderBy(x => x.cat_name)); }
internal static IQueryable <UthProduct> FilterProductsByCategoryAndManufacter(string[] keywords, int cid, int mid) { var predicate = SearchEngine.False <UthProduct>(); UthDataContext db = new UthDataContext(); foreach (string keyword in keywords) { string temp = keyword; predicate = predicate.Or(p => (p.prod_name.Contains(temp) || p.prod_model.Contains(temp) || p.prod_desc.Contains(temp) || p.UthManufacter.man_name.Contains(temp)) && (p.cat_id == cid) && (p.man_id == mid)); } return(db.UthProducts.Where(predicate).OrderBy(p => p.prod_price)); }
/// <summary> /// Returns -1 if prod_id does not exist /// </summary> /// <param name="prod_id"></param> /// <returns></returns> internal static int GetStock(int prod_id) { UthDataContext db = new UthDataContext(); try { var v = db.UthProducts.Single(p => p.prod_id == prod_id); return(v.prod_stock); } catch { return(-1); } }
/// <summary> /// Returns -1 if prod_id does not exist /// </summary> /// <param name="prod_id"></param> /// <returns></returns> internal static double GetPrice(int prod_id) { UthDataContext db = new UthDataContext(); try { var v = db.UthProducts.Single(p => p.prod_id == prod_id); return(v.prod_price); } catch { return(-1); } }
private void ShowAllProducts() { UthDataContext db = new UthDataContext(); var v = db.UthProducts.Select(p => p).OrderBy(p => p.prod_price); lvProducts.DataSource = v; if (rbFilterPrice.SelectedItem.Value == "d") { lvProducts.DataSource = v.OrderByDescending(p => p.prod_price); } lvProducts.DataBind(); }
internal static IQueryable <UthProduct> SearchProductsByIdWithoutOne(int[] ids, int notThisOne, byte limitResult) { var predicate = SearchEngine.False <UthProduct>(); UthDataContext db = new UthDataContext(); foreach (int id in ids) { int temp = id; predicate = predicate.Or(x => x.prod_id.Equals(temp) && x.prod_id != notThisOne); } //orderby stock to get more variety! return(db.UthProducts.Where(predicate).OrderByDescending(p => p.prod_stock).Take(limitResult)); }
internal static IQueryable <UthProduct> SearchProducts(params string[] keywords) { var predicate = SearchEngine.False <UthProduct>(); UthDataContext db = new UthDataContext(); foreach (string keyword in keywords) { string temp = keyword; predicate = predicate.Or(p => p.prod_name.Contains(temp) || p.prod_model.Contains(temp) || p.prod_desc.Contains(temp) || p.UthManufacter.man_name.Contains(temp)); } return(db.UthProducts.Where(predicate).OrderBy(p => p.prod_price)); }
protected void Page_Init(object sender, EventArgs e) { Session["mainPage"] = "home"; Session["subPage"] = "homeHome"; UthDataContext db = new UthDataContext(); lvBargain.DataSource = db.UthProducts.Where(p => p.prod_stock > 0).OrderBy(p => p.prod_price).Take(3); lvBargain.DataBind(); lvLatest.DataSource = db.UthProducts.OrderByDescending(p => p.prod_id).Take(3); lvLatest.DataBind(); lvTop.DataSource = LoadTopSellers(3); lvTop.DataBind(); }
private void ShowStats(bool validString, bool validUcid, bool validCid, bool validMid, string searchString, int ucid, int cid, int mid) { UthDataContext db = new UthDataContext(); ltStats.Text = "Found " + howManyResults + " product(s)"; if (validString) { ltStats.Text += " for "" + Server.HtmlEncode(searchString) + """; } if (howManyResults > 0) { if (rbFilterPrice.SelectedItem.Value == "a") { ltStats.Text += ", shown by ascending prices"; } else if (rbFilterPrice.SelectedItem.Value == "d") { ltStats.Text += ", shown by descending prices"; } if (validMid) { ltStats.Text += ", by " + db.UthManufacters.Single(m => m.man_id == mid).man_name; } if (validUcid) { if (ucid == -1) { ltStats.Text += " in all categories"; } else { ltStats.Text += " in category "" + db.UthCategories.Single(c => c.cat_id == ucid).cat_name.ToLower() + """; } } else if (validCid) { ltStats.Text += " in category "" + db.UthCategories.Single(c => c.cat_id == cid).cat_name.ToLower() + """; } } ltStats.Text += "."; }
private void ShowResultBasedOnUnsortingCategoryAndManufacter(int ucid, int mid) { UthDataContext db = new UthDataContext(); var v = db.UthProducts.Where(p => p.cat_id == ucid && p.man_id == mid); if (ucid == -1) { v = db.UthProducts.Where(p => p.man_id == mid); } lvProducts.DataSource = v.OrderBy(p => p.prod_price); if (rbFilterPrice.SelectedItem.Value == "d") { lvProducts.DataSource = v.OrderByDescending(p => p.prod_price); } lvProducts.DataBind(); this.howManyResults = v.Count(); }
private void ShowResultBasedOn(int ucid) { UthDataContext db = new UthDataContext(); var v = db.UthProducts.Where(p => p.cat_id == ucid); if (ucid == -1) { v = db.UthProducts.Select(p => p); } lvProducts.DataSource = v.OrderBy(p => p.prod_price); if (rbFilterPrice.SelectedItem.Value == "d") { lvProducts.DataSource = v.OrderByDescending(p => p.prod_price); } ShowOnlyRelevantManufacters(v); this.howManyResults = v.Count(); }
private IQueryable <UthProduct> LoadAssociatedProducts(int prodId) { UthDataContext db = new UthDataContext(); //Make j.Key (by selecting t) representing customers who have bought this product, //join them with every order ever placed, //select all products that have been bought by these customers IQueryable <int> v = from o in db.UthOrders join j in (from o in db.UthOrders where o.prod_id == prodId group o by o.cust_id into t select t) on o.cust_id equals j.Key select o.prod_id; int[] i = v.ToArray(); //return all products the customers bought except, of course, the product that's being detailed right now and here return(SearchEngine.SearchProductsByIdWithoutOne(i, prodId, 3)); }
private void Page_Load(object sender, System.EventArgs e) { try { string param = Request.QueryString["img"]; string pic_id = param.Substring(0, param.Length - 5); char pic_size = param[pic_id.Length]; Binary pic; UthDataContext db = new UthDataContext(); UthImage image = db.UthImages.Single(i => i.img_id == Int32.Parse(pic_id)); switch (pic_size) { case ('s'): pic = image.img_small; break; case ('m'): pic = image.img_medium; break; case ('l'): pic = image.img_large; break; default: pic = null; break; } Response.ContentType = "image/jpeg"; Response.BinaryWrite(pic.ToArray()); } catch { Response.Redirect("~/Default.aspx"); } }
protected void btnRegister_Click(object sender, EventArgs e) { if (this.IsValid) { UthDataContext db = new UthDataContext(); var v = db.UthCustomers.Where(cust => cust.cust_mail.Equals(tbEmail.Text)); if (v.Count() == 0) { UthCustomer c = new UthCustomer(); //c.cust_country =tbCountry.Text; c.cust_country_code = int.Parse(ddlCountry.SelectedItem.Value); c.cust_mail = tbEmail.Text; c.cust_name = tbName.Text; c.cust_password = tbPassword.Text; c.cust_phone = tbPhone.Text; c.cust_postalcode = int.Parse(tbPostal.Text); c.cust_streetname = tbStreet.Text; c.cust_streetnumber = int.Parse(tbHouse.Text); c.cust_city = tbCity.Text; db.UthCustomers.InsertOnSubmit(c); db.SubmitChanges(); bool authenticated = Customer.AuthenticateCustomer(c.cust_mail, c.cust_password); if (authenticated) { FormsAuthentication.RedirectFromLoginPage(c.cust_mail, false); } Response.Redirect("~/ThankYou.aspx"); } pError.Visible = true; } }