コード例 #1
0
        public InfographicViewModel GetInfographicViewModel(string id, string language)
        {
            Infographic infographic;
            int info_id;
            bool parse_result = Int32.TryParse(id, out info_id);
            bool isArabic = false;

            if (parse_result) //id provided
            {
                infographic = DbContext.Infographics.Where(i => i.ID == info_id).Include(i => i.InfographicCategory).FirstOrDefault();
                if (language == "ar")
                    isArabic = true;
            }else //friendly url
            {
                infographic = DbContext.Infographics.Where(i => i.FriendlyURL == id).Include(i => i.InfographicCategory).FirstOrDefault();

                if(infographic == null)
                {
                    isArabic = true;
                    infographic = DbContext.Infographics.Where(i => i.FriendlyURLAr == id).Include(i => i.InfographicCategory).FirstOrDefault();
                }
            }

            if (infographic == null)
                return null;

            InfographicViewModel result = new InfographicViewModel();
            result.CategoryOrder = infographic.InfographicCategory.Order;
            if(isArabic)
            {
                result.FriendlyURL = infographic.FriendlyURLAr;
                result.ID = infographic.ID;
                result.ImageURL = infographic.ImageURLAr;
                result.ThumbURL = infographic.ThumbURLAr;
                result.Order = infographic.Order;
                result.Name = infographic.NameAr;
                result.MetaDescription = infographic.MetaDescriptionAr;

                if( result.FriendlyURL == null ||  result.FriendlyURL == "")
                    result.FriendlyURL = infographic.FriendlyURL;

                if (result.ImageURL == null || result.ImageURL == "")
                    result.ImageURL = infographic.ImageURL;

                if (result.ThumbURL == null || result.ThumbURL == "")
                    result.ThumbURL = infographic.ThumbURL;

                if (result.Name == null || result.Name == "")
                    result.Name = infographic.Name;

                if (result.MetaDescription == null || result.MetaDescription == "")
                    result.MetaDescription = infographic.MetaDescription;
            }
            else
            {
                result.FriendlyURL = infographic.FriendlyURL;
                result.ID = infographic.ID;
                result.ImageURL = infographic.ImageURL;
                result.ThumbURL = infographic.ThumbURL;
                result.Order = infographic.Order;
                result.Name = infographic.Name;
                result.MetaDescription = infographic.MetaDescription;
            }

            return result;
        }
コード例 #2
0
        public InfographicSetViewModel GetInfographicsViewModel(string language, int order)
        {
            InfographicSetViewModel result = new InfographicSetViewModel();
            result.Categories = new List<InfographicCategoryViewModel>();

            //get all categories included
            List<InfographicCategory> categories = DbContext.InfographicCategories.Where(c => c.Order == order || order == 0).Include(c => c.Infographics).ToList();

            foreach(InfographicCategory cat in categories)
            {
                InfographicCategoryViewModel cat_viewmodel = new InfographicCategoryViewModel();
                if (language.Contains("ar"))
                {
                    cat_viewmodel.Description = cat.DescriptionAr;
                    cat_viewmodel.Name = cat.NameAr;
                }
                else
                {
                    cat_viewmodel.Description = cat.Description;
                    cat_viewmodel.Name = cat.Name;
                }
                cat_viewmodel.Order = cat.Order;
                cat_viewmodel.Infographics = new List<InfographicViewModel>();

                foreach(Infographic info in cat.Infographics)
                {
                    InfographicViewModel info_viewmodel = new InfographicViewModel();
                    if (language.Contains("ar"))
                    {
                        info_viewmodel.FriendlyURL = info.FriendlyURLAr;
                        info_viewmodel.ID = info.ID;
                        info_viewmodel.ImageURL = info.ImageURLAr;
                        info_viewmodel.Name = info.NameAr;
                        info_viewmodel.Order = info.Order;
                        info_viewmodel.ThumbURL = info.ThumbURLAr;
                        if (info_viewmodel.FriendlyURL == null || info_viewmodel.FriendlyURL == "")
                            info_viewmodel.FriendlyURL = info.FriendlyURL;
                        if (info_viewmodel.ImageURL == null || info_viewmodel.ImageURL == "")
                            info_viewmodel.ImageURL = info.ImageURL;
                        if (info_viewmodel.Name == null || info_viewmodel.Name == "")
                            info_viewmodel.Name = info.Name;
                        if (info_viewmodel.ThumbURL == null || info_viewmodel.ThumbURL == "")
                            info_viewmodel.ThumbURL = info.ThumbURL;
                    }
                    else
                    {
                        info_viewmodel.FriendlyURL = info.FriendlyURL;
                        info_viewmodel.ID = info.ID;
                        info_viewmodel.ImageURL = info.ImageURL;
                        info_viewmodel.Name = info.Name;
                        info_viewmodel.Order = info.Order;
                        info_viewmodel.ThumbURL = info.ThumbURL;
                    }

                    cat_viewmodel.Infographics.Add(info_viewmodel);
                }

                result.Categories.Add(cat_viewmodel);
            }

            return result;
        }