public IActionResult OnPost() { var Username = HttpContext.Session.GetString("username"); if (string.IsNullOrEmpty(Username)) { return(RedirectToPage("/Index")); } SingleUserData = userData.GetByUserName(Username); writeBlog.Users = SingleUserData; ; if (BlogPicture != null) { writeBlog.BlogImage = UploadedPicture(BlogPicture, SingleUserData.UserName); } var newBlog = new Blogs() { Users = writeBlog.Users, BlogTitle = writeBlog.BlogTitle, BlogDescription = writeBlog.BlogDescription, Blogcontent = writeBlog.Blogcontent, BlogDate = DateTime.Now.Date, BlogImage = writeBlog.BlogImage }; bool res = blogData.AddBlog(newBlog); if (res) { blogData.Commit(); return(RedirectToPage("/User/Dashboard", new { urlname = Username })); } return(Page()); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } blogData.Update(Blog); blogData.Commit(); return(RedirectToPage("./Detail", new { blogId = Blog.blogId })); }
public IActionResult OnPost(int blogId) { var confirmdelete = blogdata.DeleteBlog(blogId); if (confirmdelete != true) { return(Page()); } blogdata.Commit(); var us = HttpContext.Session.GetString("username"); return(RedirectToPage("Dashboard", new { urlname = us })); }
public IActionResult OnPost(int blogDetailsId) { var blogData = _blogData.Delete(blogDetailsId); _blogData.Commit(); if (blogData == null) { return(RedirectToPage("./NotFound")); } TempData["Message"] = $"{blogData.Title} deleted"; return(RedirectToPage("./Index")); }
public async Task <ActionResult> OnPost(int blogId) { blog = blogData.GetById(blogId); if (blog == null) { return(RedirectToPage("./NotFound")); } blogData.Delete(blog); if (await blogData.Commit()) { TempData["Message"] = $"Blog Deleted!"; return(RedirectToPage("./List", new { blogTypeId = blog.blogTypeId })); } return(RedirectToPage("./NotFound")); }
public async Task <ActionResult> OnPost() { if (!ModelState.IsValid) { Types = typeData.GetAll(); typeList = new SelectList(Types, "blogTypeId", "type"); return(Page()); } //Upload image or use default image string filename = null; if (Input.blogImageURL != null) { string uploadFolder = Path.Combine(hostEnvironment.WebRootPath, "images/BlogImages"); filename = Guid.NewGuid().ToString() + "_" + Input.blogImageURL.FileName; string filePath = Path.Combine(uploadFolder, filename); await Input.blogImageURL.CopyToAsync(new FileStream(filePath, FileMode.Create)); } else { filename = "new.jpg"; } //Create new Blog Blog = new Blog { blogTypeId = Input.blogTypeId, name = Input.name, body = Input.body, blogImageURL = filename, approved = false, userId = User.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value }; blogData.Add(Blog); if (await blogData.Commit()) { TempData["Message"] = $"Blog Added"; return(RedirectToPage("../Index", new { blogTypeId = Blog.blogTypeId })); } return(RedirectToPage("./NotFound")); }
public async Task <IActionResult> OnPost(int blogId) { Blog = blogData.GetById(blogId); userProfile = accountData.GetById(Blog.userId); if (Blog == null) { return(RedirectToPage("./NotFound")); } Blog.approved = true; blogData.Update(Blog); if (await blogData.Commit()) { TempData["Message"] = $"{Blog.name} approved"; return(RedirectToPage("./ReviewBlogs")); } return(RedirectToPage("./NotFound")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } if (BlogDetails.Id > 0) { _blogData.Update(BlogDetails); TempData["Message"] = "Post Updated!"; } else { _blogData.Add(BlogDetails); TempData["Message"] = "Post Added!"; } _blogData.Commit(); //redirects to index return(RedirectToPage("./Index")); }