/// <summary> /// 获取默认职位ID /// </summary> /// <returns></returns> public static int GetDefaultPost() { ViewPost vbPost = new ViewPost(); vbPost.BaseCondition = "a.Name = '员工'"; return(vbPost.Count > 0 ? vbPost.GetItem(0).ID : -1); }
public static ViewPost GetRandomPostAd() { if (HttpContext.Current.Cache["post_ads"] == null) { List <PostAd> ads = Provider.Database.ReadList <PostAd>("select * from PostAd where AdStatus=1"); HttpContext.Current.Cache.Add("post_ads", ads, null, DateTime.Now.AddSeconds(10), Cache.NoSlidingExpiration, CacheItemPriority.High, (String name, Object val, CacheItemRemovedReason r) => { foreach (var ad in (List <PostAd>)val) { ad.Save(); } } ); } List <PostAd> cachedAds = (List <PostAd>)HttpContext.Current.Cache["post_ads"]; if (cachedAds.Count > 0) { PostAd p = cachedAds[new Random().Next(cachedAds.Count)]; p.ViewCount++; ViewPost vp = new ViewPost() { SharerNick = "", UserAvatar = Provider.GetThumbPath(p.InsertUser.Avatar, 48, 48, false), UserFullName = p.InsertUser.FullName, UserNick = p.InsertUser.Nick }; Provider.Database.Read <Post>(p.PostId).CopyPropertiesWithSameName(vp); return(vp); } else { return(null); } }
/// <summary> /// 获取所在某个部门的职位 /// </summary> /// <param name="iDeptID">部门ID</param> /// <returns></returns> public ViewBase Posts(int iDeptID) { ViewPost vbPost = new ViewPost(); vbPost.BaseCondition = " b.FK_UserID=" + base.ID.ToString() + " AND b.FK_DeptID =" + iDeptID.ToString(); return(vbPost); }
public async Task <IActionResult> Delete(int?id, string blogname) { if (id == null) { return(NotFound()); } var mpost = await postManager.Details(id); ViewPost post = new ViewPost(); post.ImportFromModel(mpost); //MarkDownManager markDownManager = new MarkDownManager(); //post.HTMLcontent = markDownManager.ConvertToHtml(mpost.content); //BBCodeManager bBCodeManager = new BBCodeManager(); //post.HTMLcontent = bBCodeManager.ConvertToHtml(mpost.content); MarkUpManager markUpManager = new MarkUpManager(); post.HTMLcontent = markUpManager.ConvertToHtml(mpost.content); if (post == null) { return(NotFound()); } ViewBag.BlogName = blogname; return(View(post)); }
/// <summary> /// 绑定职位 /// </summary> /// <param name="selectpPostID"></param> /// <returns></returns> public string BindPost2(int selectpPostID) { ViewBase vbPost = new ViewPost(); vbPost.BaseCondition = "a.ID<>0 "; vbPost.Sort = "a.SortNum DESC"; string html = string.Empty; html = "<option value='-1'>|-选择职位</option>"; int i = 0; foreach (Position dp in vbPost.Ens) { if (dp.ID == selectpPostID) { html += "<option selected valueMax='" + dp.MaxSortNum.ToString() + "' valueMin='" + dp.MinSortNum.ToString() + "' valueMinDefault='" + dp.SortNum.ToString() + "' value='" + dp.ID.ToString() + "'>" + "├" + dp.Name + "</option>"; } else { html += "<option valueMax='" + dp.MaxSortNum.ToString() + "' valueMin='" + dp.MinSortNum.ToString() + "' valueMinDefault='" + dp.SortNum.ToString() + "' value='" + dp.ID.ToString() + "'>" + "├" + dp.Name + "</option>"; } i += 50; } return(html); }
public IList <ViewPost> GetViewPosts(int pageindex, int pagesize, int boardid, out int pagecount) { string sql = "usp_getpostinfobypage"; SqlParameter[] spms = SqlHelper.GetSqpParameters(new string[] { "@boardid", "@pagesize", "@pageindex", "@pagecount" }, new object[] { boardid, pagesize, pageindex, DBNull.Value }, new SqlDbType[] { SqlDbType.Int, SqlDbType.Int, SqlDbType.Int, SqlDbType.Int }); spms[3].Direction = ParameterDirection.Output; DataSet dataSet = new DataSet(); SqlHelper.GetDataTable(sql, CommandType.StoredProcedure, dataSet, spms); pagecount = Convert.ToInt32(spms[3].Value); List <ViewPost> list = new List <ViewPost>(); foreach (DataRow dataRow in dataSet.Tables[0].Rows) { ViewPost post = new ViewPost(); post.Post.PostId = Convert.ToInt32(dataRow[0]); post.Post.Title = dataRow[1].ToString(); post.Post.Content = dataRow[2].ToString(); post.Post.UserId = Convert.ToInt32(dataRow[3]); post.Post.Like = Convert.ToInt32(dataRow[4]); post.Post.UnLike = Convert.ToInt32(dataRow[5]); post.Post.DateLine = Convert.ToDateTime(dataRow[6]); post.User.Head = dataRow[7].ToString(); list.Add(post); } return(list); }
public IList <ViewPost> GetViewPostsTop() { string sql = "usp_getpoststop"; DataSet dataSet = new DataSet(); SqlHelper.GetDataTable(sql, CommandType.StoredProcedure, dataSet); List <ViewPost> list = new List <ViewPost>(); foreach (DataRow dataRow in dataSet.Tables[0].Rows) { ViewPost post = new ViewPost(); post.Post.PostId = Convert.ToInt32(dataRow[0]); post.Post.Title = dataRow[1].ToString(); post.Post.Content = dataRow[2].ToString(); post.Post.UserId = Convert.ToInt32(dataRow[3]); post.Post.Like = Convert.ToInt32(dataRow[4]); post.Post.UnLike = Convert.ToInt32(dataRow[5]); post.Post.DateLine = Convert.ToDateTime(dataRow[6]); post.User.Head = dataRow[7].ToString(); post.User.UserId = Convert.ToInt32(dataRow[8]); post.User.UserName = dataRow[9].ToString(); list.Add(post); } return(list); }
/// <summary> /// 通过职位名返回职位对象 /// </summary> /// <param name="strPostName">职位名</param> /// <returns></returns> public static Position GetPosition(string strPostName) { ViewPost vwPost = new ViewPost(true); vwPost.BaseCondition = "a.Name='" + strPostName + "'"; return(vwPost.Count > 0 ? vwPost.GetItem(0) as Position : null); }
/// <summary> /// 通过职位id返回职位对象 /// </summary> /// <param name="iPostID">职位id</param> /// <returns></returns> public static Position GetPosition(int iPostID) { ViewPost vwPost = new ViewPost(true); vwPost.BaseCondition = "a.ID='" + iPostID + "'"; return(vwPost.Count > 0 ? vwPost.GetItem(0) as Position : null); }
public AdminPostViewModel(ViewPost post) { Id = post.Id; Author = post.Author; Title = post.Title; ShortContent = post.ShortContent; Active = post.Active; }
/// <summary> /// 根据职位名称获得大于该职位的职位 /// </summary> /// <param name="sPostName">职位名称</param> /// <returns></returns> public static ViewBase GetPositions(string sPostName) { Position post = Position.GetPosition(sPostName); ViewPost vwPost = new ViewPost(true); vwPost.BaseCondition = post == null ? "1<>1" : "SortNum <=" + post.SortNum.ToString(); return(vwPost); }
public async Task <IActionResult> Edit(int?id, string blogname) { //return View(); ViewBag.CreateAction = 0; //string pathbase; string pathbase = AppSettingsManager.GetPathBase(); if (CommonTools.isEmpty(pathbase) == false) { ViewBag.pathbase = pathbase; } if (id == null) { return(NotFound()); } var post = await this.postManager.Details(id); if (post == null) { return(NotFound()); } ViewBag.BlogId = post.BlogId; var vpost = new ViewPost(); vpost.ImportFromModel(post); //MarkDownManager markDownManager = new MarkDownManager(); //vpost.content = markDownManager.ConvertToHtml(post.content); //BBCodeManager bBCodeManager = new BBCodeManager(); //vpost.HTMLcontent = bBCodeManager.ConvertToHtml(post.content); MarkUpManager markUpManager = new MarkUpManager(); vpost.HTMLcontent = markUpManager.ConvertToHtml(post.content); var cmsengine = AppSettingsManager.GetAppWideCMSEngine(); if (cmsengine == enumMarkupEngine.QUIL.ToString()) { vpost.content = vpost.content.Replace("{\"ops\":", ""); vpost.content = vpost.content.Remove(vpost.content.Length - 1, 1); } vpost.CategoriesToString = await CategoryManager.GetCategoryNamesToString(vpost.Blog.Name, (int)id); return(View(vpost)); }
public ActionResult Post(int?page) { //是否需要回答问题后才能查看内容 string PostQuestion = ConfigurationManager.AppSettings["PostQuestion"]; ViewBag.PostQuestion = PostQuestion; //若是管理员登录,则默认不需要回答问题 if (Session["username"] != null) { ViewBag.PostQuestion = "false"; } //若需要回答问题 if (PostQuestion == "true") { string jsonFile = Server.MapPath("~/Files/") + "questions.json"; Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); StreamReader file = System.IO.File.OpenText(jsonFile); JsonTextReader reader = new JsonTextReader(file); JObject obj = (JObject)JToken.ReadFrom(reader); file.Close(); //防止占用文件 var list = obj["questions"].ToString(); JArray ja = (JArray)JsonConvert.DeserializeObject(list); var selected = GetRandom(0, ja.Count, 3); List <ViewQuestion> vqlist = new List <ViewQuestion>(); foreach (var num in selected) { ViewQuestion vq = new ViewQuestion(); vq.Content = ja[num]["content"].ToString(); vq.Answer = ja[num]["answer"].ToString(); vqlist.Add(vq); } ViewBag.vqlist = vqlist; } System.Linq.IQueryable <PersonalWebsite.Models.Post> post; //进行查询 post = from p in db4.Post select p; //分页显示 post = post.OrderByDescending(p => p.PostID); const int pageItems = 10; int currentPage = (page ?? 1); IPagedList <Post> pagePost = post.ToPagedList(currentPage, pageItems); ViewPost vpost = new ViewPost(); vpost.PostList = pagePost; return(View(vpost)); }
/// <summary> /// 绑定职位 /// </summary> /// <param name="deptid"></param> /// <returns></returns> public string BindPosition2(string deptid) { ViewBase vbPost = new ViewPost(); vbPost.BaseCondition = "a.ID<>0 "; vbPost.Sort = "a.SortNum DESC"; string html = string.Empty; foreach (Position dp in vbPost.Ens) { html += "<option value='" + dp.ID.ToString() + "'>" + "├" + dp.Name + "</option>"; } return(html); }
/// <summary> /// Tex paylaşım /// </summary> public static ViewPost GetPost(int postId) { ViewPost post = Provider.Database.Read <ViewPost>(@" SELECT p.Id, u.Avatar as UserAvatar, u.Nick as UserNick, concat(u.Name,' ',u.Surname) as UserFullName, p.Metin, p.Picture, p.VideoId, p.VideoType, p.InsertDate, p.ShareCount, p.LikeCount, p.OriginalPostId, p.ReplyToPostId, IFNULL(n.Id>0, 0) as UserLikedThis FROM Post p inner join User u ON p.InsertUserId = u.Id left join Notification n ON n.PostId=p.Id AND n.InsertUserId={1} AND n.NotificationType=1 WHERE p.Id = {0}", postId, Provider.User.Id); if (Provider.User.Id != post.Originator.Id && post.Originator.Settings.NeedsConfirmation && !post.Originator.HasContact(Provider.User.Id)) { return new ViewPost() { Metin = "Unauthorized access" } } ; if (post.OriginalPostId > 0) { var orginalPost = Provider.Database.Read <Post>(post.OriginalPostId); post.SharerNick = post.UserNick; post.UserAvatar = orginalPost.InsertUser.Avatar; post.UserNick = orginalPost.InsertUser.Nick; post.UserFullName = orginalPost.InsertUser.FullName; } post.UserAvatar = Provider.GetThumbPath(post.UserAvatar, 48, 48, false); return(post); }
public PostDetailsViewModel(ViewPost post) { Id = post.Id; // Demonstrating different display options inside the view model - separate from business logic if (string.IsNullOrEmpty(post.Author)) { Author = "Anonymous"; } else { Author = $"Written by {post.Author}"; } Title = post.Title; Content = post.Content; }
// GET: Posts public async Task <IActionResult> Index(string id) { string name = id; if (name == null) { return(NotFound()); } var p = await postManager.ListByBlogNameByPublished(name); List <ViewPost> posts = new List <ViewPost>(); foreach (var tp in p) { ViewPost ap = new ViewPost(); ap.ImportFromModel(tp); posts.Add(ap); } return(View(posts)); }
public static void Main(string[] args) { int menuSelection = 0; while (menuSelection != 6) { if (menuSelection == 1) { IViewPost readObject = new ViewPost(); List <Post> allPosts = readObject.ViewPost(); foreach (Post post in allPosts) { Console.WriteLine(post.ToString()); } } else if (menuSelection == 2) { ISavePost savePost = new SavePost(); savePost.SavePost(); } else if (menuSelection == 3) { IDeletePost deletePost = new DeletePost(); deletePost.DeletePost(); } else if (menuSelection == 4) { IEditPost editPost = new EditPost(); editPost.EditPost(); } else if (menuSelection == 5) { IReseedPost reseedPost = new ReseedPost(); reseedPost.ReseedPost(); } menuSelection = displayMenu(); } }
public async Task <IActionResult> ByTag(string id, string tagname) { string name = id; if (name == null && tagname != null) { return(NotFound()); } // var p = await postManager.ListByBlogNameByPublished(name); var p = await postManager.ListPostByTag(tagname, name); p.OrderByDescending(x => x.Published); List <ViewPost> posts = new List <ViewPost>(); foreach (var tp in p) { ViewPost ap = new ViewPost(); ap.ImportFromModel(tp); posts.Add(ap); } return(View(posts)); }
public async Task <IActionResult> Create(ViewPost post) { // No categories? if (!await context.Categories.AnyAsync()) { return(RedirectToAction(actionName: "Create", controllerName: "Category")); } // Valid post? if (ModelState.IsValid) { await context.Posts.AddAsync(post.CurrentPost); //context.Attach(post.CurrentPost.Category); await context.SaveChangesAsync(); return(RedirectToAction("Post", post.CurrentPost.ID)); } List <Category> categories = await context.Categories.ToListAsync(); return(View(new ViewPost(post.CurrentPost, categories: categories))); }
// GET: Posts/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var mpost = await postManager.Details(id); ViewPost post = new ViewPost(); post.ImportFromModel(mpost); //MarkDownManager markDownManager = new MarkDownManager(); //post.HTMLcontent = markDownManager.ConvertToHtml(mpost.content); //BBCodeManager bBCodeManager = new BBCodeManager(); //post.HTMLcontent = bBCodeManager.ConvertToHtml(mpost.content); MarkUpManager markUpManager = new MarkUpManager(); post.HTMLcontent = markUpManager.ConvertToHtml(mpost.content); post.Categories = await CategoryManager.GetCategoryByPostId((int)id); post.CategoriesToString = await CategoryManager.GetCategoryNamesToString(post.Blog.Name, (int)id); //QuilDeltaManager quilDeltaManager = new QuilDeltaManager(); //post.HTMLcontent = quilDeltaManager.ToHrml(mpost.content); if (post == null) { return(NotFound()); } return(View(post)); }
public async Task <IActionResult> Create(string blogname, [Bind("Id,Title,Published,content,Author,RowVersion,BlogId,engine,CategoriesToString")] ViewPost post) { //if (ModelState.IsValid) { post.Author = await PostManager.db.Users.FirstAsync(x => x.UserName == User.Identity.Name); var mpost = post.ToModel(User.Identity.Name); MarkUpManager markDownManager = new MarkUpManager(); mpost.content = markDownManager.ConvertFromHtmlToMarkUp(post.content); var blog = await blmngr.GetBlogByIdAsync(mpost.BlogId); await postManager.Create(mpost, this.User.Identity.Name); if (post.CategoriesToString != null) { var catgories = post.CategoriesToString.Split(",").ToList(); if (catgories != null) { await CategoryManager.AttachCategoryRangetoPost(catgories, blog.Name, mpost.Id); } } if (post.TagsToString != null) { var tags = post.TagsToString.Split(",").ToList(); if (tags != null) { await TagManager.AttachTagRangetoPost(tags, blog.Name, mpost.Id); } } //blmngr.GetBlogAsync() return(RedirectToAction(nameof(Index), "Posts", new { id = blog.Name })); } // return View(post); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Published,content,Author,RowVersion,BlogId,engine")] ViewPost post, string blogname) { try { if (id != post.Id) { return(NotFound()); } // if (ModelState.IsValid) // { //_context.Update(post); //await _context.SaveChangesAsync(); var mpost = post.ToModel(User.Identity.Name); MarkUpManager markDownManager = new MarkUpManager(); mpost.content = markDownManager.ConvertFromHtmlToMarkUp(post.content); mpost = await postManager.Edit(id, mpost); var blog = await blmngr.GetBlogByIdAsync(mpost.BlogId); if (mpost != null) { post.ImportFromModel(mpost); } if (post.CategoriesToString != null) { var catgories = post.CategoriesToString.Split(",").ToList(); if (catgories != null) { CategoryManager.DettachCategoryRangetoPost(catgories, blog.Name, mpost.Id); CategoryManager.AttachCategoryRangetoPost(catgories, blog.Name, mpost.Id); } } if (post.TagsToString != null) { var tags = post.TagsToString.Split(",").ToList(); if (tags != null) { TagManager.DettachTagRangetoPost(tags, blog.Name, mpost.Id); TagManager.AttachTagRangetoPost(tags, blog.Name, mpost.Id); } } // } } catch (DbUpdateConcurrencyException) { if (this.postManager.Exists(post.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index), "Posts", new { id = post.Blog.Name })); //return View(post); }
private void post() { if (Provider.User.IsAnonim()) { return; } int lat = 0; int.TryParse(context.Request["lat"], out lat); int lng = 0; int.TryParse(context.Request["lng"], out lng); string metin = context.Request["metin"]; if (string.IsNullOrWhiteSpace(metin) && (Provider.Request.Files["Picture"] == null || Provider.Request.Files["Picture"].ContentLength == 0)) { throw new Exception("Post empty"); } int replyToPostId = 0; int.TryParse(context.Request["replyToPostId"], out replyToPostId); Post replyToPost = null; if (replyToPostId > 0) { replyToPost = Provider.Database.Read <Post>(replyToPostId); } context.Response.ContentType = "text/html"; try { Post p = new Post { LangId = Provider.CurrentLanguage.Id, Lat = lat, Lng = lng, Metin = metin == null ? "" : metin, ReplyToPostId = replyToPostId > 0 ? (replyToPost.OriginalPost == null ? replyToPostId : replyToPost.OriginalPost.Id) : 0 }; p.Save(); ViewPost vp = new ViewPost() { SharerNick = "", UserAvatar = Provider.GetThumbPath(p.InsertUser.Avatar, 48, 48, false), UserFullName = p.InsertUser.FullName, UserNick = p.InsertUser.Nick }; p.CopyPropertiesWithSameName(vp); context.Response.Write("<html><head></head><body><script>window.parent.paylas(" + vp.ToJSON() + ");</script></body></html>"); } catch (Exception ex) { context.Response.Write("<html><head></head><body><script>window.parent.niceAlert(" + ex.Message.ToJS() + ");</script></body></html>"); } }
/// <summary> /// 获得所有职位 /// </summary> /// <returns></returns> public static ViewBase GetAllPosition() { ViewPost vPost = new ViewPost(true); return(vPost); }