Exemple #1
0
 public async Task <IActionResult> Post(string slug)
 {
     try
     {
         PostDetail post = null;
         if (Guid.TryParse(slug, out Guid id))
         {
             post = _postsRepository.FindById(id);
         }
         else
         {
             post = _postsRepository.GetPostBySlug(slug);
         }
         if (post != null)
         {
             post.Content = _postsRepository.FixContent(post.Content);
             try
             {
                 ///转化Markdown
                 post.Content = await _nodeService.InvokeAsync <string>("./Node/Parser", post.Content);
             }
             catch (Exception ex)
             {
             }
         }
         return(View(post));
     }
     catch
     {
         _logger.LogWarning($"Couldn't find the ${slug} post");
     }
     return(Redirect("/"));
 }
        public ActionResult Create(PostDetail postDetail)
        {
            if (ModelState.IsValid)
            {
                var _CurrentUserId = User.Identity.GetUserId();
                if (_CurrentUserId == null)
                {
                    //becouse Sometime id = 0 ?????!!!! maybe session die???????
                    postDetail.CategoryDetails = db.Categories;
                    return(View(postDetail));
                }
                if (postDetail.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(postDetail.ImageUpload.FileName);
                    string extension = Path.GetExtension(postDetail.ImageUpload.FileName);
                    fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    postDetail.FeaturedImage = "~/Content/Images/" + fileName;
                    postDetail.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/Content/Images/"), fileName));
                }
                db.PostDetails.Add(postDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }



            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", postDetail.CategoryId);
            return(View(postDetail));
        }
Exemple #3
0
        public ActionResult RegisterReadPost(long postid, int isread, int isunderstand)
        {
            PostDetail pdetail = new PostDetail();

            var post = db.Post.Find(postid);

            if (post != null)
            {
                pdetail.postid         = post.id;
                pdetail.departmentid   = post.departmentid;
                pdetail.postcategoryid = post.postcategoryid;
                pdetail.employeeid     = User.Identity.GetUserId();
                // pdetail.isread = isread;
                // pdetail.isunderstand = isunderstand;
                pdetail.createdonutc   = System.DateTime.UtcNow;
                pdetail.updatedonutc   = System.DateTime.UtcNow;
                pdetail.ipused         = Request.UserHostAddress;
                pdetail.userid         = User.Identity.GetUserId();
                pdetail.lastvisitdate  = System.DateTime.UtcNow;
                pdetail.firstvisitdate = System.DateTime.UtcNow;
                db.PostDetail.Add(pdetail);
                db.SaveChanges();
            }

            return(Json(new { success = true }));
        }
        /// <summary>
        /// Update post
        /// </summary>
        /// <param name="detail">Post to update</param>
        /// <param name="action">Action</param>
        /// <returns>True on success</returns>
        public bool Update(PostDetail detail, string action)
        {
            if (!Security.IsAuthorizedTo(BlogEngine.Core.Rights.EditOwnPosts))
            {
                throw new System.UnauthorizedAccessException();
            }

            var post = (from p in Post.Posts.ToList() where p.Id == detail.Id select p).FirstOrDefault();

            if (post != null)
            {
                if (action == "publish")
                {
                    post.IsPublished  = true;
                    post.DateModified = DateTime.Now;
                    post.Save();
                }
                else if (action == "unpublish")
                {
                    post.IsPublished  = false;
                    post.DateModified = DateTime.Now;
                    post.Save();
                }
                else
                {
                    Save(post, detail);
                }
                return(true);
            }
            return(false);
        }
        public static IEnumerable <PostDetail> ToPostDetailList(this IEnumerable <Post> redditDotNetPostList)
        {
            return(redditDotNetPostList.Select(post =>
            {
                var newPostDetail = new PostDetail
                {
                    ID = post.Id,
                    FromSubreddit = post.Subreddit,
                    Title = post.Title,
                    DateCreated = post.Created,
                    UserCreated = post.Author,
                    UpVotes = post.UpVotes,
                    DownVotes = post.DownVotes,
                    URL = post.Listing.URL,
                    FullName = post.Fullname,
                    CommentCount = post.Listing.NumComments,
                    PermaLink = $"https://www.reddit.com{post.Listing.Permalink}"
                };

                try
                {
                    // Image URL is a JObject so might throw an error if the requested property is null (e.g. text-only posts)
                    newPostDetail.ImageURL = post.Listing.Preview["images"][0]["source"].Value <string>("url");
                }
                catch (NullReferenceException)
                {
                    // Perhaps the post is text only. set the URL to null.
                    newPostDetail.ImageURL = null;
                }

                return newPostDetail;
            }));
        }
Exemple #6
0
        /// <summary>
        /// 偏好菜单点击时
        /// </summary>
        private void Prefer_MenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem selectedItem = e.Source as MenuItem;

            Prefer prefer = (Prefer)Enum.Parse(typeof(Prefer), selectedItem.Header.ToString());

            PostDetail temp = this.Detail;

            temp.prefer = prefer;
            this.Detail = temp;

            List <PostDetail> list = new List <PostDetail>();

            foreach (var pd in ((this.Parent as Grid).Parent as PostInfoWindow).postInfoControl.tabControl.ItemsSource.Cast <PostDetail>())
            {
                temp        = pd;
                temp.prefer = prefer;
                list.Add(temp);
            }

            int selectedIndex = ((this.Parent as Grid).Parent as PostInfoWindow).postInfoControl.tabControl.SelectedIndex;

            ((this.Parent as Grid).Parent as PostInfoWindow).postInfoControl.tabControl.ItemsSource   = list;
            ((this.Parent as Grid).Parent as PostInfoWindow).postInfoControl.tabControl.SelectedIndex = selectedIndex;

            BLL.Preference.UpdatePrefer(Mode.Posts, this.Detail.file_md5, prefer);
        }
