コード例 #1
0
        public VMDetailGame GetGameDetails(string titleUrl, int amount = 10)
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                var viewModel = connection.Query <VMDetailGame>("get_game_by_url @titleUrl", new { titleUrl = titleUrl }).SingleOrDefault();
                if (viewModel == null)
                {
                    return(null);
                }

                viewModel.Materials = connection.Query <VMMaterial>("get_game_materials @titleUrl, @amount", new { titleUrl = titleUrl, amount = amount }).ToArray();
                viewModel.Videos    = connection.Query <SxVMVideo>("get_game_videos @titleUrl", new { titleUrl = titleUrl }).ToArray();
                if (viewModel.Videos.Any())
                {
                    var html = viewModel.FullDescription;
                    SxBBCodeParser.ReplaceVideos(ref html, viewModel.Videos);
                    viewModel.FullDescription = html;
                }

                if (viewModel.Materials.Any())
                {
                    FillMaterialsVideo(connection, viewModel.Materials);
                }

                return(viewModel);
            }
        }
コード例 #2
0
        public virtual ActionResult Details(int year, string month, string day, string titleUrl)
        {
            var viewModel = Repo.GetByTitleUrl(year, month, day, titleUrl);

            if (viewModel == null)
            {
                return(new HttpNotFoundResult());
            }

            nowReadingMaterial = Mapper.Map <TViewModel, VMArticle>(viewModel);

            SxBBCodeParser.Replace(nowReadingMaterial);

            return(View(viewModel));
        }
コード例 #3
0
        public virtual async Task <ActionResult> Details(int year, string month, string day, string titleUrl)
        {
            VMMaterial model = null;

            switch (ModelCoreType)
            {
            case 1:    //article
                model = await Repo.GetByTitleUrlAsync(year, month, day, titleUrl);

                break;

            case 2:    //news
                model = await Repo.GetByTitleUrlAsync(year, month, day, titleUrl);

                break;

            case 7:    //humor
                model = await Repo.GetByTitleUrlAsync(year, month, day, titleUrl);

                break;
            }

            if (model == null)
            {
                return(new HttpNotFoundResult());
            }

            SxBBCodeParser.Replace(
                material: model,
                pictureUrl: x => Url.Action("Picture", "Pictures", new { id = x.Id }),
                videoUrl: x => Url.Action("Details", "YoutubeVideos", new { videoId = x.VideoId }),
                replaceOtherAction: replaceInfographics
                );

            var seoTags = await SxSeoTagsController.Repo.GetSeoTagsAsync(model.Id, model.ModelCoreType);

            var matSeoInfo = Mapper.Map <SxSeoTags, SxVMSeoTags>(seoTags);

            ViewBag.Title       = ViewBag.Title ?? matSeoInfo?.SeoTitle ?? model.Title;
            ViewBag.Description = ViewBag.Description ?? matSeoInfo?.SeoDescription ?? model.Foreword;
            ViewBag.Keywords    = ViewBag.Keywords ?? matSeoInfo?.KeywordsString;
            ViewBag.H1          = ViewBag.H1 ?? matSeoInfo?.H1 ?? model.Title;
            ViewBag.PageImage   = ViewBag.PageImage ?? matSeoInfo?.PageImageId;

            CultureInfo ci = new CultureInfo("en-US");

            ViewBag.LastModified = model.DateUpdate.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", ci);

            if (model.Game != null)
            {
                ViewBag.GameName = model.Game.TitleUrl.ToLower();
            }

            var breadcrumbs = (SxVMBreadcrumb[])ViewBag.Breadcrumbs;

            if (breadcrumbs != null)
            {
                var bc = breadcrumbs.ToList();
                if (model.Category != null)
                {
                    bc.Add(new SxVMBreadcrumb {
                        Title = model.Category.Title, Url = Url.Action("Index", new { cat = model.Category.Id })
                    });
                }

                bc.Add(new SxVMBreadcrumb {
                    Title = ViewBag.Title
                });
                ViewBag.Breadcrumbs = bc.ToArray();
            }

            if (!Request.IsLocal)
            {
                //update views count
                await Repo.AddUserViewAsync(model.Id, model.ModelCoreType, () => {
                    model.ViewsCount++;
                });
            }

            return(View(model));
        }