Exemplo n.º 1
0
        private WishlistIndexViewModel ConstructWishistIndexViewModel(int id = 0)
        {
            var viewModel = new WishlistIndexViewModel()
            {
                WishlistID = id
            };

            using (var context = new TTTEntities())
            {
                GetNormalModel(viewModel, context);

                GetCustomizeModel(viewModel, context);
            }

            return viewModel;
        }
Exemplo n.º 2
0
        private void GetNormalModel(WishlistIndexViewModel viewModel, TTTEntities context)
        {
            var query = from wishlistItem in context.lnkwishlists
                        join wishlist in context.trnwishlists on wishlistItem.WishlistID equals wishlist.ID
                        join modelSize in context.lnkmodelsizes on wishlistItem.ModelSizeID equals modelSize.ID
                        join model in context.refmodels on modelSize.ModelID equals model.ID
                        join brand in context.refbrands on model.BrandID equals brand.ID
                        join modelColourDesc in context.lnkmodelcolourdescs on
                            new { ColourDescID = modelSize.ColourDescID, ModelID = modelSize.ModelID } equals
                            new { ColourDescID = modelColourDesc.ColourDescID, ModelID = modelColourDesc.ModelID }
                        join modelImage in context.lnkmodelimages on modelColourDesc.ID equals modelImage.ModelColourDescID
                        join colourDesc in context.refcolourdescs on modelColourDesc.ColourDescID equals colourDesc.ID
                        //join modelImages in context.lnkmodelimages on modelColourDesc.ID equals modelImages.ModelColourDescID
                        join category in context.refcategories on brand.CategoryID equals category.ID
                        select new
                        {
                            WishlistID = wishlist.ID,
                            Email = wishlist.Email,
                            WishlistItemID = wishlistItem.ID,
                            ModelName = model.Name,
                            Description = model.Description,
                            CategoryName = category.Name,
                            BrandName = brand.Name,
                            ColourName = colourDesc.Name,
                            Size = modelSize.Size,
                            ModelImage = modelImage.Image,
                            Active = wishlistItem.Active,
                            ModelID = model.ID,
                            ColourDescID = colourDesc.ID,
                            ModelSizeID = modelSize.ID,
                            SKU = modelColourDesc.SKU
                        };

            if (viewModel.WishlistID > 0)
                query = query.Where(a => a.WishlistID == viewModel.WishlistID && a.Active);
            else
            {
                var customerEmail = Util.SessionAccess.Email;
                query = query.Where(a => a.Email == customerEmail && a.Active);
            }

            var results = query.Distinct().ToList();

            if (viewModel.WishlistID == 0)
                viewModel.WishlistID = results.Select(a => a.WishlistID).Distinct().SingleOrDefault();

            var uniqueSishlistItemIDs = results.Select(a => a.WishlistItemID).Distinct().ToList();

            if (uniqueSishlistItemIDs.Count() > 0)
            {
                foreach (var id in uniqueSishlistItemIDs)
                {
                    var item = results.Where(a => a.WishlistItemID == id).First();
                    viewModel.WishlistItems.Add(new WishlistItem()
                    {
                        BrandName = item.BrandName,
                        ColourName = item.ColourName,
                        Description = item.Description,
                        ModelName = item.ModelName,
                        Size = item.Size,
                        Image = string.Format("~/Images/{0}/{1}", item.CategoryName.Replace(" ", ""), item.ModelImage),
                        WishlistItemID = item.WishlistItemID,
                        ModelID = item.ModelID,
                        ColourDescID = item.ColourDescID,
                        ModelSizeID = item.ModelSizeID,
                        SKU = item.SKU,
                        DetailsUrl = item.ModelSizeID > 0 ?
                                    Url.Action("Details", "Shoes", new { modelID = item.ModelID, colourDescID = item.ColourDescID, modelSizeID = item.ModelSizeID }) :
                                    Url.Action("Details", "Shoes", new { modelID = item.ModelID, colourDescID = item.ColourDescID })
                    });
                }
            }

            //foreach (var item in results)
            //{
            //    viewModel.WishlistItems.Add(new WishlistItem()
            //    {
            //        BrandName = item.BrandName,
            //        ColourName = item.ColourName,
            //        Description = item.Description,
            //        ModelName = item.ModelName,
            //        Size = item.Size,
            //        Image = string.Format("~/Images/{0}/{1}", item.CategoryName.Replace(" ", ""), item.ModelImage),
            //        WishlistItemID = item.WishlistItemID,
            //        ModelID = item.ModelID,
            //        ColourDescID = item.ColourDescID,
            //        ModelSizeID = item.ModelSizeID,
            //        SKU = item.SKU,
            //        DetailsUrl = item.ModelSizeID > 0 ?
            //                    Url.Action("Details", "Shoes", new { modelID = item.ModelID, colourDescID = item.ColourDescID, modelSizeID = item.ModelSizeID }) :
            //                    Url.Action("Details", "Shoes", new { modelID = item.ModelID, colourDescID = item.ColourDescID })
            //    });
            //}
        }
Exemplo n.º 3
0
        private void GetCustomizeModel(WishlistIndexViewModel viewModel, TTTEntities context)
        {
            var query = from wishlistItem in context.lnkwishlists
                        join wishlist in context.trnwishlists on wishlistItem.WishlistID equals wishlist.ID
                        join customizeModelImage in context.lnkcustomizemodelimages on wishlistItem.SKU equals customizeModelImage.SKU
                        join customizeModel in context.refcustomizemodels on customizeModelImage.CustomizeModelID equals customizeModel.ID
                        select new
                        {
                            WishlistID = wishlist.ID,
                            Email = wishlist.Email,
                            WishlistItemID = wishlistItem.ID,
                            ModelName = customizeModel.Name,
                            Description = customizeModel.Description,
                            CategoryName = "",
                            BrandName = "",
                            ColourName = customizeModelImage.Colour,
                            Size = wishlistItem.Size,
                            ModelImage = customizeModel.MainImage,
                            Active = wishlistItem.Active,
                            SKU = customizeModelImage.SKU
                        };


            if (viewModel.WishlistID > 0)
                query = query.Where(a => a.WishlistID == viewModel.WishlistID && a.Active);
            else
            {
                var customerEmail = Util.SessionAccess.Email;
                query = query.Where(a => a.Email == customerEmail && a.Active);
            }

            var results = query.Distinct().ToList();

            if (viewModel.WishlistID == 0)
                viewModel.WishlistID = results.Select(a => a.WishlistID).Distinct().SingleOrDefault();

            foreach (var item in results)
            {
                viewModel.WishlistItems.Add(new WishlistItem()
                {
                    BrandName = item.BrandName,
                    ColourName = item.ColourName,
                    Description = item.Description,
                    ModelName = item.ModelName,
                    Size = item.Size,
                    Image = string.Format("~/Images/Customize/ShoeStyle/{0}", item.ModelImage),
                    WishlistItemID = item.WishlistItemID,
                    SKU = item.SKU,
                    DetailsUrl = Url.Action("ShoeDetails", "Customize", new { sku = item.SKU })
                });
            }
        }