protected void lnkRegister_Click(object sender, EventArgs e) { model.BlogModel.Title = txtTitle.Text; model.BlogModel.Url = txtUrl.Text; model.BlogModel.EMail = txtEmail.Text; model.BlogModel.Name = txtName.Text; model.BlogModel.NickName = txtNickName.Text; model.BlogModel.Introduction = txtIntroduction.Text; model.BlogModel.Address = ddlAddress.SelectedItem.Text; model.BlogModel.Hobby = txtHobby.Text; model.BlogModel.Alarm = bool.Parse(rblAlram.SelectedValue); model.BlogModel.AutoClip = bool.Parse(rblAutoClip.SelectedValue); model.BlogModel.PostCount = int.Parse(rblPostCount.SelectedValue); model.BlogModel.RecentCommentListCount = int.Parse(rblRecentComment.SelectedValue); model.BlogModel.RecentArticleListCount = int.Parse(rblRecentArticleCount.SelectedValue); model.BlogModel.UseEmoticon = bool.Parse(rblUseEmoticon.SelectedValue); model.BlogModel.PeridoNewIcon = int.Parse(ddlNewIcon.SelectedValue); model.BlogModel.Gender = (BlogConst.Gender)Enum.Parse( typeof(BlogConst.Gender), ddlGender.SelectedValue); string path = Utility.GetAbsolutePath(UmcConfiguration.Core["BlogXmlPath"]); BlogManager.GetInstance().WriteBlogBaseInfo(path, model); Utility.JS_Alert(sender, MessageCode.MESSAGE_SAVED); }
private void BindData() { var blogPosts = BlogManager.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageId); if (blogPosts.Count > 0) { var months = new SortedDictionary <DateTime, int>(); DateTime first = blogPosts[blogPosts.Count - 1].CreatedOn; while (DateTime.SpecifyKind(first, DateTimeKind.Utc) <= DateTime.UtcNow.AddMonths(1)) { var list = blogPosts.GetPostsByDate(new DateTime(first.Year, first.Month, 1), new DateTime(first.Year, first.Month, 1).AddMonths(1).AddSeconds(-1)); if (list.Count > 0) { DateTime date = new DateTime(first.Year, first.Month, 1); months.Add(date, list.Count); } first = first.AddMonths(1); } string html = RenderMonths(months); lMonths.Text = html; } else { this.Visible = false; } }
private void GetAllUsers() { BlogManager manager = BlogManagerFactory.Create(); var users = manager.GetAllUsers(); SetUserList(users); }
protected void CreateBlogEntry(object sender, EventArgs e) { lblError.Text = string.Empty; try { BlogManager bmo = new BlogManager(); if (txtContent.Content != string.Empty && txtInsertTextbox.Text != string.Empty) { if (bmo.AddBlogEntry(txtInsertTextbox.Text, User.Identity.Name, txtContent.Content, getCat())) { PrintBlog(); lbleditorMessage.Text = "Added one row to database"; } } else { throw new Exception("You did not type anything into the textbox or the editor. Sorry at this moment we can not add your blog post."); } } catch (Exception ex) { handleError(ex.Message, ex); } }
public IActionResult DeleteBlog([FromRoute] int id) { if (ModelState.IsValid) { BlogManager blogManager = new BlogManager(this._unitOfWork); if (blogManager.DeleteBlog(id) != 0) { return(StatusCode(204)); } else { return(StatusCode(501)); } } //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} //var blog = await this._unitOfWork.GetRepository<Blog>().Single(m => m.BlogId == id); ////var blog = await _context.Blog.SingleOrDefaultAsync(m => m.BlogId == id); //if (blog == null) //{ // return NotFound(); //} return(Ok()); }
public XmlRpcStruct[] getUsersBlogs(string appKey, string username, string password) { Authenticate(username, password); var blogList = BlogManager.GetUserBlogs(username); //Create structure for blog list var blogs = new List <XmlRpcStruct>(); #if FEATURE_URL_BUILDERS var urlOptions = new ItemUrlBuilderOptions(); #else var urlOptions = UrlOptions.DefaultOptions; #endif urlOptions.AlwaysIncludeServerUrl = true; foreach (var blog in blogList) { var url = LinkManager.GetItemUrl(blog, urlOptions); var rpcstruct = new XmlRpcStruct { { "blogid", blog.ID.ToString() }, // Blog Id { "blogName", blog.Title.Raw }, // Blog Name { "url", url } }; blogs.Add(rpcstruct); } return(blogs.ToArray()); }
public List <BlogDto> GetAllBlogs() { BlogManager blogManager = new BlogManager(this._unitOfWork); List <BlogDto> blogDtolsit = new List <BlogDto>(); var bloglist = blogManager.GetBlogAll(); foreach (BlogDtoDll blog in bloglist) { BlogDto blogDto = new BlogDto { BlogId = blog.BlogId, Url = blog.Url }; List <PostDto> postDtolist = new List <PostDto>(); foreach (var post in blog.PostDtoDll) { PostDto postDto = new PostDto { BlogId = post.BlogId, Content = post.Content, Title = post.Title, PostId = post.PostId }; postDtolist.Add(postDto); } blogDto.PostDto = postDtolist; blogDtolsit.Add(blogDto); } return(blogDtolsit); }
protected void SaveButton_Click(object sender, EventArgs e) { if (Page.IsValid) { try { BlogComment blogComment = BlogManager.GetBlogCommentByID(this.BlogCommentID); if (blogComment != null) { string comment = txtComment.Text; blogComment = BlogManager.UpdateBlogComment(blogComment.BlogCommentID, blogComment.BlogPostID, blogComment.CustomerID, comment, blogComment.CreatedOn); Response.Redirect("BlogCommentDetails.aspx?BlogCommentID=" + blogComment.BlogCommentID.ToString()); } else { Response.Redirect("BlogComments.aspx"); } } catch (Exception exc) { ProcessException(exc); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //绑定最新博客 DataTable dt = new BlogManager().SelectLatest(); Replatest.DataSource = dt; Replatest.DataBind(); //绑定最热博客 dt = new BlogManager().SelectPopular(); Reppopular.DataSource = dt; Reppopular.DataBind(); //绑定最佳博主 dt = new UsersManager().SelectTopUser(); Reptopuser.DataSource = dt; Reptopuser.DataBind(); //绑定热门博主 dt = new UsersManager().SelectPopularUsers(); Reppopularuser.DataSource = dt; Reppopularuser.DataBind(); //绑定热文 dt = new BlogManager().SelectPopular(); Rephotblogs.DataSource = dt; Rephotblogs.DataBind(); } }
private void GetStaticLinks() { BlogManager manager = BlogManagerFactory.Create(); var siteLinkList = manager.GetSiteLinks(); SetStaticLinks(siteLinkList); }
public async Task BlogCreate_ShouldWorkProperly() { var blog = await BlogManager.CreateAsync("test-name", "test-slug"); blog.ShouldNotBeNull(); blog.Id.ShouldNotBe(Guid.Empty); }
public void ShowEmailWithinComments(bool enabled) { var blogTemplateId = ID.NewID; var settings = Mock.Of <IWeBlogSettings>(x => x.ContentRootPath == "/sitecore/content" && x.BlogTemplateIds == new[] { ID.NewID, blogTemplateId, ID.NewID } ); var manager = new BlogManager(settings); using (var db = new Db { new DbItem("blog", ID.NewID, blogTemplateId) { { "Show Email Within Comments", enabled ? "1" : string.Empty } } }) { var item = db.GetItem("/sitecore/content/blog"); var result = manager.ShowEmailWithinComments(item); if (enabled) { Assert.That(result, Is.True); } else { Assert.That(result, Is.False); } } }
/// <summary> /// Gets the categories as string. /// </summary> /// <param name="postid">The postid.</param> /// <param name="rpcstruct">The rpcstruct.</param> /// <returns></returns> protected virtual string GetCategoriesAsString(Item postItem, XmlRpcStruct rpcstruct) { var blog = BlogManager.GetCurrentBlog(postItem).SafeGet(x => x.InnerItem); var categoryList = CategoryManager.GetCategories(blog); if (categoryList.Length != 0) { string selectedCategories = string.Empty; try { string[] categories = (string[])rpcstruct["categories"]; foreach (string category in categories) { foreach (CategoryItem cat in categoryList) { if (category == cat.Title.Raw) { selectedCategories += cat.ID.ToString(); } } } string result = selectedCategories.Replace("}{", "}|{"); return(result); } catch { return(string.Empty); } } return(string.Empty); }
public async Task BlogCreate_ShouldThrowException_WithExistSlug() { await Should.ThrowAsync <BlogSlugAlreadyExistException>( async() => await BlogManager.CreateAsync("test-name", TestData.BlogSlug) ); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //绑定最新博客 DataTable dt = new BlogManager().SelectLatest(); //绑定热门博主 dt = new UsersManager().SelectPopularUsers(); Reppopularuser.DataSource = dt; Reppopularuser.DataBind(); //绑定热文 dt = new BlogManager().SelectPopular(); Rephotblogs.DataSource = dt; Rephotblogs.DataBind(); //绑定某类别下所有文章 string caId = Request.QueryString["caId"]; dt = new BlogManager().SelectByCategory(caId); if (dt.Rows.Count != 0) { //设置类别名称 category_name.Text = dt.Rows[0]["name"].ToString(); } Repcatelist.DataSource = dt; Repcatelist.DataBind(); } }
public void GetCurrentBlog(string startPath, string expectedPath) { var blogTemplateId = ID.NewID; var entryTemplateId = ID.NewID; var settings = Mock.Of <IWeBlogSettings>(x => x.BlogTemplateIds == new[] { blogTemplateId } && x.EntryTemplateIds == new[] { entryTemplateId } ); using (var db = new Db { new DbItem("blog", ID.NewID, blogTemplateId) { new DbItem("entries") { new DbItem("entry", ID.NewID, entryTemplateId) } } }) { var startItem = db.GetItem(startPath); var manager = new BlogManager(settings); var resultItem = manager.GetCurrentBlog(startItem); if (expectedPath == null) { Assert.That(resultItem, Is.Null); } else { Assert.That(resultItem.ID, Is.EqualTo(resultItem.ID)); } }; }
protected void Page_Load(object sender, EventArgs e) { byte[] blob = new byte[] { }; string ContentType = string.Empty; BlogEntities be = new BlogEntities(); try { if (Request.QueryString["id"] != null) { int bid = Convert.ToInt16(Request.QueryString["id"]); if (bid > 0) { blob = BlogManager.getVideoBlob(bid); Response.ContentType = BlogManager.getMimeType(bid); Response.OutputStream.Write(blob, 0, blob.Length); Response.End(); } } } catch (Exception ex) { Response.Write(ex.Message); } }
public ActionResult DeleteABlog(BlogVM blogVM) { BlogManager manager = BlogManagerFactory.Create(); manager.DeleteBlog(blogVM.Blog.BlogPostId); return(RedirectToAction("MyBlogs")); }
public virtual void FillRss <T>(System.Collections.IEnumerator eData) { while (eData.MoveNext()) { T data = (T)eData.Current; Type type = data.GetType(); bool publicRss = (bool)type.GetProperty("PublicRss").GetValue(data, null); if (!publicRss) { continue; } RssItemModel model = new RssItemModel(); int articleNo = (int)type.GetProperty("ArticleNo").GetValue(data, null); model.Title = type.GetProperty("Title").GetValue(data, null).ToString(); model.Link = Util.Utility.MakeArticleUrl(articleNo); model.Description = type.GetProperty("Content").GetValue(data, null).ToString(); model.Author = BlogManager.GetInstance().BlogBaseModel.BlogModel.Name; model.PubDate = type.GetProperty("InsertDate").GetValue(data, null).ToString(); TagBindModel tagBindModel = (TagBindModel)type.GetProperty("Tag").GetValue(data, null); foreach (TagModel tagModel in tagBindModel) { model.Category.Add(tagModel); } this.Item.Add(model); } }
protected void btnSubmit_Click(object sender, EventArgs e) { string title = txtTitle.Text.ToString(); string content = txtContent.Text.ToString(); int category = ddlCategories.SelectedIndex + 2; string imgUrl = ""; if (imgUpload.FileName.EndsWith(".jpg") | imgUpload.FileName.EndsWith(".png") | imgUpload.FileName.EndsWith(".jpeg")) { imgUrl = "img/blogimg/" + GetIntTime() + imgUpload.FileName.Substring(imgUpload.FileName.Length - 4, 4); imgUpload.SaveAs(Server.MapPath("~") + imgUrl); } Blog blog = new Blog(); blog.bTitle = title; blog.bContent = content; blog.bCategoryid = category; blog.bTitlepic = imgUrl; blog.bTags = ""; BlogManager blogManager = new BlogManager(); int res = blogManager.InsertBlog(blog); if (res != -1) { btnSubmit.Text = "成功"; } else { btnSubmit.Text = "失败"; } }
public ActionResult EditABlog(BlogVM blogVM) { BlogManager manager = BlogManagerFactory.Create(); if (blogVM.Blog.TagInputs != null) { string[] tags = blogVM.Blog.TagInputs.Split(','); foreach (var tag in tags) { var searchTag = new SearchTag() { SearchTagBody = tag }; blogVM.Blog.SearchTags.Add(searchTag); } blogVM.Blog.TagInputs = null; } manager.UpdateBlog(blogVM.Blog); return(RedirectToAction("MyBlogs")); }
private void BindGrid() { var blogPostCollection = BlogManager.GetAllBlogPosts(0); gvBlogPosts.DataSource = blogPostCollection; gvBlogPosts.DataBind(); }
public ActionResult Blog_Details(int Blog_Id) { ViewBag.Page = "Blog"; HomeViewModel homeViewModel = new HomeViewModel(); try { if (Blog_Id != 0) { BlogManager _blogMan = new BlogManager(); homeViewModel.blog = _blogMan.Get_Blog_By_Id(Blog_Id); homeViewModel.blog.Header_Image_Url = ConfigurationManager.AppSettings["Upload_Image_Path"].ToString() + @"\" + homeViewModel.blog.File_Type_Str + @"\" + homeViewModel.blog.Header_Image_Url; } ViewBag.Title = homeViewModel.blog.Title + " - MagniPi"; } catch (Exception ex) { Logger.Error("Home Controller - Blog_Details: " + ex.ToString()); homeViewModel.FriendlyMessage.Add(MessageStore.Get("SYS01")); } return(View("BlogDetails", homeViewModel)); }
private void SetTitle() { //string titleScript = string.Format("<script>document.title='{0}';</script>", // BlogManager.GetInstance().BlogBaseModel.BlogModel.Title); //ClientScript.RegisterClientScriptBlock( this.GetType(), "Title", titleScript ); Page.Title = BlogManager.GetInstance().BlogBaseModel.BlogModel.Title; }
private void BindData() { BlogPost blogPost = BlogManager.GetBlogPostById(this.BlogPostId); if (blogPost != null) { CommonHelper.SelectListItem(this.ddlLanguage, blogPost.LanguageId); this.txtBlogPostTitle.Text = blogPost.BlogPostTitle; this.txtBlogPostBody.Content = blogPost.BlogPostBody; this.cbBlogPostAllowComments.Checked = blogPost.BlogPostAllowComments; this.pnlCreatedOn.Visible = true; this.lblCreatedOn.Text = DateTimeHelper.ConvertToUserTime(blogPost.CreatedOn).ToString(); BlogCommentCollection blogComments = blogPost.BlogComments; if (blogComments.Count > 0) { this.hlViewComments.Visible = true; this.hlViewComments.Text = string.Format(GetLocaleResourceString("Admin.BlogPostInfo.ViewComments"), blogComments.Count); this.hlViewComments.NavigateUrl = CommonHelper.GetStoreAdminLocation() + "BlogComments.aspx?BlogPostID=" + blogPost.BlogPostId; } else { this.hlViewComments.Visible = false; } } else { this.pnlCreatedOn.Visible = false; hlViewComments.Visible = false; } }
public ActionResult Review(BlogVM model) { BlogManager manager = BlogManagerFactory.Create(); if (model.Blog.TagInputs != null) { string[] tags = model.Blog.TagInputs.Split(','); foreach (var tag in tags) { var searchTag = new SearchTag() { SearchTagBody = tag }; model.Blog.SearchTags.Add(searchTag); } model.Blog.TagInputs = null; } manager.UpdateBlog(model.Blog); return(RedirectToAction("ViewPending")); }
public RssModel() { this.Title = BlogManager.GetInstance().BlogBaseModel.BlogModel.Title; this.Link = BlogManager.GetInstance().BlogBaseModel.BlogModel.Url; this.Description = BlogManager.GetInstance().BlogBaseModel.BlogModel.Introduction; this.Copyright = BlogManager.GetInstance().BlogBaseModel.BlogModel.NickName; }
private void CreateLatestBlog() { BlogManager blogManager = new BlogManager(); List <Blog> blogs = blogManager.SelectLatestBlogs(); latestblogs.InnerHtml = ""; for (int i = 0; i < blogs.Count; i++) { string[] tags = blogs[i].bTags.Split(','); latestblogs.InnerHtml += "<div class=\"post col-md-4\">\n" + " <div class=\"post-thumbnail\">\n" + " <a href=\"BlogInfo.aspx?blogid=" + blogs[i].bID + "\">\n" + " <img src=\"https://zhanc.oss-cn-shenzhen.aliyuncs.com/web/zhancblog/" + blogs[i].bTitlepic + "\" alt=\"...\" class=\"img-fluid\"></a>\n" + " </div>\n" + " <div class=\"post-details\">\n" + " <div class=\"post-meta d-flex justify-content-between\">\n" + " <div class=\"date\">" + blogs[i].bUpdatedtime.ToString().Substring(0, 16) + "</div>\n" + " <div class=\"category\"><a href=\"javascript:void(0)\">" + tags[0] + "</a><a href=\"javascript:void(0)\">" + tags[1] + "</a></div>\n" + " </div>\n" + " <a href=\"BlogInfo.aspx\">\n" + " <h3 class=\"h4\">" + blogs[i].bTitle + "</h3>\n" + " </a>\n" + " <p class=\"text-muted\">" + (blogs[i].bContent.Length >= 50 ? blogs[i].bContent.Substring(0, 50) : blogs[i].bContent) + "...</p>\n" + " </div>\n" + " </div>"; } }
private void BindData() { BlogPostCollection blogPosts = BlogManager.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageID); rptrBlogPosts.DataSource = blogPosts; rptrBlogPosts.DataBind(); }
private void bind() { model = BlogManager.GetInstance().BlogBaseModel; txtTitle.Text = model.BlogModel.Title; txtUrl.Text = model.BlogModel.Url; txtEmail.Text = model.BlogModel.EMail; txtName.Text = model.BlogModel.Name; txtNickName.Text = model.BlogModel.NickName; txtIntroduction.Text = model.BlogModel.Introduction; ddlAddress.SelectedValue = model.BlogModel.Address; txtHobby.Text = model.BlogModel.Hobby; ddlGender.SelectedValue = ((BlogConst.Gender)model.BlogModel.Gender).ToString(); rblAlram.SelectedValue = model.BlogModel.Alarm.ToString(); rblAutoClip.SelectedValue = model.BlogModel.AutoClip.ToString(); rblPostCount.SelectedValue = model.BlogModel.PostCount.ToString(); rblRecentComment.SelectedValue = model.BlogModel.RecentCommentListCount.ToString(); rblRecentArticleCount.SelectedValue = model.BlogModel.RecentArticleListCount.ToString(); rblUseEmoticon.SelectedValue = model.BlogModel.UseEmoticon.ToString(); ddlNewIcon.SelectedValue = model.BlogModel.PeridoNewIcon.ToString(); if (model.BlogModel.Picture != string.Empty) { lblMyPicture.Text = BlogManager.GetInstance().GetMyPictureForImgTag(); } else { lblMyPicture.Text = MessageCode.GetMessageByCode(BlogConst.MESSAGE_HAS_NOT_MYPICTURE); } }
public void GetUserBlogs_NoBlogs() { var settings = Mock.Of <IWeBlogSettings>(x => x.ContentRootPath == "/sitecore/content" && x.BlogTemplateIds == new[] { ID.NewID } ); var manager = new BlogManager(settings); var membershipProvider = Mock.Of <MembershipProvider>(x => x.GetUser(_validUsername, true) == new FakeMembershipUser() ); using (var db = new Db()) { var item = db.GetItem("/sitecore/content"); using (new MembershipSwitcher(membershipProvider)) { var blogs = manager.GetUserBlogs(_validUsername); Assert.That(blogs, Is.Empty); } } }
protected void AddBinary(object sender, EventArgs e) { //get access to database... BlogManager bmo = new BlogManager(); try { if (bmo.Upload(fuUpload)) { pnlRespond.Visible = true; lblResult.Text = "We where successful with the upload of the file."; } } catch (Exception ex) { Response.Write(ex.Message); } }
public ActionResult Add(EntryModel entry) { if (!User.IsInRole("writer") && !User.IsInRole("chief")) { return Redirect("~/Home/AccessError"); } if (ModelState.IsValid) { Entry newEntry; BlogManager db = new BlogManager(); entry.Created = DateTime.Now; entry.Author = User.Identity.Name; newEntry = Mapper.Map<Entry>(entry); db.Add(newEntry); db.Save(); return RedirectToAction("ViewEntry", new { id = newEntry.Id }); } return View(entry); }
public void PrintBlog() { try { BlogManager bmo = new BlogManager(); StringBuilder sb = new StringBuilder(); // string cat = category; string[] bgEntry = bmo.PrintBlogEntry(category, true); foreach (var x in bgEntry) { sb.Append(x); } lblError.Text = sb.ToString(); } catch (Exception ex) { handleError(ex.Message, ex); } }
/* [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] public static AjaxControlToolkit.Slide[] printSlides(string contextKey) { return new AjaxControlToolkit.Slide[] { new AjaxControlToolkit.Slide("/Project/Handler.ashx?id=16", "windows", "pic1"), new AjaxControlToolkit.Slide("/Project/Handler.ashx?id=16", "phone", "this"), new AjaxControlToolkit.Slide("/Project/Handler.ashx?id=16", "windows7", "cool"), new AjaxControlToolkit.Slide("/Project/Handler.ashx?id=16", "web", "thia"), new AjaxControlToolkit.Slide("/Project/Handler.ashx?id=16", "shake", "make") }; } */ protected void uploadBinaryFile(object sender, EventArgs e) { BlogManager bmo = new BlogManager(); try { if (bmo.Upload(fuImage) == true) { lblMessage.Text = "Your Image was successfully added to the database."; } else { throw new Exception(@"Sorry for some reason there was an error. Perhaps your filetype was not supported please contact the webmaster at: [email protected]"); } //lblMessage.Text = "FileName: " + fuImage.FileName + " mimetype: " + fuImage.PostedFile.ContentType + " [Content]" + fuImage.PostedFile; } catch (Exception stderr) { lblMessage.Text = stderr.Message; } }
protected void uploadBinaryFile(object sender, EventArgs e) { BlogManager bmo = new BlogManager(); try { if (bmo.UploadVideo(fuImage) == true) { lblMessage.Text = "Your Image was successfully added to the database."; } else { throw new Exception("Sorry for some reason there was an error. Please try again in a few hours."); } //lblMessage.Text = "FileName: " + fuImage.FileName + " mimetype: " + fuImage.PostedFile.ContentType + " [Content]" + fuImage.PostedFile; } catch (Exception stderr) { Response.Write(stderr.Message); lblMessage.Text = stderr.Message; } }
protected void SearchSort(object sender, EventArgs e) { try { BlogManager bmo = new BlogManager(); if (ddlSort.SelectedIndex > 0) { StringBuilder sb = new StringBuilder(); string[] content = bmo.printBlogAndSort(searchBar.Text, getCat(), ddlSort.SelectedValue, true); foreach (var x in content) { sb.Append(x); } lblError.Text = sb.ToString(); // result = BlogManager.SearchBlogEntries(ddlSort.SelectedValue, searchBar.Text); } } catch (Exception ex) { handleError(ex.Message, ex); } }
public ActionResult Delete(int id) { BlogManager db = new BlogManager(); Entry etr = db.GetEntry(id); if ((etr.Author == User.Identity.Name && User.IsInRole("writer")) || User.IsInRole("chief")) { db.Delete(etr); db.Save(); return RedirectToAction("Index"); } else { return Redirect("~/Home/AccessError"); } }
public ActionResult Index(int page = 1, int pageSize = 5) { BlogManager db = new BlogManager(); int count = db.Count; IQueryable iq = db.GetAll(); ViewBag.PagesCount = Math.Ceiling((float)count / (float)pageSize); return View(); }
public ActionResult ViewEntry(int id) { BlogManager db = new BlogManager(); Entry ent = db.GetEntry(id); EntryModel entry = Mapper.Map<EntryModel>(ent); if (ent != null) { return View(entry); } else { return View("PostNotFound"); } }
public ActionResult Edit(Entry ent) { if (!User.IsInRole("chief") && !User.IsInRole("writer")) { return Redirect("~/Home/AccessError"); } if (User.IsInRole("writer") && User.Identity.Name != ent.Author) { return Redirect("~/Home/AccessError"); } BlogManager db = new BlogManager(); db.SaveEntry(ent); return RedirectToAction("ViewEntry", new { id = ent.Id }); }
/// <summary> /// Shows posts of user /// </summary> /// <param name="user">User name</param> /// <param name="page">Current page</param> /// <param name="pageSize">Amount of entries on page</param> /// <returns></returns> public ActionResult UserPosts(string user, int page = 1, int pageSize = 5) { BlogManager db = new BlogManager(); int count = db.GetCountForUser(user); if (count == 0) { return View("UserHaveNoPosts"); } ViewBag.PagesCount = Math.Ceiling((float)count / (float)pageSize); return View(); }
public ActionResult Edit(int id) { if (!User.IsInRole("chief") && !User.IsInRole("writer")) { return Redirect("~/Home/AccessError"); } BlogManager db = new BlogManager(); Entry ent = db.GetEntry(id); if (ent == null) { return Redirect("~/Home/Index"); } if (User.IsInRole("writer") && User.Identity.Name != ent.Author) { return Redirect("~/Home/AccessError"); } return View(ent); }
/// <summary> /// Gets entries for current page /// </summary> /// <param name="page">current page</param> /// <param name="user">user name</param> /// <returns></returns> public ActionResult GetPage(int page, string user = "******") { BlogManager db = new BlogManager(); IQueryable<Entry> items; EntryModel[] et; if (user == "all") { items = db.GetEntries(page); Entry[] entries = items.ToArray(); et = Mapper.Map<Entry[], EntryModel[]>(entries); } else { user = Server.UrlDecode(user); items = db.GetEntries(user, page); et = Mapper.Map<EntryModel[]>(items.ToArray()); } ViewBag.Items = et; return View(et); }