Пример #1
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <bool> Update(CL_Content entity)
        {
            string             sql     = $"update {ReName($"{Prefix}Content")} set {ReName("Title")}=@Title,{ReName("Image")}=@Image,{ReName("Content")}=@Content,{ReName("Status")}=@Status,{ReName("Recycle")}=@Recycle,{ReName("Updated")}=@Updated,{ReName("Introduce")}=@Introduce where {ReName("ContentId")}=@ContentId";
            List <DbParameter> parlist = new List <DbParameter>();

            parlist.Add(CreateParam("@ContentId", entity.ContentId));
            parlist.Add(CreateParam("@Title", entity.Title));
            parlist.Add(CreateParam("@Image", entity.Image));
            parlist.Add(CreateParam("@Content", entity.Content));
            parlist.Add(CreateParam("@Status", entity.Status));
            parlist.Add(CreateParam("@Recycle", entity.Recycle));
            parlist.Add(CreateParam("@Updated", entity.Updated));
            parlist.Add(CreateParam("@Introduce", entity.Introduce));
            return(await ExecuteNonQueryMem(sql, parlist.ToArray()));
        }
Пример #2
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns></returns>
        public async System.Threading.Tasks.Task <bool> Insert(CL_Content entity)
        {
            string             sql     = $"insert into {ReName($"{Prefix}Content")}({ReName("ContentId")},{ReName("Title")},{ReName("Image")},{ReName("Content")},{ReName("Status")},{ReName("Recycle")},{ReName("Updated")},{ReName("CreateUid")},{ReName("CreateIP")},{ReName("CreateDate")},{ReName("Introduce")})values(@ContentId,@Title,@Image,@Content,@Status,@Recycle,@Updated,@CreateUid,@CreateIP,@CreateDate,@Introduce)";
            List <DbParameter> parlist = new List <DbParameter>();

            parlist.Add(CreateParam("@ContentId", entity.ContentId));
            parlist.Add(CreateParam("@Title", entity.Title));
            parlist.Add(CreateParam("@Image", entity.Image));
            parlist.Add(CreateParam("@Content", entity.Content));
            parlist.Add(CreateParam("@Status", entity.Status));
            parlist.Add(CreateParam("@Recycle", entity.Recycle));
            parlist.Add(CreateParam("@Updated", entity.Updated));
            parlist.Add(CreateParam("@CreateUid", entity.CreateUid));
            parlist.Add(CreateParam("@CreateIP", entity.CreateIP));
            parlist.Add(CreateParam("@CreateDate", entity.CreateDate));
            parlist.Add(CreateParam("@Introduce", entity.Introduce));
            if (await ExecuteNonQueryMem(sql, parlist.ToArray()))
            {
                return(true);
            }
            return(false);
        }
        public ActionResult Details(string URL, string prv)
        {
            Content content;
            bool    isPreview = false;

            if (Session["Preview"] != null && prv == "true")
            {
                content   = (Content)Session["Preview"];
                isPreview = true;
            }
            else
            {
                content = context.Content.Where(x => x.URL.ToLower() == URL.ToLower() && x.IsDeleted == false && x.isPublished == true).FirstOrDefault();

                if (string.IsNullOrEmpty(URL) || content == null)
                {
                    ActionResult actionResult = View(viewName: activeTheme + "404.cshtml");
                    return(actionResult);
                }
                ViewBag.ContentID = content.ID;
            }
            CL_Content data = new CL_Content();

            data.ContentID     = content.ID;
            data.URL           = content.URL;
            data.Title         = content.Title;
            data.FeaturedImage = content.FeaturedImage;
            data.CoverContent  = content.CoverContent;
            data.AddedBy       = content.AddedBy;
            data.PublishedOn   = content.AddedOn;

            if (content.Type.ToLower() == "page")
            {
                data.Description = Functions.ReplaceSliderAndAddons(this.ControllerContext, activeTheme, content.Description);
                data.Type        = "page";
            }
            else
            {
                data.Description            = content.Description;
                data.Type                   = "post";
                data.PostCommentEnable      = content.EnableComment;
                data.PostCommentEnabledTill = content.CommentEnabledTill;
                var comments = context.Comment.Where(x => x.ContentID == content.ID && x.IsModerated == true && x.IsAbused == false).OrderBy(x => x.AddedOn).ToList();
                data.CommentsCount = comments.Count();
                data.Category      = content.Categories.Select(c => new CL_Category
                {
                    Name        = c.Category.Name,
                    Description = c.Category.Description,
                    URL         = c.Category.Slug
                }).ToList();
                data.Labels = content.Labels.Select(c => new CL_Label
                {
                    Name        = c.Label.Name,
                    Description = c.Label.Description,
                    URL         = c.Label.Slug
                }).ToList();
                data.Comments = comments.Select(x =>
                                                new CL_Comments
                {
                    CommentID     = x.ID,
                    ContentID     = content.ID,
                    Website       = x.Website,
                    CommentAs     = x.CommentAs,
                    Description   = x.Description,
                    UserName      = x.UserName,
                    ProfilePicUrl = x.ProfilePicUrl,
                    AddedOn       = x.AddedOn
                }).ToList();
            }
            if (!isPreview)
            {
                int ContentView = content.ContentView;
                if (ContentView == 0)
                {
                    ContentView = 1;
                }
                else
                {
                    ContentView++;
                }
                content.ContentView          = ContentView;
                context.Entry(content).State = EntityState.Modified;
                context.SaveChanges();

                Functions.IncreaseContentView(content.ID, Request);
            }
            return(View(viewName: activeTheme + "content.cshtml", model: data));
        }