public ActionResult Create(Restaurant restaurant, HttpPostedFileBase fileArticle, HttpPostedFileBase RestaurantImage)
 {
     if (ModelState.IsValid)
     {
         if (fileArticle != null)
         {
             string fileName = checkfile(fileArticle.FileName);
             string filePath = Path.Combine(Server.MapPath("~/Images/restaurant"), Path.GetFileName(fileName));
             fileArticle.SaveAs(filePath);
             restaurant.RestaurantLogo = fileName;
         }
         if (RestaurantImage != null)
         {
             string fileName = checkfile(RestaurantImage.FileName);
             string filePath = Path.Combine(Server.MapPath("~/Images/restaurant"), Path.GetFileName(fileName));
             RestaurantImage.SaveAs(filePath);
             restaurant.RestaurantImageInDetailPage = fileName;
         }
         db.Restaurants.Add(restaurant);
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.LocationId = new SelectList(db.Locations, "LocationId", "LocationName");
     return View(restaurant);
 }
Beispiel #2
0
 public ActionResult Index(Restaurant restaurant, string ReturnUrl = "")
 {
     var user = db.Restaurants.Where(au => au.Email == restaurant.Email && au.Password == restaurant.Password).SingleOrDefault();
         if (user == null)
         {
             ModelState.AddModelError("", "Login data is incorrect");
             return View(user);
         }
         FormsAuthentication.SetAuthCookie(user.Email, false);
         Session["RestaurantUser"] = user;
         var sesId = user.RestaurantId;
         //Session["RestaurantUserId"] = user.Email;
         //return Redirect(ReturnUrl);
         if (Url.IsLocalUrl(ReturnUrl))
             return Redirect(ReturnUrl);
         else
             return RedirectToAction( "Details", "admin/Restaurant", new { id=((Restaurant)Session["RestaurantUser"]).RestaurantId });
 }
        public ActionResult Index(Restaurant restaurant, string ReturnUrl = "")
        {
            var resuser = db.Restaurants.Where(au => au.Username == restaurant.Username && au.Password == restaurant.Password).SingleOrDefault();
            if (resuser == null)
            {
                ModelState.AddModelError("", "Login data is incorrect");
                return View(restaurant);
            }
            //FormsAuthentication.SetAuthCookie(user.UserName, false);

              //  Restaurant restaurant=db.Restaurants.Find(resuser.RestaurantId);
            Session["RestaurantUser"] = restaurant;
            //return Redirect(ReturnUrl);
            if (Url.IsLocalUrl(ReturnUrl))
                return Redirect(ReturnUrl);
            else
                if (resuser.RestaurantId == null)
                    return RedirectToAction("Index", "Home");
                return RedirectToAction("Dashboard");
        }
        public ActionResult FoodItemSearch(int? page, string txtCuisines = "", string RestLocation = "", string SortBy = "", string txtRestaurantName="")
        {
            ViewBag.Bread = "Food";
             string Keyword = txtCuisines;
            string Location = RestLocation;
            if (Keyword != "")
                ViewBag.Keyword = Keyword;
            else
                ViewBag.Keyword = "";
            if (Location != "")
                ViewBag.RestLocation = new SelectList(db.Locations, "LocationId", "LocationName", Location);
            else
                ViewBag.RestLocation = new SelectList(db.Locations, "LocationId", "LocationName", string.Empty);
            if (SortBy != "")
                ViewBag.SortBy = SortBy;
            else
                ViewBag.SortBy = "";
            if (txtRestaurantName != "")
                ViewBag.Restaurant = txtRestaurantName;
            else
                ViewBag.Restaurant = String.Empty;
            int pageSize = 5;
            int pageNumber = (page ?? 1);
            List<FoodItem> food = db.FoodItems.ToList();
            List<Restaurant> restaurant = new List<Restaurant>();
            if (Keyword != "" && Location != "")
            {
                string KeyWord = Keyword;
                int LocationId = Convert.ToInt32(Location);
                food = food.Where(a => a.FoodItemName.ToUpper().Contains(KeyWord.ToUpper()) || a.Restaurant.RestaurantName.ToUpper().Contains(KeyWord.ToUpper()) || a.Restaurant.LocationId == LocationId || a.FoodCategory.FoodCategoryName.ToUpper().Contains(KeyWord.ToUpper())).ToList();
                Restaurant r = new Restaurant();
                foreach (var f in food)
                {
                    r = db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId);

                    if (!restaurant.Contains(r))
                        restaurant.Add(db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId));
                }
                //restaurant = restaurant.Where(a =>a.RestaurantName.ToUpper().Contains(KeyWord.ToUpper())).ToList();

            }
            if (Keyword != "" && Location == "")
            {
                string KeyWord = Keyword;
                //int LocationId = Convert.ToInt32(Search["Location"].ToString());
                food = food.Where(a => a.FoodItemName.ToUpper().Contains(KeyWord.ToUpper()) || a.Restaurant.RestaurantName.ToUpper().Contains(KeyWord.ToUpper()) || a.FoodCategory.FoodCategoryName.ToUpper().Contains(KeyWord.ToUpper())).ToList();
                Restaurant r = new Restaurant();
                foreach (var f in food)
                {
                    r = db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId);

                    if (!restaurant.Contains(r))
                        restaurant.Add(db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId));
                }
                List<Restaurant> restaurant1 = db.Restaurants.Where(a => a.RestaurantName.ToUpper().Contains(KeyWord.ToUpper())).ToList();
                foreach (var a in restaurant1)
                {
                    if (!restaurant.Contains(a))
                        restaurant.Add(a);
                }
            }
            if (Keyword == "" && Location != "")
            {
                restaurant = db.Restaurants.ToList();
                int LocationId = Convert.ToInt32(Location);
                restaurant = restaurant.Where(l => l.LocationId == LocationId).ToList();
            }
            if (Keyword == "" && Location == "")
            {
                restaurant = db.Restaurants.ToList();

            }

            ViewBag.RestaurantSelected = "Checked";
            ViewBag.FoodItemsSelected = "";

            if (Keyword != "")
                ViewBag.Keyword = Keyword;
            else
                ViewBag.Keyword = "";
            if (Location != "")
                ViewBag.LocationSelectedId = Location;
            else
                ViewBag.LocationSelectedId = String.Empty;
            ViewBag.Location = new SelectList(db.Locations, "LocationId", "LocationName");
               return View(restaurant.ToPagedList(pageNumber, pageSize));
        }
        public ActionResult Index(int? page, string txtKeyword = "", string Location = "", string SortBy = "", string txtQuickRestaurantName="")
        {
            bool filterCheckStatus = false;
            string Keyword = txtKeyword;
            string Locations = Location;
            string SortBys = SortBy;
            string RestaurantName = txtQuickRestaurantName;

            ViewBag.Bread = "Restaurant";
            int pageSize = 100;
            int pageNumber = (page ?? 1);
            List<FoodItem> food = db.FoodItems.ToList();
            List<Restaurant> restaurant = new List<Restaurant>();

            if (Keyword == "" && Locations == "" && SortBys == "-- Select Sort By --" && RestaurantName == "")
            {
                restaurant = db.Restaurants.ToList();
                filterCheckStatus = true;
            }
            else
            {
                if (Keyword != "")
                {
                    filterCheckStatus = true;
                    food = food.Where(a => a.FoodItemName.ToUpper().Contains(Keyword.ToUpper())).ToList();
                    foreach (var f in food)
                    {
                        Restaurant r = new Restaurant();
                        r = db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId);

                        if (!restaurant.Contains(r))
                            restaurant.Add(db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId));
                    }
                    //restaurant = restaurant.Where(a => a.CusineInfo.ToLower().Contains(Keyword.ToLower())).ToList();
                }
                if (Locations != "")
                {
                    int loc = Convert.ToInt32(Location);
                    if (filterCheckStatus == false)
                    {
                        restaurant = db.Restaurants.ToList();
                        filterCheckStatus = true;
                    }

                    restaurant = restaurant.Where(a => a.LocationId == loc).ToList();
                }

                if (SortBys != "-- Select Sort By --")
                {
                    if (filterCheckStatus == false)
                    {
                        restaurant = db.Restaurants.ToList();
                        filterCheckStatus = true;
                    }
                    if (restaurant.Count > 0)
                    {
                        if (SortBys == "Restaurant Name")
                            restaurant = restaurant.OrderBy(a => a.RestaurantName).ToList();
                        else if (SortBys == "Minimum Order Amount")
                            restaurant = restaurant.OrderBy(a => a.MinOrderAmount).ToList();
                    }
                }

                if (RestaurantName != "")
                {
                    if (filterCheckStatus == false)
                    {
                        restaurant = db.Restaurants.ToList();
                        filterCheckStatus = true;
                    }
                    if (restaurant.Count > 0)
                    {
                        restaurant = restaurant.Where(a => a.RestaurantName.ToUpper().Contains(RestaurantName.ToUpper())).ToList();
                    }
                }
            }

            if (Keyword != "")
                ViewBag.Keyword = Keyword;
            else
                ViewBag.Keyword = "";

            if (Locations != "")
                ViewBag.Location = Locations;
            else
                ViewBag.Location = String.Empty;

            if (RestaurantName != "")
                ViewBag.QuickRestaurantName = RestaurantName;
            else
                ViewBag.QuickRestaurantName = String.Empty;

            if (SortBys != "")
                ViewBag.SortBy = SortBys;
            else
                ViewBag.SortBy = "-- Select Sort By --";

            ViewBag.Location = new SelectList(db.Locations, "LocationId", "LocationName", ViewBag.Location);
            return View(restaurant.ToPagedList(pageNumber, pageSize));
        }
        public ActionResult Index(int? page, string txtKeyWord = "", string Location = "")
        {
            string Keyword = txtKeyWord;

            if (Keyword != "")
                ViewBag.Keyword = Keyword;
            else
                ViewBag.Keyword = String.Empty;

            ViewBag.Bread = "Restaurant";

            int pageSize = 100;
            int pageNumber = (page ?? 1);
            List<FoodItem> food = db.FoodItems.ToList();
            List<Restaurant> restaurant = new List<Restaurant>();

            if (Keyword != "")
            {
                food = food.Where(a => a.FoodItemName.ToUpper().Contains(Keyword.ToUpper())).ToList();
                foreach (var f in food)
                {
                    Restaurant r = new Restaurant();
                    r = db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId);

                    if (!restaurant.Contains(r))
                        restaurant.Add(db.Restaurants.Single(a => a.RestaurantId == f.RestaurantId));
                }
            }

            if (Location != "")
            {
                int loc = Convert.ToInt32(Location);
                restaurant = restaurant.Where(a => a.LocationId==loc).ToList();
            }

            if (Keyword == "" && Location == "")
            {
                restaurant = db.Restaurants.ToList();
            }

               // ViewBag.Location = new SelectList(db.Locations, "LocationId", "LocationName");

            ViewBag.Location = new SelectList(db.Locations, "LocationId", "LocationName", ViewBag.Location);
            return View(restaurant.ToPagedList(pageNumber, pageSize));
        }