Esempio n. 1
0
        public ActionResult Create(Tour tour)
        {
            if (ModelState.IsValid)
            {
                dbContext.Tours.Add(tour);
                dbContext.SaveChanges();
                return(RedirectToAction("index"));
            }

            return(View(tour));
        }
        public ActionResult Create([Bind(Include = "CategoryId,CategoryName,CategoryDescription,CategoryPhotoLink")] tourCategory tourCategory)
        {
            if (ModelState.IsValid)
            {
                db.tourCategories.Add(tourCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tourCategory));
        }
Esempio n. 3
0
 public ActionResult Upload(HttpPostedFileBase file)
 {
     if (file != null)
     {
         //check if file is valid
         if (ValidateFile(file))
         {
             try
             {
                 SaveFileToDisk(file);
             }
             catch (Exception)
             {
                 ModelState.AddModelError("FileName", "Sorry an error occured saving the file to the disk" +
                                          ", please try again");
             }
         }
         else
         {
             //if the user has not entered a file return an error message
             ModelState.AddModelError("FileName", "The file must be a gif,png,jpeg or jpg and less than 2MB in size");
         }
     }
     else
     {
         //if the user has not entered a file return an error message
         ModelState.AddModelError("FileName", "Please choose a file");
     }
     if (ModelState.IsValid)
     {
         db.tourPhotoes.Add(new tourPhoto {
             FileName = file.FileName
         });
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }