Example #1
0
        public ActionResult AddImage([Bind(Include = "Name,Description")] Image image)
        {
            //Validate Model
            if (ModelState.IsValid)
            {
                // Get first file
                var newImage = Request.Files[0];

                string errorMsg = "";

                if (!isValidName(image, ref errorMsg))
                {
                    ModelState.AddModelError("Name", errorMsg);
                    return(View());
                }


                //Check if file is Valid Image
                if (isValidImage(newImage, ref errorMsg))
                {
                    //Upload Image to Azure
                    Image UploadedImage = AzureStorage.UploadImage(newImage, image);

                    // Set Image Path
                    image.ImagePath = UploadedImage.ImagePath;

                    //Add Image to DB
                    int id = imageRepository.AddNewImage(image);

                    TempData["Success"] = "The image was added successfully";
                }
                else
                {
                    ModelState.AddModelError("ImagePath", errorMsg);
                }
            }
            return(View());
        }