public IActionResult AddNewLocation() { AddNewLocationViewModel model = new AddNewLocationViewModel(); GetAllCategories(model); return(View()); }
private AddNewLocationViewModel GetAllCategories(AddNewLocationViewModel model) { var categories = categoryRepository.GetAll(); foreach (var category in categories) { model.Categories.Add(new SelectListItem { Value = category.Id.ToString(), Text = category.Title }); } return(model); }
public async Task <IActionResult> AddNewLocation(AddNewLocationViewModel model) { if (ModelState.IsValid) { Location location = new Location { Title = model.Title, Number = model.Number, LocationCategoryId = model.CategoryId, AdminId = await GetCurrentLoggedInUserId() }; string location_title = model.Title; locationRepository.Insert(location); locationRepository.Save(); TempData["created"] = $"New Location { location_title } was created successfully."; return(Redirect("alllocations")); } GetAllCategories(model); return(RedirectToAction("alllocations", model)); }