protected void Page_InitComplete(object sender, EventArgs e)
        {
            bool b = false;

            vwLogoutMessage.Visible = (bool.TryParse(Generics.IfNullString(Request.QueryString["logout"]), out b) && b);
            vwLoginMessage.Visible  = (Generics.IfNullString(Request.QueryString["logon"]) == "enabled");
        }
        public static bool doRemoveCartItem(int CartItemID)
        {
            Guid testId;
            bool t = false;

            if ((Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId)) && (CartItemID > 0))
            {
                SrvContext dbCtx      = new SrvContext();
                int        CustomerID = dbCtx.Customers
                                        .Where(el => (el.UniqueKey == testId))
                                        .Single()
                                        .CustomerID;
                if (dbCtx.CartItems.Where(el => (el.CartItemID == CartItemID)
                                          &&
                                          (el.CustomerID == CustomerID)).Count() == 1)
                {
                    CartItem ci = dbCtx.CartItems
                                  .Where(el => (el.CartItemID == CartItemID)
                                         &&
                                         (el.CustomerID == CustomerID))
                                  .Single();
                    dbCtx.CartItems.Remove(ci);
                    try
                    {
                        t = (dbCtx.SaveChanges() > 0);
                    }
                    catch
                    {
                        ;
                    }
                }
            }
            return(t);
        }
 protected void btnRemoveCartItem_Click(object sender, CommandEventArgs e)
 {
     try
     {
         Mediator.doRemoveCartItem(int.Parse(Generics.IfNullString(e.CommandArgument)));
         Response.Redirect(Request.RawUrl);
     }
     catch
     {
         ;
     }
 }
        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;
     }
 }
        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);
                }
            }
        }
Пример #7
0
        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");
            }
        }