Example #1
0
        public static List <ViewPackageProduct> GetProducts(int packageID)
        {
            using (var db = OnlineStoreDbContext.Entity)
            {
                var query = from item in db.PackageProducts
                            where item.PackageID == packageID
                            select new ViewPackageProduct
                {
                    OldPrice         = item.OldPrice,
                    NewPrice         = item.NewPrice,
                    DisplayTitleType = item.Product.DisplayTitleType,
                    Title            = item.Product.Title,
                    Title_En         = item.Product.Title_En,
                    GroupID          = item.Product.GroupID.Value,
                    ProductID        = item.ProductID,
                    ProductVarientID = item.ProductVarientID,
                    ImageFile        = (from img in db.ProductImages
                                        where img.ProductID == item.ProductID && img.ProductImagePlace == ProductImagePlace.Home
                                        select img.Filename).FirstOrDefault()
                };

                var result = query.ToList();

                foreach (var item in result)
                {
                    if (item.ProductVarientID.HasValue)
                    {
                        item.ProductVarientTitle = ProductVarientAttributes.GetVarients(item.ProductVarientID.Value);
                    }
                }

                return(result);
            }
        }
Example #2
0
        public static List <ViewOrderItem> GetOrderItems(int id)
        {
            using (var db = OnlineStoreDbContext.Entity)
            {
                var cartItem = from item in db.CartItems
                               where item.CartID == id
                               select new ViewOrderItem
                {
                    ProductTitle = item.ProductVarient != null ?
                                   item.ProductVarient.Product.Title :
                                   item.Product.Title,
                    GroupID = item.ProductVarient != null ?
                              item.ProductVarient.Product.GroupID.Value :
                              item.Product.GroupID.Value,
                    Price     = item.Price,
                    Quantity  = item.Quantity,
                    DateTime  = item.DateTime,
                    ProductID = item.ProductVarient != null ?
                                item.ProductVarient.ProductID :
                                item.ProductID.Value,
                    ProductVarentID = item.ProductVarientID,
                    Gifts           = (from gift in db.CartItemGifts
                                       where gift.CartItemID == item.ID
                                       select new ViewCartItemGift
                    {
                        ID = gift.ID,
                        GiftTitle = gift.Gift.Title,
                        GiftID = gift.GiftID,
                        Price = gift.Price
                    }).ToList()
                };

                var result = cartItem.ToList();

                foreach (var item in result)
                {
                    if (item.ProductVarentID.HasValue)
                    {
                        item.VarientTitle = ProductVarientAttributes.GetVarients(item.ProductVarentID.Value);
                    }

                    foreach (var gift in item.Gifts)
                    {
                        var gProduct = Products.GetByID(gift.GiftID);
                        var gGroup   = Groups.GetByID(gProduct.GroupID.Value);
                        gift.Url = UrlProvider.GetProductUrl(gProduct.ID, gGroup.UrlPerfix, gProduct.UrlPerfix);
                    }

                    var group = Groups.GetByID(item.GroupID);
                    item.ProductTitle = group.Perfix + " " + item.ProductTitle;
                }

                return(result);
            }
        }
Example #3
0
        public static string GetVarients(int productVarientID)
        {
            var attrs = new List <string>();

            foreach (var attr in ProductVarientAttributes.GetJsonByProductVarientID(productVarientID))
            {
                attrs.Add(Attributes.GetByID(attr.AttributeID).Title + ": " + attr.AttributeOptionTitle);
            }

            return("(" + String.Join(" + ", attrs) + ")");
        }
        public static void DeleteWithAttributes(int id)
        {
            using (var db = OnlineStoreDbContext.Entity)
            {
                var productVarient = (from item in db.ProductVarients
                                      where item.ID == id
                                      select item).Single();

                ProductVarientAttributes.DeleteByProductVarientID(productVarient.ID);

                db.ProductVarients.Remove(productVarient);

                db.SaveChanges();
            }
        }
Example #5
0
        public static List <ViewOrderItem> GetOrderDetails(int id)
        {
            using (var db = OnlineStoreDbContext.Entity)
            {
                var cartItem = from item in db.CartItems
                               where item.CartID == id
                               select new ViewOrderItem
                {
                    ProductTitle = item.ProductVarient != null ?
                                   item.ProductVarient.Product.Title :
                                   item.Product.Title,
                    GroupID = item.ProductVarient != null ?
                              item.ProductVarient.Product.GroupID.Value :
                              item.Product.GroupID.Value,
                    ProductID = item.ProductVarient != null ?
                                item.ProductVarient.ProductID :
                                item.ProductID.Value,
                    ProductVarentID = item.ProductVarientID,
                };

                var result = cartItem.ToList();

                foreach (var item in result)
                {
                    if (item.ProductVarentID.HasValue)
                    {
                        item.VarientTitle = ProductVarientAttributes.GetVarients(item.ProductVarentID.Value);
                    }

                    var group = Groups.GetByID(item.GroupID);
                    item.ProductTitle = group.Perfix + " " + item.ProductTitle;
                }

                return(result);
            }
        }
