예제 #1
0
        public IActionResult AddNewLocation()
        {
            AddNewLocationViewModel model = new AddNewLocationViewModel();

            GetAllCategories(model);
            return(View());
        }
예제 #2
0
        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);
        }
예제 #3
0
 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));
 }