コード例 #1
0
        public IQueryable <Product> FetchProducts()
        {
            SrvContext dbCtx = new SrvContext();

            if ((this.category_id > 0) && (dbCtx.Categories
                                           .Where(el => el.CategoryID == category_id))
                .Count() == 1)
            {
                ltlCategory.Text = dbCtx.Categories
                                   .Where(el => el.CategoryID == category_id)
                                   .Select(el => el.Name)
                                   .First();
                return(dbCtx.Products
                       .Where(el => el.CategoryID == category_id)
                       .OrderBy(el => el.Name));
            }
            else
            {
                if (!(string.IsNullOrEmpty(Request.QueryString["q"])))
                {
                    string q = Request.QueryString["q"].ToString();
                    ltlCategory.Text = ("Search : " + q);
                    return(dbCtx.Products
                           .Where(el => el.Name.Contains(q) || el.Description.Contains(q))
                           .OrderBy(el => el.Name));
                }
                else
                {
                    return(dbCtx.Products
                           .Where(el => el.IsFeatured)
                           .OrderByDescending(el => el.CategoryID));
                }
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString["product_id"], out product_id);
            SrvContext dbCtx = new SrvContext();

            if ((product_id > 0) && (dbCtx.Products
                                     .Where(el => (el.ProductID == product_id))
                                     .Count() == 1))
            {
                WebFormsCommerceDemo.Models.Product currProduct = dbCtx.Products
                                                                  .Where(el => el.ProductID == product_id)
                                                                  .First();
                ltlProductName.Text = currProduct.Name;
                ltlPrice.Text       = string.Format("{0:C}", currProduct.UnitPrice);
                ltlDescription.Text = currProduct.Description;
                imgProduct.ImageUrl = currProduct.ImagePath;
                if (!currProduct.IsAvailable)
                {
                    lblStock.CssClass     = lblStock.CssClass.Replace("label-success", "label-danger");
                    lblStock.Text         = "Unavailable";
                    btnAddToCart.Disabled = true;
                }
                lnkCategory.PostBackUrl = ("/?category_id=" + currProduct.CategoryID);
                lnkCategory.Text        = currProduct.Category.Name;
            }
            else
            {
                plhBreadCrumbs.Visible        = false;
                plhProductDetails.Visible     = false;
                plhProductDescription.Visible = false;
                plhNoContent.Visible          = true;
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId))
     {
         dbCtx = new SrvContext();
         this.FetchOrderHistory();
     }
 }
コード例 #5
0
 protected void Page_PreRender(object sender, EventArgs e)
 {
     if (!(IsPostBack) && (Generics.IfNullString(Request.QueryString["cart_added"]) == "true"))
     {
         SrvContext dbCtx = new SrvContext();
         vwAddedCart.InnerText = vwAddedCart.InnerText.Replace("{{Product}}", dbCtx.Products.Where(el => (el.ProductID == product_id)).Single().Name);
         vwAddedCart.Visible   = true;
     }
 }
コード例 #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId))
     {
         dbCtx = new SrvContext();
         this.FetchCartItems();
         updCustomer = dbCtx.Customers.Where(el => (el.UniqueKey == testId))
                       .Single();
     }
 }
コード例 #7
0
        protected void Page_InitComplete(object sender, EventArgs e)
        {
            Guid   testId;
            string UserUUID = Generics.IfNullString(Default.AppUserUniqueKey);

            if (Guid.TryParse(UserUUID, out testId))
            {
                dbCtx       = new SrvContext();
                updCustomer = dbCtx.Customers.Where(el => (el.UniqueKey == testId))
                              .Single();
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public IQueryable <CartItem> FetchCartItems()
        {
            SrvContext            dbCtx        = new SrvContext();
            IQueryable <CartItem> lstCartItems = dbCtx.CartItems
                                                 .Where(el => (el.Customer.UniqueKey == testId)
                                                        &&
                                                        el.IsActive);

            CartItemCount = lstCartItems.Count();
            if (CartItemCount > 0)
            {
                CartItemTotal      = lstCartItems.Select(el => el.ItemPrice).Sum();
                vwCheckout.Visible = true;
            }
            return(lstCartItems);
        }
コード例 #10
0
        public IQueryable <CartItem> FetchCartItems()
        {
            Guid testId;

            Guid.TryParse(Generics.IfNullString(Default.AppUserUniqueKey), out testId);
            SrvContext            dbCtx        = new SrvContext();
            IQueryable <CartItem> lstCartItems = dbCtx.CartItems
                                                 .Where(el => (el.Customer.UniqueKey == testId)
                                                        &&
                                                        el.IsActive);

            if (lstCartItems.Count() > 0)
            {
                vwNoItems.Visible   = false;
                thCheckout.Visible  = true;
                lvwCheckout.Visible = true;
                tfCheckout.Visible  = true;
                TotalAmount         = lstCartItems.Select(el => el.ItemPrice)
                                      .Sum();
            }
            return(lstCartItems);
        }
コード例 #11
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");
            }
        }
コード例 #12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     dbCtx = new SrvContext();
 }
コード例 #13
0
        public IQueryable <Category> FetchCategories()
        {
            SrvContext dbCtx = new SrvContext();

            return(dbCtx.Categories);
        }