public ProductReview get_by_id(Int32 id = 0) { // Create the post to return ProductReview post = ProductReview.GetOneById(id); // Return the post return(post); } // End of the get_by_id method
public ActionResult delete(Int32 id = 0, string returnUrl = "") { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get query parameters ViewBag.QueryParams = new QueryParams(returnUrl); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator" }) == true) { 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 review ProductReview review = ProductReview.GetOneById(id); // Create an error code variable Int32 errorCode = 0; // Make sure that the review not is null if(review != null) { // Delete the review errorCode = ProductReview.DeleteOnId(id); // 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 product rating Product.UpdateRating(review.product_id, review.language_id); } // Redirect the user to the list return Redirect("/admin_product_reviews" + returnUrl); } // End of the delete method
public ActionResult edit(Int32 id = 0, string returnUrl = "") { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get query parameters ViewBag.QueryParams = new QueryParams(returnUrl); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true) { 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.ProductReview = ProductReview.GetOneById(id); ViewBag.ReturnUrl = returnUrl; // Return the user to the index page if the review does not exist if (ViewBag.ProductReview == null) { // Return the user to the index page return Redirect("/admin_product_reviews" + returnUrl); } // Return the edit view return View("edit"); } // End of the edit method
public ActionResult edit(FormCollection collection) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get query parameters string returnUrl = collection["returnUrl"]; ViewBag.QueryParams = new QueryParams(returnUrl); // Check if the administrator is authorized if (Administrator.IsAuthorized(new string[] { "Administrator", "Editor" }) == true) { 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 all the form values Int32 id = Convert.ToInt32(collection["txtId"]); string reviewText = collection["txtReviewText"]; // Get the product review ProductReview review = ProductReview.GetOneById(id); // Update the review if(review != null) { review.review_text = reviewText; ProductReview.Update(review); } // Redirect the user to the list return Redirect("/admin_product_reviews" + returnUrl); } // End of the edit method
public HttpResponseMessage update(ProductReview post) { // Check for errors if (post == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null")); } else if (Product.MasterPostExists(post.product_id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The product does not exist")); } else if (Customer.MasterPostExists(post.customer_id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The customer does not exist")); } else if (Language.MasterPostExists(post.language_id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist")); } // Make sure that the data is valid post.review_date = AnnytabDataValidation.TruncateDateTime(post.review_date); post.rating = AnnytabDataValidation.TruncateDecimal(post.rating, 0, 999999.99M); // Get the saved post ProductReview savedPost = ProductReview.GetOneById(post.id); // Check if the post exists if (savedPost == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The record does not exist")); } // Update the post ProductReview.Update(post); // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful")); } // End of the update method