Exemple #7
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            PostDetail detail = (PostDetail)value;

            switch (detail.site)
            {
            case Site.Yande:
                return(string.Format("https://yande.re/post/show/{0}", detail.id));

            case Site.Konachan:
                return(string.Format("http://konachan.com/post/show/{0}", detail.id));

            case Site.Danbooru:
                return(string.Format("http://danbooru.donmai.us/posts/{0}", detail.id));

            case Site.Gelbooru:
                return(string.Format("http://gelbooru.com/index.php?page=post&s=view&id={0}", detail.id));

            case Site.Sankaku:
                return(string.Format("https://chan.sankakucomplex.com/post/show/{0}", detail.id));

            default:
                return(null);
            }
        }
        // GET: AdminPanelPost/Create
        public ActionResult Create()
        {
            PostDetail model = new PostDetail();

            model.CategoryDetails = db.Categories;
            return(View(model));
        }
Exemple #9
0
        /// <summary>
        /// 设定缓存
        /// </summary>
        /// <param name="detail"></param>
        public void SetCache(PostDetail detail)
        {
            string imgPath = GetImagePath(detail);

            //图片不存在
            if (System.IO.File.Exists(imgPath) == false)
            {
                return;
            }

            Task <BitmapImage> task = new Task <BitmapImage>(p =>
            {
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                bitmapImage.UriSource   = new Uri((string)p);
                bitmapImage.EndInit();
                bitmapImage.Freeze();
                return(bitmapImage);
            }, imgPath);

            task.ContinueWith(t =>
            {
                this.Cache = new KeyValuePair <string, BitmapImage>(detail.file_md5, task.Result);
            }
                              );

            task.Start();
        }
Exemple #10
0
 public async Task <IActionResult> Post(string slug)
 {
     try
     {
         PostDetail post = null;
         if (Guid.TryParse(slug, out Guid id))
         {
             post = await _postService.GetById(id.ToString());
         }
         else
         {
             post = await _postService.GetBySlug(slug);
         }
         if (post != null)
         {
             if (post.ContentType == (int)DataConst.ContentType.Markdown)
             {
                 post.Content = Markdig.Markdown.ToHtml(post.Content);
             }
         }
         return(View(post));
     }
     catch
     {
         _logger.LogWarning($"Couldn't find the ${slug} post");
     }
     return(Redirect("/"));
 }
        static void Save(Post post, PostDetail detail)
        {
            post.Title              = detail.Title;
            post.ChapterNumber      = detail.ChapterNumber;
            post.Author             = string.IsNullOrEmpty(detail.Author) ? Security.CurrentUser.Identity.Name : detail.Author;
            post.Description        = GetDescription(detail.Description, detail.Content);
            post.Content            = detail.Content;
            post.Summary            = detail.Summary;
            post.IsPublished        = detail.IsPublished;
            post.HasCommentsEnabled = detail.HasCommentsEnabled;
            post.IsDeleted          = detail.IsDeleted;
            post.DateCreated        = DateTime.ParseExact(detail.DateCreated, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
            post.Verses             = detail.Verses = detail.Verses.TrimEnd().TrimEnd(',');

            // if changing slug, should be unique
            if (post.Slug != detail.Slug)
            {
                post.Slug = GetUniqueSlug(detail.Slug);
            }

            UpdatePostCategories(post, detail.Categories);
            UpdatePostTags(post, FilterTags(detail.Tags));
            UpatePostVerses(post, detail.Verses);

            post.Save();
        }
        public async Task <IHttpActionResult> PutPostDetail(int id, PostDetail postDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != postDetail.id)
            {
                return(BadRequest());
            }

            db.Entry(postDetail).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #13
0
 public static void DeletPost(PostDetail post)
 {
     using (var connect = GetDatabse())
     {
         connect.Delete(post);
     }
 }
Exemple #14
0
 public static void AddPost(PostDetail post)
 {
     using (var connect = GetDatabse())
     {
         connect.InsertOrReplace(post);
     }
 }
Exemple #15
0
        /// <summary>
        /// Creates a new post for a user and project
        /// </summary>
        /// <param name="title"></param>
        /// <param name="projectid"></param>
        /// <param name="tags"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        /// has been reduced and used atomic methods and removed locks
        public Task <bool> CreatePost(string title, int projectid, string[] tags, string description, string code)
        {
            var userid = Identity.User.UserID;

            return(Task.Run(async() =>
            {
                var postbin = await _userService.GetPosts();

                var newPost = new PostDetail()
                {
                    UserID = userid,
                    Title = title,
                    ProjectID = projectid,
                    Description = description,
                    Code = code,
                    //Tags = tags.ToList()
                };

                var postDetailBinID = await _userService.AddNewPostDetail(newPost, $"PostDetail_{projectid}_{userid}");

                postbin.Posts.Add(new Post()
                {
                    PostBInID = postDetailBinID,
                    PostID = postbin.TopPostID + 1,
                    ProjectID = projectid,
                    UserID = userid,
                    Title = title
                });
                postbin.TopPostID += 1;

                var res = await _userService.UpdatePosts(postbin);

                return true;
            }));
        }
 public PostDetail Add(PostDetail post)
 {
     return(new PostDetail()
     {
         Id = Guid.NewGuid()
     });
 }
Exemple #17
0
 public static bool FindPost(PostDetail post)
 {
     using (var connect = GetDatabse())
     {
         var isbookmarked = connect.Find <PostDetail>(item => item.Id == post.Id);
         return(isbookmarked != null);
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            PostDetail postDetail = db.PostDetails.Find(id);

            db.PostDetails.Remove(postDetail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #19
0
        // GET: Post
        //[Authorize(Roles = "canManagePost")]
        public ActionResult NewPost()
        {
            PostDetail model = new PostDetail();

            model.PostId          = 0;//Becouse HttpPost NewPost, Need Id to know Edit or AddNew .
            model.CategoryDetails = _context.Categories;

            return(View(model));
        }
Exemple #20
0
        //[Authorize(Roles ="canManagePost")]
        public ActionResult NewPost(PostDetail data)
        {
            if (ModelState.IsValid)
            {
                var _CurrentUserId = User.Identity.GetUserId();
                if (_CurrentUserId == null)
                {
                    //becouse Sometime id = 0 ?????!!!! maybe session die???????
                    data.CategoryDetails = _context.Categories;
                    return(View(data));
                }
                if (data.ImageUpload != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(data.ImageUpload.FileName);
                    string extension = Path.GetExtension(data.ImageUpload.FileName);
                    fileName           = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    data.FeaturedImage = "~/Content/Images/" + fileName;
                    data.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/Content/Images/"), fileName));
                }



                if (data.PostId == 0)
                {
                    var _post = new PostDetail(); //To get Post ID From AddPost to use it for Details
                    _post.Title         = data.Title;
                    _post.Post_Content  = data.Post_Content;
                    _post.FeaturedImage = data.FeaturedImage;
                    _post.Create_time   = DateTime.Now;
                    _post.Tages         = data.Tages;
                    _post.CategoryId    = data.CategoryId;

                    _context.PostDetails.Add(_post);
                    _context.SaveChanges();
                    data.PostId = _post.PostId;
                }
                else
                {
                    var dbEntry = _context.PostDetails.Find(data.PostId);
                    if (dbEntry != null)
                    {
                        dbEntry.PostId       = data.PostId;
                        dbEntry.Title        = data.Title;
                        dbEntry.Post_Content = data.Post_Content;

                        dbEntry.Tages      = data.Tages;
                        dbEntry.CategoryId = data.CategoryId;

                        _context.SaveChanges();
                    }
                }
                return(RedirectToAction("Index", "Home"));
            }
            data.CategoryDetails = _context.Categories;
            return(View(data));
        }
Exemple #21
0
        public PostDetailPage_Model(PostDetail model)
        {
            if (IsInDesignMode)
            {
                VM.Title = "文章标题";
            }
            VM = model;

            Init();
        }
        public PostDetailViewModel()
        {
            currentPost         = new PostDetail();
            comment             = new CommentDetail();
            SaveCommand         = new Command(SaveComment);
            LikePostCommand     = new Command(OnLikePost);
            DisplayImageCommand = new Command(DisplayImage);

            comments = new ObservableCollection <CommentDetail>();
        }
Exemple #23
0
 //postdetail
 public static PostDetailModel PostDetailMap(PostDetail postdetail, IUrlHelper url)
 {
     return(new PostDetailModel
     {
         Url = url.Link(Config.PostDetailRoute, new { id = postdetail.id }),
         id = postdetail.id,
         title = postdetail.title,
         body = postdetail.body
     });
 }
Exemple #24
0
        public IActionResult PostsUpdate([FromBody] PostDetail item)
        {
            var result = _postsRepository.Update(item);

            if (result == null)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
Exemple #25
0
        /// <summary>
        /// Get detailed post
        /// </summary>
        /// <param name="post">Post</param>
        /// <returns>Json post detailed</returns>
        public PostDetail GetPostDetail(Post post)
        {
            var categories = _ctx.PostsInCategories.Where(m => m.PostsId == post.Id).Select(m => m.Categories).ToList();
            //if (post.ContentType == (int)DataConst.ContentType.Markdown)
            //{
            //    post.Content = Markdig.Markdown.ToHtml(post.Content);
            //}
            var author = new Author();

            author.Id          = post.Author?.Id;
            author.Signature   = post.Author?.Signature;
            author.DisplayName = post.Author?.DisplayName;
            author.Name        = post.Author?.UserName;
            author.Avatar      = post.Author?.Avatar;
            author.SiteUrl     = post.Author?.SiteUrl;
            var postDetail = new PostDetail
            {
                ContentType         = post.ContentType,
                Id                  = post.Id,
                Author              = author,
                Title               = post.Title,
                Slug                = post.Slug,
                Description         = post.Description,
                RelativeLink        = "/post/" + post.Id,
                Content             = post.Content,
                DateCreated         = post.DatePublished.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture),
                Categories          = GetCategories(categories),
                Tags                = GetTags(post.Tags.Split(',')),
                Comments            = GetComments(post),
                HasCommentsEnabled  = post.HasCommentsEnabled,
                HasRecommendEnabled = post.HasRecommendEnabled,
                IsPublished         = post.IsPublished,
                IsDeleted           = false,
                CanUserEdit         = true,
                CanUserDelete       = true
            };

            if (!string.IsNullOrEmpty(post.CoverImage))
            {
                var covers = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(post.CoverImage);
                if (covers.Count > 0)
                {
                    postDetail.Cover1 = covers[0];
                }
                if (covers.Count > 1)
                {
                    postDetail.Cover2 = covers[1];
                }
                if (covers.Count > 2)
                {
                    postDetail.Cover2 = covers[2];
                }
            }
            return(postDetail);
        }
        public async Task <IHttpActionResult> GetPostDetail(int id)
        {
            PostDetail postDetail = await db.PostDetails.FindAsync(id);

            if (postDetail == null)
            {
                return(NotFound());
            }

            return(Ok(postDetail));
        }
 public ActionResult Edit([Bind(Include = "PostId,Title,Post_Content,Create_time,Tages,FeaturedImage,CategoryId,UserId")] PostDetail postDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(postDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "CategoryName", postDetail.CategoryId);
     return(View(postDetail));
 }
Exemple #28
0
    public HttpResponseMessage Post([FromBody] PostDetail item)
    {
        var result = repository.Add(item);

        if (result == null)
        {
            return(Request.CreateResponse(HttpStatusCode.NotModified));
        }

        return(Request.CreateResponse(HttpStatusCode.Created, result));
    }
Exemple #29
0
        public PostDetail Add(PostDetail detail)
        {
            var post = new Post();

            UpdatePostDetail(detail, post);
            _ctx.Posts.Add(post);
            UpdatePostCategories(post, detail.Categories);
            SaveAll();
            detail.Id = post.Id;
            return(detail);
        }
        /// <summary>
        /// Add new post
        /// </summary>
        /// <param name="detail">Post</param>
        /// <returns>Saved post with new ID</returns>
        public PostDetail Add(PostDetail detail)
        {
            if (!Security.IsAuthorizedTo(Rights.CreateNewPosts))
            {
                throw new UnauthorizedAccessException();
            }

            var post = new Post();

            Save(post, detail);
            return(Json.GetPostDetail(post));
        }