public static bool doUpdateCartItemQuantity(int CartItemID, byte quantity) { Guid testId; bool t = false; if (Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId)) { SrvContext dbCtx = new SrvContext(); Customer cx = dbCtx.Customers .Where(el => (el.UniqueKey == testId)) .Single(); CartItem ci; if (dbCtx.CartItems .Where(el => (el.CustomerID == cx.CustomerID) && el.IsActive && (el.CartItemID == CartItemID)).Count() == 1) { ci = dbCtx.CartItems .Where(el => (el.CustomerID == cx.CustomerID) && el.IsActive && (el.CartItemID == CartItemID)) .Single(); if ((ci.Quantity > 0) && (ci.Quantity < 10)) { ci.Quantity = quantity; ci.ItemPrice = double.Parse(Generics.IfNullString(dbCtx.Products .Where(el => (el.ProductID == ci.ProductID)) .Single() .UnitPrice)) * ci.Quantity; if (Validator.TryValidateObject(ci, new ValidationContext(ci, serviceProvider: null, items: null), new List <ValidationResult>(), true)) { try { t = (dbCtx.SaveChanges() > 0); } catch { ; } } } } } return(t); }
protected void Page_Init(object sender, EventArgs e) { txtSearch.Value = Request.QueryString["q"]; if (Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId)) { //PrintUsername = Generics.IfNullString(); PrintUsername = "******"; //vwCart.Visible = true; vwUser.Visible = true; vwLogin.Visible = false; vwFooterUser.Visible = true; vwFooterLogin.Visible = false; } }
protected void btnRegister_Click(object sender, EventArgs e) { bool t = false; Customer newCustomer = new Customer(); newCustomer.FirstName = txtRegisterFirstName.Text; newCustomer.LastName = txtRegisterLastName.Text; newCustomer.Username = txtRegisterUsername.Text; newCustomer.Phone = decimal.Parse(txtRegisterPhone.Text); newCustomer.PasswordBin = Generics.MakeHash(txtRegisterPassword.Text); if (Validator.TryValidateObject(newCustomer, new ValidationContext(newCustomer, serviceProvider: null, items: null), new List <ValidationResult>(), true)) { dbCtx.Customers.Add(newCustomer); try { if (dbCtx.SaveChanges() > 0) { lblRegistrationSummary.Text = "You have been successfully registered into the system."; lblRegistrationSummary.CssClass = lblRegistrationSummary.CssClass.Replace("warning", "success"); lblRegistrationSummary.CssClass = lblRegistrationSummary.CssClass.Replace("red", "green"); lblRegistrationSummary.Visible = true; t = true; } } catch { lblRegistrationSummary.Text = "A user with the Email Address or Phone Number already exists in the system."; } } if (!t) { lblRegistrationSummary.Visible = true; } }
private void Application_BeginRequest(Object source, EventArgs e) { Guid testId; Ctx = ((HttpApplication)source).Context; bool ShouldProtect = false; try { ShouldProtect = string.Equals(Generics.IfNullString(Ctx.Request.Url.Segments[1]), "Protected/", StringComparison.InvariantCultureIgnoreCase); } catch { ShouldProtect = false; } if (ShouldProtect) { string SessionKey = string.Empty; try { SessionKey = Generics.IfNullString(Ctx.Session["UniqueKey"]); } catch { ; } if (Guid.TryParse(Generics.IfNullString(SessionKey), out testId)) { ; } else { Ctx.Response.Redirect(FormsAuthentication.LoginUrl); } } }
protected void btnAddToCart_Click(object sender, CommandEventArgs e) { Guid testId; int ProductId = 0; if (Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId) && int.TryParse(Generics.IfNullString(e.CommandArgument), out ProductId)) { if (Mediator.doAddCartItem(ProductId)) { SrvContext dbCtx = new SrvContext(); vwAddedCart.InnerText = vwAddedCart.InnerText.Replace("{{Product}}", dbCtx.Products.Where(el => (el.ProductID == ProductId)).Single().Name); } else { vwAddedCart.InnerText = "There was an error adding the product to your cart."; vwAddedCart.Attributes["class"] = vwAddedCart.Attributes["class"].Replace("-success", "-danger"); } vwAddedCart.Visible = true; } else { Response.Redirect("/Login/?logon=enabled"); } }