public ActionResult delete_rating(Int32 id = 0, Int32 languageId = 0) { // Get the signed in user Administrator user = Administrator.GetSignedInAdministrator(); // Check if the post request is valid if (user == null) { return RedirectToAction("login", "user"); } // Get the current domain Domain domain = Tools.GetCurrentDomain(); // Get the rating PostRating postRating = PostRating.GetOneById(id, user.id, languageId); // Delete the rating if (postRating != null && postRating.administrator_id == user.id) { // Delete the rating PostRating.DeleteOnId(id, user.id, languageId); // Update the rating for the post Post.UpdateRating(postRating.post_id, postRating.language_id); } // Return the edit ratings view return RedirectToAction("edit_ratings"); } // End of the delete_rating method
public ActionResult edit(Int32 id = 0, Int32 administratorId = 0, Int32 languageId = 0, string returnUrl = "/admin_ratings") { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get query parameters ViewBag.QueryParams = new QueryParams(returnUrl); // Get the signed in administrator Administrator administrator = Administrator.GetSignedInAdministrator(); // Get the post rating PostRating postRating = PostRating.GetOneById(id, administratorId, languageId); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true) { ViewBag.AdminSession = true; } else if (administrator != null && administrator.admin_role == "Author" && (postRating == null || postRating.administrator_id == administrator.id)) { ViewBag.AdminSession = true; } else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true) { ViewBag.AdminSession = true; ViewBag.AdminErrorCode = 1; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); return View("index"); } else { // Redirect the user to the start page return RedirectToAction("index", "admin_login"); } // Get the default admin language Int32 adminLanguageId = currentDomain.back_end_language; // Add data to the view ViewBag.TranslatedTexts = StaticText.GetAll(adminLanguageId, "id", "ASC"); ViewBag.PostRating = postRating; ViewBag.ReturnUrl = returnUrl; // Return the user to the index page if the rating does not exist if (ViewBag.PostRating == null) { // Return the user to the index page return Redirect(returnUrl); } // Return the edit view return View("edit"); } // End of the edit method
public ActionResult edit_rating(FormCollection collection) { // Make sure that the user is signed in Administrator user = Administrator.GetSignedInAdministrator(); // Get the current domain Domain domain = Tools.GetCurrentDomain(); // Get the translated texts KeyStringList tt = StaticText.GetAll(domain.front_end_language, "id", "ASC"); // Check if the post request is valid if (user == null || collection == null) { return RedirectToAction("login", "user"); } // Get the form data Int32 post_id = Convert.ToInt32(collection["hiddenPostId"]); Int32 language_id = Convert.ToInt32(collection["hiddenLanguageId"]); decimal userVote = 0; decimal.TryParse(collection["userVote"], NumberStyles.Any, CultureInfo.InvariantCulture, out userVote); // Get the post Post post = Post.GetOneById(post_id, language_id); // Try to get a saved rating PostRating postRating = PostRating.GetOneById(post_id, user.id, language_id); // Add or update the rating if (postRating != null && postRating.administrator_id == user.id) { // Update values postRating.rating_date = DateTime.UtcNow; postRating.rating = userVote; // Update the rating PostRating.Update(postRating); } else { // Create a new rating postRating = new PostRating(); // Update values postRating.post_id = post_id; postRating.administrator_id = user.id; postRating.language_id = language_id; postRating.rating_date = DateTime.UtcNow; postRating.rating = userVote; // Add the rating PostRating.Add(postRating); } // Send a email to the administrator of the website string subject = tt.Get("rating") + " - " + domain.website_name; string message = tt.Get("post") + ": " + postRating.post_id.ToString() + "<br />" + tt.Get("language") + ": " + postRating.language_id.ToString() + "<br />" + tt.Get("user_name") + ": " + user.admin_user_name + "<br />" + tt.Get("rating") + ": " + postRating.rating.ToString(); Tools.SendEmailToHost("", subject, message); // Update the rating for the post Post.UpdateRating(postRating.post_id, postRating.language_id); // Redirect the user to the post return Redirect("/home/post/" + post.page_name + "#comments"); } // End of the edit_rating method
public ActionResult delete(Int32 id = 0, Int32 administratorId = 0, Int32 languageId = 0, string returnUrl = "/admin_ratings") { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get query parameters ViewBag.QueryParams = new QueryParams(returnUrl); // Get the signed in administrator Administrator administrator = Administrator.GetSignedInAdministrator(); // Get the post rating PostRating postRating = PostRating.GetOneById(id, administratorId, languageId); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator" }) == true) { ViewBag.AdminSession = true; } else if (administrator != null && administrator.admin_role == "Author" && (postRating == null || postRating.administrator_id == administrator.id)) { ViewBag.AdminSession = true; } else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true) { ViewBag.AdminSession = true; ViewBag.AdminErrorCode = 1; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); return View("index"); } else { // Redirect the user to the start page return RedirectToAction("index", "admin_login"); } // Get the rating post PostRating rating = PostRating.GetOneById(id, administratorId, languageId); // Create an error code variable Int32 errorCode = 0; // Make sure that the rating not is null if (rating != null) { // Delete the rating errorCode = PostRating.DeleteOnId(id, administratorId, languageId); // Check if there is an error if (errorCode != 0) { ViewBag.AdminErrorCode = errorCode; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); return View("index"); } // Update the post rating Post.UpdateRating(rating.post_id, rating.language_id); } // Redirect the user to the list return Redirect(returnUrl); } // End of the delete method
public ActionResult edit(FormCollection collection) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get all the form values Int32 post_id = Convert.ToInt32(collection["hiddenPostId"]); Int32 administrator_id = Convert.ToInt32(collection["hiddenAdministratorId"]); Int32 language_id = Convert.ToInt32(collection["hiddenLanguageId"]); decimal rating = 0; decimal.TryParse(collection["userVote"].Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture, out rating); string returnUrl = collection["returnUrl"]; // Get query parameters ViewBag.QueryParams = new QueryParams(returnUrl); // Get the signed in administrator Administrator administrator = Administrator.GetSignedInAdministrator(); // Get the post rating PostRating postRating = PostRating.GetOneById(post_id, administrator_id, language_id); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true) { ViewBag.AdminSession = true; } else if (administrator != null && administrator.admin_role == "Author" && (postRating == null || postRating.administrator_id == administrator.id)) { ViewBag.AdminSession = true; } else if (Administrator.IsAuthorized(Administrator.GetAllAdminRoles()) == true) { ViewBag.AdminSession = true; ViewBag.AdminErrorCode = 1; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); return View("index"); } else { // Redirect the user to the start page return RedirectToAction("index", "admin_login"); } // Update the post rating if (postRating != null) { // Update the rating for the post postRating.rating = rating; PostRating.Update(postRating); // Update the rating sum for the post Post.UpdateRating(post_id, language_id); } // Redirect the user to the list return Redirect(returnUrl); } // End of the edit method