Beispiel #1
0
        public ActionResult <IEnumerable <TalentsCategorizedVM> > GetCategorized()
        {
            try
            {
                List <TalentsCategorizedVM> talentsCategorizedVM = new List <TalentsCategorizedVM>();
                List <Category>             categories           = new List <Category>();

                var featuredTalents = TalentSearchService.GetFeatured(null, 10);
                if (featuredTalents.Count() > 0)
                {
                    var featuredTalentsVM = new TalentsCategorizedVM(
                        new Category()
                    {
                        ID   = (int)CategoryEnum.featured,
                        Name = "Популярные"
                    },
                        featuredTalents.ToList());
                    talentsCategorizedVM.Add(featuredTalentsVM);
                }

                var newTalents = TalentSearchService.GetNew(null, 10);
                if (newTalents.Count() > 0)
                {
                    var newTalentsVM = new TalentsCategorizedVM(
                        new Category()
                    {
                        ID   = (int)CategoryEnum.neW,
                        Name = "Новые"
                    },
                        newTalents.ToList());
                    talentsCategorizedVM.Add(newTalentsVM);
                }

                categories.AddRange(CategoryService.GetAllActive());
                foreach (var category in categories)
                {
                    var talentsCategorized = TalentSearchService.Search(category.ID, SortTypeEnum.def, 10);
                    if (talentsCategorized.Count() > 0)
                    {
                        var categoryTalentsVM = new TalentsCategorizedVM(category, talentsCategorized.ToList());

                        talentsCategorizedVM.Add(categoryTalentsVM);
                    }
                }

                foreach (var categoryTalentsVM in talentsCategorizedVM)
                {
                    foreach (var talent in categoryTalentsVM.talents)
                    {
                        if (talent.avatar == null || talent.avatar.id == 0)
                        {
                            talent.avatar     = new AttachmentDetailsVM();
                            talent.avatar.url = TalentService.GetRandomPhotoUrl();
                        }
                    }
                }

                return(talentsCategorizedVM);
            }
            catch (Exception ex)
            {
                return(CustomBadRequest(ex));
            }
        }
Beispiel #2
0
        public ActionResult <IEnumerable <TalentsCategorizedVM> > GetByCategory(int category_id)
        {
            try
            {
                //1. if category = new then
                //  - all in new
                //2. if category = featured then:
                //  - featured
                //  - new in featured
                //  - all in featured
                //3. else (if normal category)
                //  - featured in category
                //  - new in category
                //  - all in category

                List <TalentsCategorizedVM> talentsCategorizedVM = new List <TalentsCategorizedVM>();

                if (category_id == (int)CategoryEnum.neW)
                {
                    var newTalents = TalentSearchService.GetNew(null);
                    if (newTalents.Count() > 0)
                    {
                        var newTalentsVM = new TalentsCategorizedVM(
                            new Category()
                        {
                            ID   = (int)CategoryEnum.neW,
                            Name = "Все новые"
                        },
                            newTalents.ToList());
                        talentsCategorizedVM.Add(newTalentsVM);
                    }
                }
                else if (category_id == (int)CategoryEnum.featured)
                {
                    //DO NOT DELETE THIS CODE!!!
                    //must be uncommented later when number of telants will be large

                    //var featuredTalents = TalentService.GetFeatured(null, 6);
                    //if (featuredTalents.Count() > 0)
                    //{
                    //    var featuredTalentsVM = new TalentsCategorizedVM(
                    //        new Category()
                    //        {
                    //            ID = (int)CategoryEnum.featured,
                    //            Name = "Популярные"
                    //        },
                    //        featuredTalents.ToList());
                    //    talentsCategorizedVM.Add(featuredTalentsVM);
                    //}

                    //var newTalents = TalentService.GetNewInFeatured(6);
                    //if (newTalents.Count() > 0)
                    //{
                    //    var newTalentsVM = new TalentsCategorizedVM(
                    //        new Category()
                    //        {
                    //            ID = (int)CategoryEnum.neW,
                    //            Name = "Новые"
                    //        },
                    //        newTalents.ToList());
                    //    talentsCategorizedVM.Add(newTalentsVM);
                    //}

                    var allTalents = TalentSearchService.GetFeatured(null);
                    if (allTalents.Count() > 0)
                    {
                        var allTalentsVM = new TalentsCategorizedVM(
                            new Category()
                        {
                            ID   = (int)CategoryEnum.neW,
                            Name = "Все Популярные"
                        },
                            allTalents.ToList());
                        talentsCategorizedVM.Add(allTalentsVM);
                    }
                }
                else
                {
                    var categoryDB = CategoryService.GetActiveByID(category_id);
                    if (categoryDB == null)
                    {
                        throw new Exception("Category not found");
                    }

                    //DO NOT DELETE THIS CODE!!!
                    //must be uncommented later when number of telants will be large

                    //var featuredTalents = TalentService.GetFeatured(categoryID, 6);
                    //if (featuredTalents.Count() > 0)
                    //{
                    //    var featuredTalentsVM = new TalentsCategorizedVM(
                    //        new Category()
                    //        {
                    //            ID = (int)CategoryEnum.featured,
                    //            Name = "Популярные"
                    //        },
                    //        featuredTalents.ToList());
                    //    talentsCategorizedVM.Add(featuredTalentsVM);
                    //}

                    //var newTalents = TalentService.GetNew(categoryID, 6);
                    //if (newTalents.Count() > 0)
                    //{
                    //    var newTalentsVM = new TalentsCategorizedVM(
                    //        new Category()
                    //        {
                    //            ID = (int)CategoryEnum.neW,
                    //            Name = "Новые"
                    //        },
                    //        newTalents.ToList());
                    //    talentsCategorizedVM.Add(newTalentsVM);
                    //}

                    var allTalents = TalentSearchService.Search(category_id, SortTypeEnum.def);
                    if (allTalents.Count() > 0)
                    {
                        var allTalentsVM = new TalentsCategorizedVM(
                            new Category()
                        {
                            ID   = (int)CategoryEnum.neW,
                            Name = "Все"
                        },
                            allTalents.ToList());
                        talentsCategorizedVM.Add(allTalentsVM);
                    }
                }

                foreach (var categoryTalentsVM in talentsCategorizedVM)
                {
                    foreach (var talent in categoryTalentsVM.talents)
                    {
                        if (talent.avatar == null || talent.avatar.id == 0)
                        {
                            talent.avatar     = new AttachmentDetailsVM();
                            talent.avatar.url = TalentService.GetRandomPhotoUrl();
                        }
                    }
                }

                return(talentsCategorizedVM);
            }
            catch (Exception ex)
            {
                return(CustomBadRequest(ex));
            }
        }