public CategoryMenuDTO GetRandomCategory(Langs l, WebSites w) { long languageId = Utils.getLanguage(l); var list = unitOfWork.CategoryRepository.Get(c => true).AsEnumerable().Where(c => (long)getWebsite(c.Id) == (long)w); Random random = new Random(); long seed = random.Next(); list = list.OrderBy(s => (~(s.Id & seed)) & (s.Id | seed)); // ^ seed); if (!list.Any()) { return(null); } var first = list.First(); Mapper.Initialize(cfg => cfg.CreateMap <Category, CategoryMenuDTO>() .ForMember(dest => dest.EnglishName, opt => opt.MapFrom(src => src.CategoryDescriptions.Where(dsc => dsc.LanguageId == (long)Langs.English).FirstOrDefault().Name) ) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.CategoryDescriptions.Where(dsc => dsc.LanguageId == (long)l).FirstOrDefault().Name)) .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.ImageUrl ?? DefaultImages.Category) ).ForMember(dest => dest.Banner, opt => opt.MapFrom(src => src.Banner ?? DefaultImages.Banner) ) ); //CategoryMenuDTO menuCategoryDTO = Mapper.Map<Category, CategoryMenuDTO>(first); CategoryMenuDTO menuCategoryDTO = Mapper.Map <Category, CategoryMenuDTO>(first, opt => opt.AfterMap((src, dest) => dest.Name = src.CategoryDescriptions.Where(dsc => dsc.LanguageId == (long)l).FirstOrDefault().Name)); return(menuCategoryDTO); }
public CategoryMenuDTO GetAll(Langs l, WebSites w) { CategoryMenuDTO ctmDTO = GetAll(l); ctmDTO.SubCategories = ctmDTO.SubCategories.AsEnumerable().Where(c => c.Id == (long)w).FirstOrDefault().SubCategories; return(ctmDTO); }
public CategoryMenuDTO GetAll(Langs l) { CategoryMenuDTO allCategories = new CategoryMenuDTO(); allCategories.SubCategories = new List <CategoryMenuDTO>(); allCategories.SubCategories.Add(GetClothesCategory(l)); allCategories.SubCategories.Add(GetTechnoCategory(l)); allCategories.SubCategories.Add(GetGymCategory(l)); return(allCategories); }
public CategoryMenuDTO getSubCategories(long categoryId, long languageId) { List <CategoryMenuDTO> subMenuCategoryDTOs = new List <CategoryMenuDTO>(); var category = unitOfWork.CategoryRepository.GetByID(categoryId); var config = new MapperConfiguration( cfg => cfg.CreateMap <Category, CategoryMenuDTO>() .ForMember(dest => dest.EnglishName, opt => opt.MapFrom(src => src.CategoryDescriptions.Where(dsc => dsc.LanguageId == (long)Langs.English).FirstOrDefault().Name) ) //.ForMember(dest => dest.Name, opt => // opt.MapFrom(src => src.CategoryDescriptions.Where(dsc => dsc.LanguageId == languageId).FirstOrDefault().Name) //) .ForMember(dest => dest.ImageUrl, opt => opt.MapFrom(src => src.ImageUrl ?? DefaultImages.Category) ).ForMember(dest => dest.Banner, opt => opt.MapFrom(src => src.Banner ?? DefaultImages.Banner) ) ); var mapper = config.CreateMapper(); //Mapper.Initialize(cfg => cfg.CreateMap<Category, CategoryMenuDTO>() // .ForMember(dest => dest.EnglishName, opt => // opt.MapFrom(src => src.CategoryDescriptions.Where(dsc => dsc.LanguageId == (long)Langs.English).FirstOrDefault().Name) // ) // //.ForMember(dest => dest.Name, opt => // // opt.MapFrom(src => src.CategoryDescriptions.Where(dsc => dsc.LanguageId == languageId).FirstOrDefault().Name) // //) // .ForMember(dest => dest.ImageUrl, opt => // opt.MapFrom(src => src.ImageUrl ?? DefaultImages.Category) // ).ForMember(dest => dest.Banner, opt => // opt.MapFrom(src => src.Banner ?? DefaultImages.Banner) // ) //); //CategoryMenuDTO menuCategoryDTO = Mapper.Map<Category, CategoryMenuDTO>(category); CategoryMenuDTO menuCategoryDTO = mapper.Map <Category, CategoryMenuDTO>(category, opt => opt.AfterMap((src, dest) => dest.Name = src.CategoryDescriptions.Where(dsc => dsc.LanguageId == languageId).FirstOrDefault().Name)); menuCategoryDTO.Name = category.CategoryDescriptions.Where(dsc => dsc.LanguageId == languageId).FirstOrDefault().Name; menuCategoryDTO.EnglishName = category.CategoryDescriptions.Where(dsc => dsc.LanguageId == (long)Langs.English).FirstOrDefault().Name; List <Category> subCategories = unitOfWork.CategoryRepository.Get(c => c.Status == true && c.ParentId == categoryId).OrderBy(c => c.SortOrder).ToList(); foreach (var cat in subCategories) { subMenuCategoryDTOs.Add(getSubCategories(cat.Id, languageId)); } subMenuCategoryDTOs.OrderBy(c => c.SortOrder); menuCategoryDTO.SubCategories = subMenuCategoryDTOs; return(menuCategoryDTO); }
public PartialViewResult MenuArea() { //MenuCategoryDTO m = new MenuCategoryDTO(); //m = m.Create(3); //Mapper.Initialize(cfg => cfg.CreateMap<MenuCategoryDTO, MenuCategoryVM>()); //MenuCategoryVM vm = Mapper.Map<MenuCategoryDTO, MenuCategoryVM>(m); CategoryMenuDTO menuDto = _categoryService.GetAll(CurrentLanguage, CurrentWebsite); Mapper.Initialize(cfg => cfg.CreateMap <CategoryMenuDTO, CategoryMenuVM>() ); CategoryMenuVM vm = Mapper.Map <CategoryMenuDTO, CategoryMenuVM>(menuDto); return(PartialView("_MenuArea", vm)); }
public PartialViewResult SearchByCategory() { CategoryMenuDTO menuDto = _categoryService.GetAll(CurrentLanguage, CurrentWebsite); Mapper.Initialize(cfg => cfg.CreateMap <CategoryMenuDTO, CategoryMenuVM>()); CategoryMenuVM vm = Mapper.Map <CategoryMenuDTO, CategoryMenuVM>(menuDto); SearchVM svm = new SearchVM() { CategoryId = Int32.Parse(Request.QueryString["CategoryId"] ?? "-1"), SearchText = Request.QueryString["SearchText"] ?? "", Categories = vm }; return(PartialView("_SearchPartialView", svm)); }
public DataControllerMessage <MenuDTO> GetMenu() { string message = String.Empty; bool success = true; MenuDTO data = new MenuDTO(); try { var categoryEntities = unitOfWork.Categories.GetAll().OrderBy(category => category.Name); foreach (CategoryEntity categoryEntity in categoryEntities) { CategoryMenuDTO category = new CategoryMenuDTO { NewName = categoryEntity.Name, OldName = categoryEntity.Name, Dishes = categoryEntity.Dishes.Select(dish => new DishMenuDTO { NewName = dish.Name, OldName = dish.Name, Price = dish.Price }) .OrderBy(dish => dish.OldName) .ToList() }; data.Categories.Add(category); } } catch (Exception ex) { success = false; message = ExceptionMessageBuilder.BuildMessage(ex); } return(new DataControllerMessage <MenuDTO>(success, message, data)); }
public FilterMenuDTO FilterFilters(String categoryName, String[] designers, String[] subCategories, String[] colorNames, String[] sizeNames, String[] tags, double lowPrice, double highPrice, Sorts s, Currency currency, Langs l) { List <ProductDTO> products = Filter(categoryName, designers, subCategories, colorNames, sizeNames, tags, lowPrice, highPrice, s, currency, l); // long baseCategoryId = GetCategoryIdByName(categoryName, l); List <long> productIds; if (products == null) { productIds = new List <long>(); } else { productIds = products.Select(p => p.Id).ToList(); } FilterMenuDTO filterMenuDTO = new FilterMenuDTO(); filterMenuDTO.Products = products; filterMenuDTO.Categories = new List <Tuple <CategoryMenuDTO, int> >(); long categoryId; List <Category> categoriess; if (!String.IsNullOrWhiteSpace(categoryName)) { categoryId = GetCategoryIdByName(categoryName, l); categoriess = unitOfWork.CategoryRepository.Get(c => c.ParentId == categoryId).ToList(); } else { categoriess = unitOfWork.CategoryRepository.Get(c => true).ToList(); var realCategories = new List <Category>(); foreach (var category in categoriess) { if (!unitOfWork.CategoryRepository.Get(c => c.ParentId == category.Id).Any()) { realCategories.Add(category); } } categoriess = realCategories; } foreach (var category in categoriess) { string ctgryName = category.CategoryDescriptions.Where(c => c.LanguageId == (long)Langs.English).Select(c => c.Name).FirstOrDefault(); var categoryProducts = productService.GetCategoryTreeProducts(ctgryName, Langs.English, currency); List <long> Ids; if (categoryProducts == null || categoryProducts.Count == 0) { Ids = new List <long>(); } else { Ids = categoryProducts.Select(c => c.Id).ToList(); } CategoryMenuDTO cat = GetCategoryFilters(ctgryName, l); int count = Ids.Intersect(productIds).Count(); if (count != 0) { filterMenuDTO.Categories.Add(new Tuple <CategoryMenuDTO, int>(cat, count)); } } List <long> designerIds = unitOfWork.ProductRepository.Get(c => productIds.Contains(c.Id)).Select(c => c.DesignerId).Distinct().ToList(); List <DesignerDTO> designerss = GetDesignerFilters(designerIds, l); filterMenuDTO.Designers = new List <Tuple <DesignerDTO, int> >(); foreach (var des in designerss) { Designer dsgnrs = unitOfWork.DesignerDescriptionRepository .Get(c => c.Text == des.DesignerName).FirstOrDefault().Designer; List <long> Ids = dsgnrs.Products.Select(c => c.Id).ToList(); int count = Ids.Intersect(productIds).Count(); if (count != 0) { filterMenuDTO.Designers.Add(new Tuple <DesignerDTO, int>(des, count)); } } List <long> tagIds = new List <long>(); var productss = unitOfWork.ProductRepository.Get(c => productIds.Contains(c.Id)).ToList(); foreach (var product in productss) { foreach (var sku in product.ProductSKUs) { tagIds = tagIds.Union(sku.Tags.Where(t => t.LanguageId == (long)l).Select(t => t.Id)).Distinct().ToList(); } } filterMenuDTO.Tags = GetTagsFilter(tagIds, l); filterMenuDTO.Colors = GetColorFilters(productIds, l); filterMenuDTO.Sizes = GetSizeFilters(productIds, l); filterMenuDTO.minPrice = !products.Any() ? 0 : products.Min(c => c.Price); filterMenuDTO.maxPrice = !products.Any() ? 0 : products.Max(c => c.Price); return(filterMenuDTO); }
/* * d => Designer, cat => Sub Categories, c => Colors,s => sizes,pNumber =>PageNumber .. */ public ActionResult Browse(String categoryName, String[] d, String[] cat, String[] c, String[] s, String [] t, int MinPrice = 0, int MaxPrice = 1000, int pNumber = 1, int pSize = PAGE_SIZE, String Show = "g", Sorts SortBy = Sorts.NameUpDown) { ShopGridVM vm = new ShopGridVM(); List <ProductDTO> productDtos = new List <ProductDTO>(); // for (int i = 1; i < 25; i++) // { // productDtos.Add(new ProductDTO(i * 100, "Small", -1)); // productDtos.Add(new ProductDTO(i * 101, "أحمر")); // productDtos.Add(new ProductDTO(i * 102)); // productDtos.Add(new ProductDTO(i * 103, "أحمر", "Small")); //if (i%2 == 0) //{ // productDtos.Add(new ProductDTO(i, "أحمر")); //} //else if(i%3 ==0) //{ // productDtos.Add(new ProductDTO(i)); //} //else if (i%5 == 0) //{ // productDtos.Add(new ProductDTO(i, "أحمر","Small")); //} //else if (i%7 == 0) //{ // productDtos.Add(new ProductDTO(i, "Small",-1)); //} //} FilterMenuDTO filters = _productFilterService.FilterFilters(categoryName, d, cat, c, s, t, MinPrice, MaxPrice, SortBy, CurrentCurrency, CurrentLanguage); #region Manual Filters //List<CategoryFilterVM> categories = new List<CategoryFilterVM>() //{ // new CategoryFilterVM() // { // Name = "بنطال", // Checked = false // }, // new CategoryFilterVM() // { // Name = "بلوزة", // Checked = false // } //}; //List<ColorFilterVM> colors = new List<ColorFilterVM>() //{ // new ColorFilterVM() // { // Name = "أحمر", // Checked = false, // Image = "#00ff00", // IsImage = false // }, // new ColorFilterVM() // { // Name = "أخضر", // Checked = false, // Image = "#0000ff", // IsImage = false // } //}; //List<SizeFilterVM> sizes = new List<SizeFilterVM>() //{ // new SizeFilterVM() // { // Name = "صغير", // Checked = false // }, // new SizeFilterVM() // { // Name = "XL", // Checked = false // } //}; //List<PriceFilter> prices = new List<PriceFilter>() //{ // new PriceFilter() // { // Price = new Tuple<int, int>(20,50), // Checked = false // }, // new PriceFilter() // { // Price = new Tuple<int, int>(50,100), // Checked = false // } //}; //List<DesignerFilterVM> designers = new List<DesignerFilterVM>() //{ // new DesignerFilterVM() // { // Checked = false, // Id = 1, // Name = "هاني" // }, // new DesignerFilterVM() // { // Checked = false, // Id = 2, // Name = "عصام" // } //}; //if (d != null) // foreach (String item in d) // { // DesignerFilterVM dd = designers.Where(ddd => ddd.Name == item).FirstOrDefault(); // if (dd != null) // dd.Checked = true; // } //if (cat != null) // foreach (String item in cat) // { // CategoryFilterVM dd = categories.Where(ddd => ddd.Name == item).FirstOrDefault(); // if (dd != null) // dd.Checked = true; // } //if (c != null) // foreach (String item in c) // { // ColorFilterVM dd = colors.Where(ddd => ddd.Name == item).FirstOrDefault(); // if (dd != null) // dd.Checked = true; // } //if (s != null) // foreach (String item in s) // { // SizeFilterVM dd = sizes.Where(ddd => ddd.Name == item).FirstOrDefault(); // if (dd != null) // dd.Checked = true; // } #endregion #region Category Automatic Filter List <Tuple <CategoryMenuDTO, int> > categoryDTO = filters.Categories; // _productFilterService.GetCategoryFilters(categoryName, CurrentLanguage); List <CategoryFilterVM> categories = new List <CategoryFilterVM>(); foreach (var categoryfilter in categoryDTO) { categories.Add(new CategoryFilterVM() { Name = categoryfilter.Item1.Name, EnglishName = Utils.GenerateSlug(categoryfilter.Item1.EnglishName), Checked = cat != null && cat.Contains(Utils.GenerateSlug(categoryfilter.Item1.EnglishName)), Count = categoryfilter.Item2 }); } #endregion #region Size Automatic Filter List <SizeValueDTO> sizeDtos = filters.Sizes;//_productFilterService.GetSizeFilters(categoryName, CurrentLanguage); List <SizeFilterVM> sizes = new List <SizeFilterVM>(); foreach (var sizeValueDto in sizeDtos) { sizes.Add(new SizeFilterVM() { Name = sizeValueDto.Name, EnglishName = sizeValueDto.EnglishName, Checked = s != null && s.Contains(sizeValueDto.EnglishName) }); } #endregion #region color Automatic Filter List <ColorValuesDTO> colorDtos = filters.Colors;// _productFilterService.GetColorFilters(categoryName, CurrentLanguage); List <ColorFilterVM> colors = new List <ColorFilterVM>(); foreach (var colorValueDto in colorDtos) { colors.Add(new ColorFilterVM() { Name = colorValueDto.ColorName, EnglishName = colorValueDto.ColorName, Checked = c != null && c.Contains(colorValueDto.ColorName), Image = colorValueDto.Image, IsImage = colorValueDto.IsImages }); } #endregion #region Deisner Automatic Filter List <Tuple <DesignerDTO, int> > designerDtos = filters.Designers;//_productFilterService.GetDesignerFilters(categoryName, CurrentLanguage); List <DesignerFilterVM> designers = new List <DesignerFilterVM>(); foreach (var designerDto in designerDtos) { designers.Add(new DesignerFilterVM() { Name = designerDto.Item1.DesignerName, Id = designerDto.Item1.DesignerId, Checked = d != null && d.Contains(designerDto.Item1.DesignerName), Count = designerDto.Item2 }); } #endregion #region Tags Automatic Filter List <TagDTO> tagDtos = filters.Tags;//_productFilterService.GetSizeFilters(categoryName, CurrentLanguage); List <TagVM> tags = new List <TagVM>(); foreach (var tag in tagDtos) { tags.Add(new TagVM() { Name = tag.Name, Checked = t != null && t.Contains(tag.Name) }); } #endregion vm.Categories = categories; vm.Colors = colors; vm.Designers = designers; vm.Sizes = sizes; vm.Tags = tags; // vm.ProductDtos = productDtos.ToPagedList(pNumber, pSize); // vm.ProductDtos = _productService.GetCategoryTreeProducts(categoryName, CurrentLanguage).ToPagedList(pNumber, pSize); productDtos = filters.Products;//_productFilterService.Filter(categoryName, d, cat, c, s,MinPrice,MaxPrice, SortBy,CurrentCurrency,CurrentLanguage); // productDtos.AddRange(productDtos); // productDtos.AddRange(productDtos); // productDtos.AddRange(productDtos); vm.ProductDtos = productDtos.ToPagedList(pNumber, pSize); vm.PageSize = pSize; vm.PageNumber = pNumber; vm.Show = Show; vm.SortBy = SortBy; vm.MinPrice = (Int32)filters.minPrice; vm.MaxPrice = (Int32)filters.maxPrice; long categoryId = _productService.GetCategoryIdByName(categoryName, CurrentLanguage); CategoryMenuDTO category = _categoryService.GetCategory(categoryId, CurrentLanguage); vm.categoryName = categoryName; vm.Name = category.Name; vm.Banner = category.Banner; ViewBag.Title = "استعراض المنتجات - " + category.Name; return(View(vm)); }