Esempio n. 1
0
        public HttpResponseMessage add(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);

            // Add the post
            InspirationImageMap.Add(post);;

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method
Esempio n. 2
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