Example #6
0
        public static List <ViewCartItem> GetByCartID(int cartID, string userID)
        {
            using (var db = OnlineStoreDbContext.Entity)
            {
                var query = from item in db.CartItems
                            where item.CartID == cartID
                            select new ViewCartItem()
                {
                    ID = item.ID,

                    ProductVarientID = item.ProductVarientID,
                    ProductID        = item.ProductID,
                    PackageID        = item.PackageID,

                    Quantity = item.Quantity
                };

                var result = query.ToList();
                foreach (var item in result)
                {
                    if (item.ProductVarientID.HasValue || item.ProductID.HasValue)
                    {
                        var priceItem = new PriceItem();

                        if (item.ProductVarientID.HasValue)
                        {
                            var productVarient = ProductVarients.GetByID(item.ProductVarientID.Value);

                            item.CartProductID = productVarient.ProductID;
                            item.Price         = ProductVarientPrices.GetPriceByProductVarientID(item.ProductVarientID.Value);

                            priceItem.ID = item.ProductVarientID.Value;
                        }
                        else if (item.ProductID.HasValue)
                        {
                            item.CartProductID = item.ProductID.Value;
                        }

                        var product = Products.GetByID(item.CartProductID);
                        var group   = Groups.GetByID(product.GroupID.Value);

                        product.Title    = group.Perfix + " " + product.Title;
                        product.Title_En = product.Title_En + " " + group.Perfix_En;

                        item.Title = product.DisplayTitle;

                        item.Image = (from img in db.ProductImages
                                      where img.ProductID == item.CartProductID &&
                                      img.ProductImagePlace == ProductImagePlace.Home
                                      select img.Filename).FirstOrDefault();

                        item.HasVarients = product.HasVarients;

                        item.Image = UrlProvider.GetProductImage(item.Image, StaticValues.MiniCartProductImageSize);

                        item.Url = UrlProvider.GetProductUrl(item.CartProductID, group.UrlPerfix, product.UrlPerfix);

                        #region Prices

                        if (item.ProductVarientID.HasValue)
                        {
                            item.VarientTitle = ProductVarientAttributes.GetVarients(item.ProductVarientID.Value);
                        }
                        else if (item.ProductID.HasValue)
                        {
                            item.Price = (from price in db.ProductPrices
                                          where price.ProductID == item.CartProductID &&
                                          price.PriceType == PriceType.Sell
                                          orderby price.LastUpdate descending
                                          select price.Price).FirstOrDefault();
                        }

                        priceItem.Price = item.Price;
                        var prices = new List <PriceItem>()
                        {
                            priceItem
                        };

                        var productID = (item.ProductID.HasValue ? item.ProductID.Value : ProductVarients.GetProductID(item.ProductVarientID.Value));

                        Products.SetDiscounts(userID, product.ID, product.HasVarients, prices);

                        item.DiscountPercent = priceItem.DiscountPercent;
                        item.DiscountPrice   = priceItem.DiscountPrice;

                        #endregion Prices

                        DateTime now = DateTime.Now;

                        var gifts = (from gift in db.ProductGifts
                                     where ((item.ProductID != null && gift.ProductID == item.ProductID) ||
                                            (item.ProductID == null && gift.ProductID == item.CartProductID)) &&
                                     gift.StartDate <= now && gift.EndDate >= now
                                     select new ViewCartItemGift
                        {
                            ID = gift.ID,
                            ProductID = gift.ProductID,
                            GiftTitle = gift.Gift.Title,
                            GiftID = gift.GiftID
                        }).ToList();

                        foreach (var gift in gifts)
                        {
                            var gProduct = Products.GetByID(gift.GiftID);
                            var gGroup   = Groups.GetByID(gProduct.GroupID.Value);
                            gift.Url = UrlProvider.GetProductUrl(gProduct.ID, gGroup.UrlPerfix, gProduct.UrlPerfix);

                            var giftPrices = Products.GetProductPrices(gift.GiftID, false, PriceType.Sell);
                            var price      = giftPrices.LastOrDefault();

                            if (price != null)
                            {
                                gift.Price = price.Price;
                            }
                        }

                        item.Gifts = gifts;

                        item.IsFreeDelivery = product.IsFreeDelivery;
                    }
                    else if (item.PackageID.HasValue)
                    {
                        var package = Packages.GetByID(item.PackageID.Value);

                        item.Title = package.Title;

                        item.Image = (from img in db.PackageImages
                                      where img.PackageID == package.ID &&
                                      img.PackageImagePlace == ProductImagePlace.Home
                                      select img.Filename).FirstOrDefault();

                        item.Image = UrlProvider.GetPackageImage(item.Image, StaticValues.MiniCartProductImageSize);

                        item.Url = UrlProvider.GetPackageUrl(item.Title, item.PackageID.Value);

                        #region Prices

                        var products = PackageProducts.GetProducts(item.PackageID.Value);

                        item.Price           = products.Sum(a => a.OldPrice);
                        item.DiscountPrice   = products.Sum(a => a.NewPrice);
                        item.DiscountPercent = (item.Price * 100) / item.DiscountPrice;

                        #endregion Prices
                    }
                }

                return(result);
            }
        }