private void PopulateOrder(string invoice, List <PaypalItem> items, Amount amt) { BetaDB db = new BetaDB(); var login = db.Logins.Where(x => x.ID == userId).FirstOrDefault(); var profile = login.Profiles.ElementAt(0); var addr = profile.Address + ", " + profile.City + ", " + profile.State + ", Pin: " + profile.PinCode + ", " + profile.Country; Payment _p = new Payment(); _p.AddedOn = DateTime.Now; _p.InvoiceNo = invoice; _p.Status = 0; _p.ShippingAddress = addr; _p.Shipping = Convert.ToDecimal(amt.details.shipping); _p.Tax = Convert.ToDecimal(amt.details.tax); _p.Subtotal = Convert.ToDecimal(amt.details.subtotal); _p.UserId = userId; db.Payments.Add(_p); foreach (PaypalItem pi in items) { OrderDetail od = new OrderDetail(); od.InvoiceNo = invoice; od.Price = Convert.ToDecimal(pi.price); od.ProductId = pi.ProductId; od.UserId = userId; od.Size = pi.size; od.Quantity = pi.quantity; od.TotalAmount = Convert.ToDecimal((double)pi.quantity * pi.price); db.OrderDetails.Add(od); } db.SaveChanges(); }
protected void cartViewRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { BetaDB db = new BetaDB(); HiddenField hdnID = e.Item.FindControl("ProHdn") as HiddenField; int id = Convert.ToInt32(hdnID.Value); Label productSize = e.Item.FindControl("lblProductSize") as Label; var size = productSize.Text; DropDownList dl = e.Item.FindControl("Quantity") as DropDownList; int qty = Convert.ToInt32(dl.SelectedItem.Text); if (e.CommandName == "remove") { if (carthandler.GetCount() != 0) { CartItem ci = new CartItem { Id = id, Quantity = qty, Size = size }; carthandler.RemoveFromCart(ci); //cookiehandler.DeleteCookie("Cart", Id, size); //cookiehandler.ch.products = cookiehandler.GetCookie("Cart"); //cookiehandler.AddCookie("Cart", cookiehandler.ch.products); } } CartDetails(); Response.Redirect(Request.Url.ToString()); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { var db = new BetaDB(); string guid = Page.RouteData.Values["guid"].ToString(); var uniqueId = Guid.Parse(guid); var IsValid = db.GUIDs.Where(x => x.UniqueId.Equals(uniqueId)).FirstOrDefault(); if (IsValid != null && IsValid.Purpose == "Activation") { Login lg = db.Logins.Find(IsValid.UserId); lg.IsActive = true; db.Entry(lg).State = System.Data.Entity.EntityState.Modified; var deleteGUID = db.GUIDs.SingleOrDefault(x => x.UniqueId.Equals(IsValid.UniqueId)); db.Entry(deleteGUID).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); AccountActivation.Visible = true; ltMessage.Text = "Account Activated Successfully!"; } else { AccountActivation.Visible = true; ltMessage.Text = "Broken Link !"; lblMessagedesc.Text = "Varify link has Experied or Invalid. Please click here to activate account"; } } catch { return; } } }
public void CartDetails() { BetaDB db = new BetaDB(); if (Session["email"] != null) { var email = Session["email"].ToString(); var Id = db.Logins.Where(x => x.Email.Equals(email)).Select(x => x.ID).FirstOrDefault(); var producttt = (from c in db.Carts join p in db.Products on c.ProductID equals p.ProductID where c.UserId == Id orderby c.ID select new { cartId = c.ID, ProductId = p.ProductID, size = c.Size, quantity = c.Quantity, productName = p.ProductName, price = p.ProductPrice * c.Quantity }).ToList(); cartViewRepeater.DataSource = producttt; cartViewRepeater.DataBind(); if (producttt.Count == 0) { cartempty.Visible = true; cartemptymsg.Text = "YOUR CART IS EMPTY"; } } else if (carthandler.GetCount() != 0) { var productt = carthandler.cookiehandler.cartitems.Select(x => new { ProductId = x.Id, size = x.Size, quantity = x.Quantity }).ToList(); cartViewRepeater.DataSource = productt; cartViewRepeater.DataBind(); } else { cartempty.Visible = true; cartemptymsg.Text = "YOUR CART IS EMPTY"; } }
public static Login GetUserByEmail(string email) { var db = new BetaDB(); var userId = db.Logins.Where(d => d.Email.Equals(email)).FirstOrDefault(); return(userId); }
public static List <ProductSize> GetProductSizesFromProduct(Product product) { BetaDB db = new BetaDB(); List <ProductSize> ps = db.ProductSizes.Where(x => x.ProductSubCatID == product.ProductSubCatID).ToList(); return(ps); }
public static string forgetpassword(string password, string uniqueId) { var db = new BetaDB(); string validpassword = password.ValidatePassword(); if (validpassword == "true") { var uuniqueId = Guid.Parse(uniqueId); var IsValid = db.GUIDs.Where(x => x.UniqueId.Equals(uuniqueId)).FirstOrDefault(); Login lg = db.Logins.Find(IsValid.UserId); lg.Password = HelpUs.Encrypt(password); db.Entry(lg).State = System.Data.Entity.EntityState.Modified; var deleteGUID = db.GUIDs.SingleOrDefault(x => x.UniqueId.Equals(IsValid.UniqueId)); db.Entry(deleteGUID).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Password reset successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "server error"); return(JsonConvert.SerializeObject(dic)); } }
public string GetProductCategories() { string categories = ""; BetaDB db = new BetaDB(); foreach (ProductCategory pc in db.ProductCategories.ToList()) { string subcat = ""; foreach (ProductSubCategory psc in pc.ProductSubCategories) { subcat = subcat + psc.ProductSubCatName + ","; } if (subcat.Length > 1) { subcat = subcat.Substring(0, subcat.Length - 1); categories = categories + pc.ProductCatName + "|" + subcat + "#"; } else { categories = categories + pc.ProductCatName + "|#"; } } if (categories.Length > 1) { categories = categories.Substring(0, categories.Length - 1); } return(categories); }
protected void Page_Load(object sender, EventArgs e) { BetaDB db = new BetaDB(); carthandler = new CartHandler(); if (!IsPostBack) { CartDetails(); } if (carthandler.GetCount() == 0) { cartCalculation.Visible = false; } //else //{ // cartCalculation.Visible = true; //} if (!Page.IsPostBack) { lblCartTotal.Text = totalPrice.ToString() + "$"; double tax = (((double)totalPrice * 15) / 100); lbltax.Text = tax.ToString(); lbldelivery.Text = NicePayment.PaymentHandler._fixedShipping.ToString() + "$"; double grandtotal = totalPrice + Convert.ToDouble(lbltax.Text) + NicePayment.PaymentHandler._fixedShipping; lbltax.Text += "$"; lblGrandCartTotal.Text = grandtotal.ToString() + "$"; } }
public static string Search(string searchterm) { BetaDB db = new BetaDB(); db.Configuration.ProxyCreationEnabled = false; var listt = db.Logins.Where(x => x.Email.Contains(searchterm) && x.UserRole == "User").Select(x => new { x.ID, x.Email, x.UserRole, x.IsActive }).ToList(); return(new JavaScriptSerializer().Serialize(listt)); }
public static string OrderDetail() { BetaDB db = new BetaDB(); db.Configuration.ProxyCreationEnabled = false; var list = db.OrderDetails.Select(x => new { x.ProductId, x.Product.ProductName, x.Price, x.Login.Email, x.InvoiceNo, x.Quantity, Status = db.Payments.FirstOrDefault().Status }).ToList(); return(new JavaScriptSerializer().Serialize(list)); }
protected void orderViewPanelRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { BetaDB db = new BetaDB(); var invoiceNo = (e.Item.FindControl("hfInvoiceNo") as HiddenField).Value; Repeater rptOrders = e.Item.FindControl("orderViewRepeater") as Repeater; var list = db.OrderDetails.Where(x => x.InvoiceNo == invoiceNo).Select(x => new { x.ProductId, ImageUrl = x.Product.ProductImages.FirstOrDefault(), x.Product.ProductName, x.Product.ProductBrandName, x.Price, x.InvoiceNo, x.Quantity, Status = db.Payments.FirstOrDefault().Status, AddedOn = db.Payments.FirstOrDefault().AddedOn }).ToList(); rptOrders.DataSource = list; rptOrders.DataBind(); } }
protected void productrepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { BetaDB db = new BetaDB(); HiddenField hdnID = e.Item.FindControl("ProHdn") as HiddenField; int Id = Convert.ToInt32(hdnID.Value); var images = db.ProductImages.Where(im => im.ProductID.Equals(Id)).FirstOrDefault(); Image img = e.Item.FindControl("proImg") as Image; string imgpath = "~/ProductImage/" + images.ProductImagePath.ToString(); img.ImageUrl = imgpath; }
public static bool IsUserExist(string email) { var db = new BetaDB(); var user = db.Logins.Where(d => d.Email.Equals(email)).FirstOrDefault(); if (user == null) { return(false); } else { return(true); } }
public static string GetProducts(int page) { BetaDB db = new BetaDB(); db.Configuration.ProxyCreationEnabled = false; try { var listt = db.Products.Select(x => new { Id = x.ProductID, Desciption = x.ProductDesc, Name = x.ProductName, Price = x.ProductPrice, BrandName = x.ProductBrandName, ImageUrl = x.ProductImages.FirstOrDefault() }).ToList().Skip(limit * (page - 1)).Take(limit); return(new JavaScriptSerializer().Serialize(listt)); } catch (Exception e) { return(new JavaScriptSerializer().Serialize(new List <Product>())); } }
public static GUID NewGuid(Login login, string _purpose) { BetaDB db = new BetaDB(); Guid UniqueCode = Guid.NewGuid(); GUID guid = new GUID() { UniqueId = UniqueCode, UserId = login.ID, CreatedOn = DateTime.Now, Purpose = _purpose }; db.GUIDs.Add(guid); db.SaveChanges(); return(guid); }
public static string ChangePassword(string password, string newpassword) { string email = HttpContext.Current.Session["email"].ToString(); var db = new BetaDB(); var oldpassword = HelpUs.Encrypt(password); var newPassword = HelpUs.Encrypt(newpassword); var User = db.Logins.Where(x => x.Email == email).FirstOrDefault(); if (User.Password != oldpassword) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Old Password did not match"); return(JsonConvert.SerializeObject(dic)); } else if (User.Password == newPassword) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "New Password Cannot be same as before"); return(JsonConvert.SerializeObject(dic)); } else { string validpassword = newpassword.ValidatePassword(); if (validpassword == "true") { User.Password = HelpUs.Encrypt(newpassword); //db.Entry(lg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Password Changed successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Password Must Contain Uppercase,Lowercase,Character and 8 Digits"); return(JsonConvert.SerializeObject(dic)); } } }
public static string GetProductsByCategory(string category, int page) { BetaDB db = new BetaDB(); db.Configuration.ProxyCreationEnabled = false; try { int productcategoryid = db.ProductCategories.SingleOrDefault(x => x.ProductCatName == category).ProductCatID; var list = db.Products.Where(x => x.ProductCatID == productcategoryid).ToList().Skip(limit * (page - 1)).Take(limit); return(new JavaScriptSerializer().Serialize(list)); } catch (Exception e) { return(new JavaScriptSerializer().Serialize(new List <Product>())); } }
// In page load check for valid activation code and deleting it on successful activation public String IsGuidValid(string guid) { var db = new BetaDB(); var uniqueId = Guid.Parse(Page.RouteData.Values["guid"].ToString()); var IsValid = db.GUIDs.Where(x => x.UniqueId.Equals(uniqueId)).FirstOrDefault(); if (IsValid == null) { return(null); } else { var result = IsValid.Purpose; return(result); } }
public static string GetProductsBySubCategory(string category, string subcategory, int page) { BetaDB db = new BetaDB(); db.Configuration.ProxyCreationEnabled = false; try { int productcategoryid = db.ProductCategories.SingleOrDefault(x => x.ProductCatName == category).ProductCatID; int productsubcategoryid = db.ProductSubCategories.SingleOrDefault(x => x.ProductSubCatName == subcategory && x.ProductCatID == productcategoryid).ProductSubCatID; var list = db.Products.Select(x => new { Id = x.ProductID, Desciption = x.ProductDesc, Name = x.ProductName, Price = x.ProductPrice, BrandName = x.ProductBrandName, ImageUrl = x.ProductImages.FirstOrDefault(), SubcategoryId = x.ProductSubCatID, CategoryId = x.ProductCatID }).Where(x => x.SubcategoryId == productsubcategoryid).ToList().Skip(limit * (page - 1)).Take(limit); return(new JavaScriptSerializer().Serialize(list)); } catch (Exception e) { return(new JavaScriptSerializer().Serialize(new List <Product>())); } }
public static string SendForgetPasswordLink(string email) { BetaDB db = new BetaDB(); if (!string.IsNullOrEmpty(email) && !string.IsNullOrWhiteSpace(email)) { if (IsUserExist(email)) { string purpose = "Reset"; var user = GetUserByEmail(email); var guidId = db.GUIDs.FirstOrDefault(f => f.UserId == user.ID && f.Purpose == purpose); if (guidId == null) { guidId = NewGuid(user, purpose); string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Reset/" + guidId.UniqueId); Sendemail(email, guidId.Purpose, url); } else if (guidId != null && guidId.UserId != null && guidId.Purpose == "Reset") { string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Reset/" + guidId.UniqueId); Sendemail(email, guidId.Purpose, url); } Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Check your email to reset your password. "); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "User does not exist"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email and Password Required"); return(JsonConvert.SerializeObject(dic)); } }
protected void BtnRegister_Click(object sender, EventArgs e) { using (var db = new BetaDB()) { if (db.Logins.Count((a) => a.Email == TxtEmail.Text) > 0) { lblMessage.Text = "sorry"; } else { var encryptedpassword = HelpUs.Encrypt(TxtPassword.Text); Login lg = new Login { Email = TxtEmail.Text, Password = encryptedpassword }; db.Logins.Add(lg); db.SaveChanges(); } } }
protected void Page_Load(object sender, EventArgs e) { db = new BetaDB(); try { id = Convert.ToInt32(Page.RouteData.Values["id"].ToString()); product = db.Products.SingleOrDefault(x => x.ProductID == id); ProductName.Text = product.ProductName; productready = true; CreatBreadCrumbs(product); if (product != null) { List <ProductImage> images = product.ProductImages.ToList(); int count = 0; foreach (ProductImage image in images) { string path = "/ProductImage/" + image.ProductImagePath; HtmlGenericControl li = new HtmlGenericControl("li"); HtmlGenericControl img = new HtmlGenericControl("img"); img.Attributes.Add("src", path); img.Attributes.Add("Class", "productimagessmall"); img.Attributes.Add("id", "product_images_" + count); ProductImagesContainer.Controls.Add(img); count++; } if (!IsPostBack) { Sizes.DataSource = ProductHandler.GetProductSizesFromProduct(product); Sizes.DataTextField = "ProductSizeName"; Sizes.DataValueField = "ProductSizeID"; Sizes.DataBind(); } string mainpath = "/ProductImage/" + images.ElementAt(0).ProductImagePath; MainImage.Attributes.Add("src", mainpath); } } catch { product = new Product(); } }
public void OrderDetails() { BetaDB db = new BetaDB(); if (Session["email"] != null) { var email = Session["email"].ToString(); var Id = db.Logins.Where(x => x.Email.Equals(email)).Select(x => x.ID).FirstOrDefault(); var invoiceNo = db.OrderDetails.GroupBy(x => x.InvoiceNo).Select(y => new { InvoiceNo = y.Key }).ToList(); orderViewPanelRepeater.DataSource = invoiceNo; orderViewPanelRepeater.DataBind(); if (invoiceNo.Count <= 0) { orderempty.Visible = true; orderemptymsg.Text = "There is no Orders to show"; } } else { orderempty.Visible = true; orderemptymsg.Text = "There is no Orders to show"; } }
protected void Checkoutt_Click(object sender, EventArgs e) { if (cartitems == null) { db = new BetaDB(); var email = Session["email"].ToString(); userId = db.Logins.Where(x => x.Email == email).Select(x => x.ID).FirstOrDefault(); cartitems = db.Carts.Where(x => x.UserId == userId).ToList <Cart>(); } List <PaypalItem> approvedItems = new List <PaypalItem>(); foreach (Cart ci in cartitems) { var product = db.Products.Where(x => x.ProductID == ci.ProductID).SingleOrDefault(); var stock = db.Stocks.Where(x => x.ProductID == ci.ProductID && x.ProductSizeName == ci.Size).FirstOrDefault(); if (stock.StockCount < ci.Quantity) { outofstocklbl.Text = "Some Products are Out of Stock"; } else { PaypalItem pi = new PaypalItem { ProductId = product.ProductID, name = product.ProductName, currency = "NZD", price = Convert.ToDouble(product.ProductPrice), quantity = (int)ci.Quantity, size = ci.Size, sku = product.ProductID.ToString() }; approvedItems.Add(pi); } } PaymentHandler ph = new PaymentHandler(approvedItems, userId); }
public static string register(string email, string password) { try { var db = new BetaDB(); if (!string.IsNullOrEmpty(email) && !string.IsNullOrWhiteSpace(email)) { var emailexist = db.Logins.FirstOrDefault(x => x.Email == email); if (emailexist == null) { // checking email format bool valid = email.ValidateEmail(); if (valid == true) { Login l = new Login(); // for password requirement string validpassword = password.ValidatePassword(); if (validpassword == "true") { l.Email = email; l.Password = HelpUs.Encrypt(password); l.UserRole = "User"; l.CreatedOn = DateTime.Now; l.IsActive = false; l.Islocked = false; db.Logins.Add(l); db.SaveChanges(); //to send activation email and save data in GUID data string purpose = "Activation"; GUID UniqueCode = NewGuid(l, purpose); string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Activation/" + UniqueCode.UniqueId); Sendemail(email, purpose, url); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "User Registered Successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Password Must Contain Uppercase,Lowercase,Character and 8 Digits"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email is Invalid"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "User Already Exists"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email and Password Required"); return(JsonConvert.SerializeObject(dic)); } } catch (Exception e) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Server Error"); return(JsonConvert.SerializeObject(dic)); } }
public static string login(string email, string password) { using (var db = new BetaDB()) { if (!string.IsNullOrEmpty(email) && !string.IsNullOrWhiteSpace(email)) { var login = db.Logins.SingleOrDefault(x => x.Email == email); string Password = HelpUs.Encrypt(password); if (login != null && login.Password == Password) { //check if isemail varified if (login.IsActive == true) { HttpContext.Current.Session["email"] = login.Email; HttpContext.Current.Session["UserRole"] = login.UserRole; CartHandler carthandler = new CartHandler(); carthandler.SyncCookieDatainDb(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Login Successfull "); dic.Add("RedirectUrl", "/Home"); return(JsonConvert.SerializeObject(dic)); } else { // To send a activation email if user forget to activate when register var guidId = db.GUIDs.FirstOrDefault(f => f.UserId == login.ID && f.Purpose == "Activation"); if (login.IsActive == false) { string purpose = "Activation"; if (guidId == null) { guidId = NewGuid(login, purpose); } string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Activation/" + guidId.UniqueId); Sendemail(email, guidId.Purpose, url); } else if (guidId != null && guidId.UserId != null && guidId.Purpose == "Activation") { string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Activation/" + guidId.UniqueId); Sendemail(email, guidId.Purpose, url); } // guid is null Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Verify your Email first "); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Username or Password Do not Match"); dic.Add("RedirectUrl", "/Home"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email and Password Required"); return(JsonConvert.SerializeObject(dic)); } } }
public CartHandler() { db = new BetaDB(); cookiehandler = new CookieHandler(); }
protected void cartViewRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { BetaDB db = new BetaDB(); HiddenField hdnID = e.Item.FindControl("ProHdn") as HiddenField; int Id = Convert.ToInt32(hdnID.Value); var images = db.ProductImages.Where(im => im.ProductID.Equals(Id)).FirstOrDefault(); HiddenField qtyhdnID = e.Item.FindControl("hdnqty") as HiddenField; int qty = Convert.ToInt32(qtyhdnID.Value); var productts = db.Products.Where(x => x.ProductID == Id).Select(x => new { productName = x.ProductName, price = qty * x.ProductPrice }).ToList(); Label productPrice = e.Item.FindControl("lblProductPrice") as Label; productPrice.Text = productts.Select(x => x.price).FirstOrDefault().ToString(); Label productName = e.Item.FindControl("lblProductName") as Label; productName.Text = productts.Select(x => x.productName).FirstOrDefault().ToString(); Label productSize = e.Item.FindControl("lblProductSize") as Label; var size = productSize.Text; DropDownList productQuantity = e.Item.FindControl("Quantity") as DropDownList; var stock = db.Stocks.Where(x => x.ProductID == Id && x.ProductSizeName == size).FirstOrDefault(); if (stock != null) { Label stocklabel = e.Item.FindControl("lblstock") as Label; if (stock.StockCount > 0) { stocklabel.ForeColor = System.Drawing.Color.Green; stocklabel.Text = "Available in stock"; } else { stocklabel.ForeColor = System.Drawing.Color.Red; stocklabel.Text = "Out of stock"; } List <int> list = new List <int>(); if (stock.StockCount >= qty) { for (int i = 0; i <= stock.StockCount; i++) { list.Add(i); } } else { for (int i = 0; i <= qty; i++) { list.Add(i); } } productQuantity.DataSource = list; // to update quantity in cart productQuantity.Text = qty.ToString(); productQuantity.DataBind(); } else { List <int> list = new List <int>(); list.Add(0); list.Add(1); productQuantity.DataSource = list; productQuantity.Text = qty.ToString(); productQuantity.DataBind(); Label stocklabel = e.Item.FindControl("lblstock") as Label; stocklabel.ForeColor = System.Drawing.Color.Red; stocklabel.Text = "Out of stock"; } Image img = e.Item.FindControl("proImg") as Image; string imgpath = "~/ProductImage/" + images.ProductImagePath.ToString(); img.ImageUrl = imgpath; //for cart total totalPrice = totalPrice + Convert.ToInt32(productPrice.Text); }
protected void Quantity_SelectedIndexChanged(object sender, EventArgs e) { DropDownList ddl = (DropDownList)sender; RepeaterItem item = (RepeaterItem)ddl.NamingContainer; BetaDB db = new BetaDB(); HiddenField hdnID = item.FindControl("ProHdn") as HiddenField; int Id = Convert.ToInt32(hdnID.Value); Label productSize = item.FindControl("lblProductSize") as Label; var size = productSize.Text; DropDownList dl = item.FindControl("Quantity") as DropDownList; int qty = Convert.ToInt32(dl.SelectedItem.Text); if (Session["email"] != null) { if (Convert.ToInt32(dl.SelectedItem.Text) != 0) { var email = Session["email"].ToString(); var userId = db.Logins.Where(x => x.Email == email).Select(x => x.ID).FirstOrDefault(); int cartId = db.Carts.Where(x => x.ProductID == Id && x.Size == size).Select(x => x.ID).FirstOrDefault(); int quantity = Convert.ToInt32(((DropDownList)item.FindControl("Quantity")).SelectedValue); Cart cart = new Cart() { ID = cartId, UserId = userId, ProductID = Id, Size = size, Quantity = quantity }; db.Entry(cart).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } else { CartItem ci = new CartItem { Id = Id, Quantity = qty, Size = size }; carthandler.RemoveFromCart(ci); } } else if (carthandler.GetCount() != 0) { if (Convert.ToInt32(dl.SelectedItem.Text) == 0) { CartItem ci = new CartItem { Id = Id, Quantity = qty, Size = size }; carthandler.RemoveFromCart(ci); } else { //carthandler.RemoveFromCart(Id,size); //carthandler.AddtoCart(Id, size, qty); //cookiehandler.ch.AddtoCart(Id, size, qty); //cookiehandler.AddCookie("Cart", cookiehandler.ch.products); foreach (CartItem ci in carthandler.cookiehandler.cartitems) { if (ci.Size == size && ci.Id == Id) { ci.Quantity = qty; } } carthandler.cookiehandler.SyncListItems(); } } CartDetails(); Response.Redirect(Request.Url.ToString()); }