public ActionResult Index() { var response = new DAO.ArticleController().GetAllArticle().Result; List <Post> articles = new List <Post>(); if (response.IsSuccessStatusCode) { var articleDetails = response.Content.ReadAsAsync <List <Post> >().Result; if (articleDetails != null) { articles = articleDetails; } else { articles = null; } } else { articles = null; } return(View(articles)); }
public ActionResult ArticleById(int articleId) { try { var response = new DAO.ArticleController().GetArticleById(articleId).Result; Post article = new Post(); if (response.IsSuccessStatusCode) { article = response.Content.ReadAsAsync <Post>().Result; if (article != null) { return(View(article)); } else { return(RedirectToAction("NotFound", "Home")); } } else { return(RedirectToAction("NotFound", "Home")); } } catch (Exception ex) { new Logger().LogError(ModuleName, "ArticleById", "Error Getting Article By Id " + articleId + " " + ex + "\n"); return(RedirectToAction("NotFound", "Home")); } }
public ActionResult DeleteArticle(int articleId, int authorId) { try { var result = new DAO.ArticleController().DeleteArticle(articleId, authorId).Result; if (result.IsSuccessStatusCode) { //GET ARTICLE var status = result.Content.ReadAsAsync <bool>().Result; if (status) { return(Json(new { success = true, message = "Article Deleted successfully" })); } else { return(Json(new { success = false, message = "Deleting Article failed, Please Try Again" })); } } else { return(Json(new { success = false, message = "Deleting Article Failed, Please Try Again" })); } } catch (Exception ex) { new Logger().LogError(ModuleName, "DeleteArticle", "Error Deleting Article " + ex + "\n"); return(Json(new { success = false, message = "Deleting Article Failed, Please Try Again" })); } }
public ActionResult AuthorProfile(int authorId) { try { var response = new DAO.ProfileController().GetAuthorProfile(authorId).Result; Profile profile = new Profile(); if (response.IsSuccessStatusCode) { var authorDetails = response.Content.ReadAsAsync <Author>().Result; if (authorDetails != null) { //get author articles var articleResponse = new DAO.ArticleController().GetArticleByAuthorId(authorId).Result; if (articleResponse.IsSuccessStatusCode) { var authorArticles = articleResponse.Content.ReadAsAsync <List <Post> >().Result; if (authorArticles != null) { profile.Posts = authorArticles; } else { profile.Posts = null; } } else { profile.Posts = null; } profile.authorId = authorDetails.authorId; profile.email = authorDetails.email; profile.username = authorDetails.username; profile.dateRegistered = authorDetails.dateRegistered; profile.profile = authorDetails.profile; return(View(profile)); } else { return(RedirectToAction("NotFound", "Home")); } } else { return(RedirectToAction("NotFound", "Home")); } } catch (Exception ex) { new Logger().LogError(ModuleName, "GetAuthorProfile", "Error GettingAuthorProfiile - Server Error" + "Status Code: " + ex + "\n"); return(RedirectToAction("NotFound", "Home")); } }
public ActionResult PostArticle(Post article) { try { article.createDate = DateTime.Today; article.updateDate = DateTime.Today; StringBuilder text = new StringBuilder(); // Encode text text.Append(HttpUtility.HtmlEncode(article.text)); text.Replace("<b>", "<b>"); text.Replace("</b>", "</b>"); text.Replace("<br/>", "<br/>"); text.Replace("<em>", "<em>"); text.Replace("</em>", "</em>"); text.Replace("<u>", "<u>"); text.Replace("</u>", "</u>"); text.Replace("<h4>", "<h4>"); text.Replace("</h4>", "</h4>"); text.Replace("<p>", "<p>"); text.Replace("</p>", "</p>"); article.text = text.ToString(); var postArticleResult = new DAO.ArticleController().AddArticle(article).Result; if (postArticleResult.IsSuccessStatusCode) { //GET ARTICLE var result = postArticleResult.Content.ReadAsAsync <bool>().Result; if (result) { return(Json(new { success = true, message = "Article Posted successfully" })); } else { return(Json(new { success = false, message = "Posting Article failed, Please Try Again" })); } } else { return(Json(new { success = false, message = "Posting Article Failed, Please Try Again" })); } } catch (Exception ex) { new Logger().LogError(ModuleName, "PostArticle", "Error Posting Article " + ex + "\n"); return(Json(new { success = false, message = "Posting Article Failed, Please Try Again" })); } }
public ActionResult EditArticle(int articleId, int authorId) { try { Post article = new Post(); var author = Session["AUTHORID"] != null ? (Session["AUTHORID"]) : null; if (author != null) { var response = new DAO.ArticleController().GetArticleById(articleId).Result; if (response.IsSuccessStatusCode) { article = response.Content.ReadAsAsync <Post>().Result; if (article != null) { if (article.authorId == authorId) { return(View(article)); } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Index", "Home")); } } catch (Exception ex) { new Logger().LogError(ModuleName, "EditArticle", "Error Getting Article By Id " + ex + "\n"); return(RedirectToAction("NotFound", "Home")); } }
public ActionResult DeleteAuthor(int authorId) { try { var articleDeleteResult = new DAO.ArticleController().DeleteArticleByAuthorId(authorId).Result; if (articleDeleteResult.IsSuccessStatusCode) { var result = new DAO.ProfileController().DeleteAuthor(authorId).Result; if (result.IsSuccessStatusCode) { //GET ARTICLE var status = result.Content.ReadAsAsync <bool>().Result; if (status) { Session["AUTHORID"] = null; Session["AUTHOR"] = null; return(Json(new { success = true, message = "Your Profile has been Deleted and all records cleared," })); } else { return(Json(new { success = false, message = "Deleting Your Profile failed, Please Try Again" })); } } else { return(Json(new { success = false, message = "Deleting Your Profile failed, Please Try Again" })); } } else { return(Json(new { success = false, message = "Deleting Your Profile Failed, Please Try Again" })); } } catch (Exception ex) { new Logger().LogError(ModuleName, "DeleteAuthor", "Error Deleting Author " + ex + "\n"); return(Json(new { success = false, message = "Deleting Your Profile Failed, Please Try Again" })); } }
public ActionResult EditArticle(Post article) { try { if (article != null) { var authorId = Session["AUTHORID"] != null ? (Session["AUTHORID"]) : null; StringBuilder text = new StringBuilder(); // Encode text text.Append(HttpUtility.HtmlEncode(article.text)); text.Replace("<b>", "<b>"); text.Replace("</b>", "</b>"); text.Replace("<br/>", "<br/>"); text.Replace("<em>", "<em>"); text.Replace("</em>", "</em>"); text.Replace("<u>", "<u>"); text.Replace("</u>", "</u>"); text.Replace("<h4>", "<h4>"); text.Replace("</h4>", "</h4>"); text.Replace("<p>", "<p>"); text.Replace("</p>", "</p>"); article.text = text.ToString(); if (authorId != null) { if (authorId.ToString() == article.authorId.ToString()) { article.updateDate = DateTime.Today; var response = new DAO.ArticleController().UpdateArticle(article, Int32.Parse(authorId.ToString())).Result; if (response.IsSuccessStatusCode) { var update = response.Content.ReadAsAsync <bool>().Result; if (update == true) { return(Json(new { success = true, message = "Article Update Successful" })); } else { new Logger().LogError(ModuleName, "EditArticle", "Error Editing Article - false" + "\n"); return(Json(new { success = false, message = "Edit Article Failed, Please Try Again" })); } } else { new Logger().LogError(ModuleName, "EditArticle", "Error EditArticle - Unauthorized or Server Error" + "Status Code: " + response.StatusCode + "\n"); return(Json(new { success = false, message = "Edit Article Failed , Please Try Again" })); } } else { return(Json(new { success = false, message = "Edit Article Failed- Not Authorized , Please Try Again" + authorId.ToString() + article.authorId.ToString() })); } } else { return(RedirectToAction("index", "Home")); } } else { new Logger().LogError(ModuleName, "EditArticle", "Error Editing Article " + "\n"); return(Json(new { success = false, message = "Edit Article Failed, Please Provide all necessary Details" })); } } catch (Exception ex) { new Logger().LogError(ModuleName, "EditArticle", "Error Editing Article " + ex + "\n"); return(Json(new { success = false, message = "Edit Article failed - Server Error, Please Try Again" })); } }