public ActionResult Index() { var list = new List <RestaurantModelView>(); var restaurantModel = _restaurantRepository.Get(); foreach (var item in restaurantModel) { var modelView = new RestaurantModelView { Id = item.Id, Name = item.Name }; list.Add(modelView); } return(View(list)); }
public ActionResult Edit(int id) { var s = _RestaurantService.GetDetails(id); RestaurantModelView res = new RestaurantModelView(); res.ID = s.ID; res.MaxEstimatedDeliveryTime = s.MaxEstimatedDeliveryTime; res.Meals = s.Meals; res.Mobile = s.Mobile; res.Name = s.Name; res.WorkingFrom = s.WorkingFrom; res.WorkingTo = s.WorkingTo; res.DeliveryFee = s.DeliveryFee; res.HotLine = s.HotLine; return(View(res)); }
public ActionResult Edit(int id, RestaurantModelView Model, IFormFile file) { try { var rest = _RestaurantService.GetDetails(id); rest.ID = Model.ID; rest.MaxEstimatedDeliveryTime = Model.MaxEstimatedDeliveryTime; rest.Meals = Model.Meals; rest.Mobile = Model.Mobile; rest.Name = Model.Name; rest.WorkingFrom = Model.WorkingFrom; rest.WorkingTo = Model.WorkingTo; rest.DeliveryFee = Model.DeliveryFee; rest.HotLine = Model.HotLine; string uniqueFileName = null; if (Model.Logo != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(_appEnvironment.WebRootPath, "images"); // To make sure the file name is unique we are appending a new // GUID value and and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + Model.Logo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder Model.Logo.CopyTo(new FileStream(filePath, FileMode.Create)); } rest.Logo = uniqueFileName; _RestaurantService.Update(id, rest); return(RedirectToAction("Index")); } catch { return(View(Model)); } }
public async Task <ActionResult> AddRestaurant(RestaurantModelView restaurant, IFormFile file) { var stands = context.Areas .Select(s => new { ID = s.ID, areas = string.Format("{0} / {1}", s.CityName, s.SubArea) }) .ToList(); ViewBag.StandID = stands; if (!ModelState.IsValid) { return(View(restaurant)); } Restaurant res = new Restaurant(); res.ID = res.ID; res.MaxEstimatedDeliveryTime = res.MaxEstimatedDeliveryTime; res.Meals = restaurant.Meals; res.Mobile = restaurant.Mobile; res.Name = restaurant.Name; res.WorkingFrom = restaurant.WorkingFrom; res.WorkingTo = restaurant.WorkingTo; res.DeliveryFee = restaurant.DeliveryFee; res.Area = restaurant.Area; res.AreaID = restaurant.AreaID; res.HotLine = restaurant.HotLine; if (!CheckForRest(res)) { ModelState.AddModelError("", "This Restaurant is already Exists in this Area ,Please check again your inputs"); return(View(restaurant)); } try { string uniqueFileName = null; if (restaurant.Logo != null) { // The image must be uploaded to the images folder in wwwroot // To get the path of the wwwroot folder we are using the inject // HostingEnvironment service provided by ASP.NET Core string uploadsFolder = Path.Combine(_appEnvironment.WebRootPath, "images"); // To make sure the file name is unique we are appending a new // GUID value and and an underscore to the file name uniqueFileName = Guid.NewGuid().ToString() + "_" + restaurant.Logo.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); // Use CopyTo() method provided by IFormFile interface to // copy the file to wwwroot/images folder restaurant.Logo.CopyTo(new FileStream(filePath, FileMode.Create)); } res.Logo = uniqueFileName; _RestaurantService.Add(res); return(RedirectToAction("Registration", restaurant)); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View(restaurant)); } }