Esempio n. 1
0
        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
Esempio n. 2
0
        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
Esempio n. 3
0
        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 += "&#149; " + String.Format(tt.Get("error_field_length"), tt.Get("name"), "50") + "<br/>";
            }
            if (imageMap.image_name.Length > 100)
            {
                errorMessage += "&#149; " + 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