public JsonResult GetPostData(int id) { POST result = ArtRepo.GetPost(id); if (result.Tags != null) { result.Tags = result.Tags.Replace(",", string.Empty); } return(Json(result)); }
public JsonResult SaveChanges(POST editedPost) { if (!CheckAuth()) { return(new JsonResult("403")); } ArtRepo.UpdatePost(editedPost); return(new JsonResult("success")); }
public IActionResult AddPost() { IFormFile pic = HttpContext.Request.Form.Files[0]; string extension = Path.GetExtension(pic.FileName); POST newPost = new POST(); newPost.Description = HttpContext.Request.Form["Description"]; newPost.Title = HttpContext.Request.Form["Title"]; newPost.Tags = HttpContext.Request.Form["Tags"]; newPost.Date = DateTime.Now; newPost.Deleted = 0; string filename = "pics/" + DateTime.Now.Ticks.ToString() + extension; using (FileStream fs = System.IO.File.Create("wwwroot/" + filename)) { pic.CopyTo(fs); fs.Flush(); } newPost.ImgUrl = filename; ArtRepo.AddPost(newPost); return(RedirectToAction("Index")); }
public JsonResult GetPosts(int page = 1, string search = "") { List <POST> result; if (search == null) { result = ArtRepo.GetPosts(); } else { result = ArtRepo.SearchPosts(search); } int start = 10 * (page - 1); int end = (10 * page) - 1; bool leftArrow = true; bool rightArrow = false; if (page > 1) { leftArrow = false; } if (result.Count - 1 == end) { rightArrow = true; } if (result.Count - 1 < start) { start = result.Count - 1; } if (result.Count - 1 < end) { end = result.Count - 1; rightArrow = true; } var ArrowState = new { rightArrow = rightArrow, leftArrow = leftArrow }; List <POST> Posts = result.GetRange(start, (end + 1) - start); foreach (POST i in Posts) { if (i.Tags != null) { i.Tags = i.Tags.Replace(",", string.Empty); } } var Send = new { Posts = Posts, ArrowState = ArrowState }; return(Json(Send)); }