Example #1
0
 public ActionResult SaveRestaurant(Restaurant model)
 {
     if (ModelState.IsValid)
     {
         _db.Restaurants.Add(model);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
 public ActionResult Create(Restaurant restaurant)
 {
     if (ModelState.IsValid)
     {
         db.Restaurants.Add(restaurant);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(restaurant));
 }
 public ActionResult Create(RestaurantReview review)
 {
     if (ModelState.IsValid)
     {
         _db.Reviews.Add(review);
         _db.SaveChanges();
         return(RedirectToAction("Index", new { id = review.RestaurantId }));
     }
     return(View(review));
 }
 public ActionResult Create(RestaurantReview review)
 {
     if (ModelState.IsValid)
     {
         review.ReviewerName = User.Identity.Name;
         _db.Reviews.Add(review);                                             //If IsValid returns true, then add this review to the Reviews collections
         _db.SaveChanges();                                                   //This will actually save it to the database
         return(RedirectToAction("Index", new { id = review.RestaurantId })); //Second paramter ensures the user can then view their newly entered review (as we've passed the id through).
     }
     return(View(review));                                                    //Passing 'review' as a parameter here ensures that the user doesn't lose their already inputted data.
 }
        public ActionResult Create([Bind(Include = "Id,Name,City,Country")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                db.Restaurants.Add(restaurant);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(restaurant));
        }
Example #6
0
        public ActionResult Create([Bind(Include = "Id, RestaurantId, Rating, Body")] RestaurantReview review)
        {
            if (ModelState.IsValid)
            {
                review.RestaurantId = (int)Session["RestaurantId"];
                _db.Reviews.Add(review);
                _db.SaveChanges();
                return(RedirectToAction("Index", new { RestaurantId = (int)Session["RestaurantId"] }));
            }

            return(View(review));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Pub,VFriendly,LastUpdatedDateTime")] Restaurant restaurant)
        {
            if (ModelState.IsValid)
            {
                restaurant.LastUpdatedDateTime = DateTime.Now;
                db.Restaurants.Add(restaurant);
                db.SaveChanges();
                return(RedirectToAction("Restaurant"));
            }

            return(View(restaurant));
        }
Example #8
0
        public ActionResult Create([Bind(Include = "Name,Rating,Comment,Author")] RestaurantReview restaurantReview)
        {
            if (ModelState.IsValid)
            {
                restaurantReview.LastUpdated = DateTime.Now;
                db.Reviews.Add(restaurantReview);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(restaurantReview));
        }
Example #9
0
        public ActionResult Create(Comments comments)
        {
            if (ModelState.IsValid)
            {
                db.Comments.Add(comments);
                db.SaveChanges();

                BackgroundJob.Enqueue(() => NewComment.NotifyNewComment(comments.Id));
                //  RecurringJob.AddOrUpdate(() => NewComment.Send("*****@*****.**", "test", "Test Recuret Task"), Cron.Minutely);
            }
            return(RedirectToAction("Index"));
        }
Example #10
0
        public ActionResult Create(RecipeReview recipeReview)
        {
            if (ModelState.IsValid)
            {
                recipeReview.ReviewerName = User.Identity.Name;
                db.RecipeReviews.Add(recipeReview);
                db.SaveChanges();
                return(RedirectToAction("Index", new { id = recipeReview.RecipeId }));
            }

            return(View(recipeReview));
        }
Example #11
0
        public ActionResult Edit([Bind(Exclude = "ReviewerName")] RestaurantReview review)
        {
            if (ModelState.IsValid)
            {
                _db.Entry(review).State = System.Data.Entity.EntityState.Modified;

                _db.SaveChanges();

                return(RedirectToAction("Index", new { id = review.RestaurantId }));
            }

            return(View(review));
        }
Example #12
0
        public ActionResult Create(RestaurantListViewModel restaurant)
        {
            Restaurant newRestaurant;

            if (ModelState.IsValid)
            {
                newRestaurant = AutoMapper.Mapper.Map <RestaurantListViewModel, Restaurant>(restaurant);
                _db.Restaurants.Add(newRestaurant);
                _db.SaveChanges();
                return(RedirectToAction("Index", "Restaurant"));
            }
            HttpContext.Response.StatusCode = 500;
            return(PartialView("_CreateRestaurant", restaurant));
        }
Example #13
0
        public ActionResult Create(RestaurantReview review)
        {
            if (ModelState.IsValid)
            {
                if (!review.DateCreated.HasValue)
                {
                    review.DateCreated = DateTime.Now;
                }

                _db.RestaurantReviews.Add(review);
                _db.SaveChanges();
                return(RedirectToAction("Index", new { id = review.RestaurantId }));
            }
            return(View(review));
        }
Example #14
0
 public ActionResult Create(RestaurantReview review)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             _db.Reviews.Add(review);
             _db.SaveChanges();
             return(RedirectToAction("Index", new { id = review.RestaurantId }));
         }
         return(View(review));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult Create(RestaurantReview review)
        {
            //Model binder will instantiate RestaurantReview and populate it with values from the request
            //Will also give the restaurant id to associate it correctly.

            // check if model state is valid
            if (ModelState.IsValid)
            {
                // Add the review to the collection
                _db.Reviews.Add(review);

                // Save to the db
                _db.SaveChanges();

                return(RedirectToAction("Index", new { id = review.RestaurantId }));
            }

            return(View(review));
        }
        public ActionResult Create(Recipe recipe, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/")
                                + file.FileName);
                    recipe.ImagePath = file.FileName;
                }

                recipe.UserName = User.Identity.Name;//This allows me to match the Recipe's UserName property with the UserName of the currently logged in user.

                recipe.Date = DateTime.Today;
                db.Recipes.Add(recipe);
                db.SaveChanges();
                return(RedirectToAction("DisplayList"));
            }

            return(View(recipe));
        }
        public ActionResult Create(Restaurant restaurant, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                //string fileName = Path.GetFileNameWithoutExtension(restaurant.ImageFile.FileName);
                //string extension = Path.GetExtension(restaurant.ImageFile.FileName);
                //fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                //restaurant.ImagePath = "~/Images/" + fileName;
                //fileName = Path.Combine(Server.MapPath("~/Images/"), fileName);
                //restaurant.ImageFile.SaveAs(fileName);

                //restaurant.ImageFile.SaveAs(Server.MapPath("~/Images/") + ".jpg");

                //This code sourced from: http://stackoverflow.com/questions/16255882/uploading-displaying-images-in-mvc-4
                if (file != null)
                {
                    file.SaveAs(HttpContext.Server.MapPath("~/Images/")
                                + file.FileName);
                    restaurant.ImagePath = file.FileName;
                }

                restaurant.Date     = DateTime.Today;     //Setting the Restaurant's date property to today's date.
                restaurant.UserName = User.Identity.Name; //This allows me to match the Restaurant's UserName property with the UserName of the currently logged in user.
                db.Restaurants.Add(restaurant);
                db.SaveChanges();

                //restaurant = repo.Create(restaurant);//EXTRA

                TempData["Message"] = "Your entry was successfully added"; //This TempData will survive to the next request but not after that (i.e. if we refresh the page again, the message will disappear).
                return(RedirectToAction("DisplayList"));                   //We want to redirect the user here rather than simply return a View so the latest request in the system is a Get Request and not a Post request to the Create method, which otherwise would have been there (The latest entry in the browser's history would be a post request. Therefore, refeshing the page wpuld cause the post request to be sent to the server again).
            }
            else
            {
                return(View(restaurant));
            }
        }
Example #18
0
        public ActionResult Create(Restaurant restaurant)
        {
            //if (Request.Files["files"] != null)
            //{
            //    byte[] Image;
            //    using (var binaryReader = new BinaryReader(Request.Files["files"].InputStream))
            //    {
            //        Image = binaryReader.ReadBytes(Request.Files["files"].ContentLength);
            //    }
            //    restaurant.Photo = Image;
            //}

            //_db.Restaurants.Add(restaurant);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #19
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (var db = new OdeToFoodDb())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
 public Restaurant Create(Restaurant restaurant)
 {
     db.Restaurants.Add(restaurant);
     db.SaveChanges();
     return(restaurant);
 }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (var db = new OdeToFoodDb())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }