public HttpResponseMessage update(InspirationImageMap post) { // Check for errors if (post == null) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null")); } else if (post.language_id != 0 && Language.MasterPostExists(post.language_id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist")); } else if (post.category_id != 0 && Category.MasterPostExists(post.category_id) == false) { return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The category does not exist")); } // Make sure that the data is valid post.name = AnnytabDataValidation.TruncateString(post.name, 50); post.image_name = AnnytabDataValidation.TruncateString(post.image_name, 100); // Get the saved post InspirationImageMap savedPost = InspirationImageMap.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 InspirationImageMap.Update(post); // Return the success response return(Request.CreateResponse <string>(HttpStatusCode.OK, "The update was successful")); } // End of the update method
public InspirationImageMap get_by_id(Int32 id = 0) { // Create the post to return InspirationImageMap post = InspirationImageMap.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 image map InspirationImageMap imageMap = InspirationImageMap.GetOneById(id); // Create an error code variable Int32 errorCode = 0; // Delete the image map post and all the connected posts (CASCADE) errorCode = InspirationImageMap.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"); } // Delete the image if (imageMap != null) { DeleteInspirationImage(imageMap.id); } // Redirect the user to the list return Redirect("/admin_inspiration" + returnUrl); } // End of the delete method
public ActionResult image_map(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"); } // Add data to the view ViewBag.Keywords = ""; ViewBag.CurrentPage = 1; ViewBag.TranslatedTexts = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); ViewBag.Languages = Language.GetAll(currentDomain.back_end_language, "name", "ASC"); ViewBag.InspirationImageMap = InspirationImageMap.GetOneById(id); ViewBag.ReturnUrl = returnUrl; // Return the view if (ViewBag.InspirationImageMap != null) { // Return the image view return View("image_map"); } else { return Redirect("/admin_inspiration" + returnUrl); } } // End of the image_map method
public string get_image_by_id(Int32 id = 0) { // Create the string to return string url = ""; // Get the post InspirationImageMap post = InspirationImageMap.GetOneById(id); // Make sure that the post not is null if (post == null) { return(url); } // Get the url url = Tools.GetInspirationImageUrl(post.id, post.image_name); // Return the url return(url); } // End of the get_image_by_id method
public ActionResult image_map(FormCollection collection) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get all the form values Int32 id = Convert.ToInt32(collection["txtId"]); string image_map_points = collection["hiddenImageMapPoints"]; string keywords = collection["txtSearch"]; Int32 currentPage = Convert.ToInt32(collection["hiddenPage"]); string returnUrl = collection["returnUrl"]; // 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 translated texts KeyStringList tt = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); // Get the image map InspirationImageMap imageMap = InspirationImageMap.GetOneById(id); // Update values imageMap.image_map_points = image_map_points; // Check if the user wants to do a search if (collection["btnSearch"] != null) { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = 1; ViewBag.InspirationImageMap = imageMap; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("image_map"); } // Check if the user wants to do a search if (collection["btnPreviousPage"] != null) { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = currentPage - 1; ViewBag.InspirationImageMap = imageMap; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("image_map"); } // Check if the user wants to do a search if (collection["btnNextPage"] != null) { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = currentPage + 1; ViewBag.InspirationImageMap = imageMap; ViewBag.TranslatedTexts = tt; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("image_map"); } // Check if there is errors if (collection["btnSearchProducts"] == null) { // Update the image map InspirationImageMap.Update(imageMap); // Redirect the user to the list return Redirect("/admin_inspiration" + returnUrl); } else { // Set form values ViewBag.Keywords = keywords; ViewBag.CurrentPage = 1; ViewBag.TranslatedTexts = tt; ViewBag.InspirationImageMap = imageMap; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("image_map"); } } // End of the image_map method
public ActionResult edit(FormCollection collection) { // Get the current domain Domain currentDomain = Tools.GetCurrentDomain(); ViewBag.CurrentDomain = currentDomain; // Get the return url 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"]); Int32 language_id = Convert.ToInt32(collection["selectLanguage"]); string name = collection["txtName"]; Int32 category_id = Convert.ToInt32(collection["selectCategory"]); HttpPostedFileBase inspirationImage = Request.Files["uploadInspirationImage"]; // Get translated texts KeyStringList tt = StaticText.GetAll(currentDomain.back_end_language, "id", "ASC"); // Get the image map InspirationImageMap imageMap = InspirationImageMap.GetOneById(id); bool postExists = true; // Check if the image map exists if (imageMap == null) { // Create an empty image map imageMap = new InspirationImageMap(); postExists = false; } // Update values imageMap.language_id = language_id; imageMap.name = name; imageMap.category_id = category_id; // Set the image name if (inspirationImage.ContentLength > 0) { imageMap.image_name = System.IO.Path.GetFileName(inspirationImage.FileName); } // Create a error message string errorMessage = ""; // Check for errors in the image map if (imageMap.name.Length > 50) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "50") + "<br/>"; } if (imageMap.image_name.Length > 100) { errorMessage += "• " + String.Format(tt.Get("error_field_length"), tt.Get("file_name"), "100") + "<br/>"; } // Check if there is errors if (errorMessage == "") { // Check if we should add or update the image map if (postExists == false) { // Add the image map Int64 insertId = InspirationImageMap.Add(imageMap); imageMap.id = Convert.ToInt32(insertId); } else { // Update the image map InspirationImageMap.Update(imageMap); } // Update the image if (inspirationImage.ContentLength > 0) { UpdateInspirationImage(imageMap, inspirationImage); } // Redirect the user to the list return Redirect("/admin_inspiration" + returnUrl); } else { // Set form values ViewBag.ErrorMessage = errorMessage; ViewBag.TranslatedTexts = tt; ViewBag.Languages = Language.GetAll(currentDomain.back_end_language, "id", "ASC"); ViewBag.InspirationImageMap = imageMap; ViewBag.ReturnUrl = returnUrl; // Return the edit view return View("edit"); } } // End of the edit method