Exemplo n.º 1
0
        private static void FillMaterialsVideo(IDbConnection connection, IReadOnlyList <VMMaterial> materials)
        {
            VMMaterial item = null;

            var table = new DataTable();

            table.Columns.Add("Materialid", typeof(int));
            table.Columns.Add("ModelCoreType", typeof(int));

            for (var i = 0; i < materials.Count; i++)
            {
                item = materials[i];
                table.Rows.Add(item.Id, (int)item.ModelCoreType);
            }

            var videoLinks = connection.Query <SxVideoLink, SxVideo, SxVideoLink>("dbo.get_materials_videos", (vl, v) =>
            {
                vl.Video = v;
                return(vl);
            }, new { materials = table.AsTableValuedParameter("dbo.ForSelectMaterials") }, commandType: CommandType.StoredProcedure, splitOn: "Id").ToArray();

            for (var i = 0; i < materials.Count; i++)
            {
                item        = materials[i];
                item.Videos = videoLinks.Where(x => Equals(x.MaterialId, item.Id) && x.ModelCoreType == item.ModelCoreType).Select(x => Mapper.Map <SxVideo, SxVMVideo>(x.Video)).ToArray();
            }
        }
        public override PartialViewResult Last(byte?mct = null, int amount = 5, int?mid = null)
        {
            var data = (Repo as RepoArticle).GetLast(mct, amount, mid, new[] {
                SxMvcApplication.ModelCoreTypeProvider[nameof(Article)],
                SxMvcApplication.ModelCoreTypeProvider[nameof(News)]
            });

            var          viewModel = new VMMaterial[data.Length];
            SxVMMaterial item      = null;

            for (int i = 0; i < data.Length; i++)
            {
                item = data[i];
                switch (item.ModelCoreType)
                {
                case 1:
                    viewModel[i] = new VMArticle {
                        Title = item.Title, TitleUrl = item.TitleUrl, DateCreate = item.DateCreate, ModelCoreType = item.ModelCoreType
                    };
                    break;

                case 2:
                    viewModel[i] = new VMNews {
                        Title = item.Title, TitleUrl = item.TitleUrl, DateCreate = item.DateCreate, ModelCoreType = item.ModelCoreType
                    };
                    break;
                }
            }

            return(PartialView("_Last", viewModel));
        }
        public sealed override PartialViewResult Popular(int?mct = default(int?), int?mid = default(int?), int amount = 4)
        {
            var          mctProvider = MvcApplication.ModelCoreTypeProvider;
            var          data        = Repo.GetPopular(mct, mid, amount);
            var          viewModel   = new VMMaterial[data.Length];
            SxVMMaterial item        = null;

            for (int i = 0; i < data.Length; i++)
            {
                item = data[i];
                if (item.ModelCoreType == 1)
                {
                    viewModel[i] = Mapper.Map <SxVMMaterial, VMArticle>(item);
                }
            }
            return(PartialView("_Popular", viewModel));
        }
 public VMLastMaterialsBlock()
 {
     Materials     = new VMMaterial[0];
     Games         = new VMGame[0];
     GameMaterials = new VMMaterial[0];
 }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
 public VMMaterialCategory()
 {
     Materials = new VMMaterial[0];
 }