public async Task <IActionResult> Create(LocationsLegendViewModel viewModel, List <int> ViewLocationInput)
        {
            ModelState.Remove("ViewLocation.UserId");
            ModelState.Remove("ViewLocation.User");
            if (ModelState.IsValid)
            {
                var location    = viewModel.ViewLocation;
                var currentUser = await _userManager.GetUserAsync(HttpContext.User);

                viewModel.ViewLocation.User   = currentUser;
                viewModel.ViewLocation.UserId = currentUser.Id;
                _context.Add(location);
                foreach (var id in ViewLocationInput)
                {
                    LegendViewLocation newView = new LegendViewLocation()
                    {
                        ViewLocationId = location.ViewLocationId,
                    };
                }
                await _context.SaveChangesAsync();

                if (_userManager.GetUserAsync(User).Result.IsAdmin)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(RedirectToAction(nameof(LegendsIndex)));
                }
            }
            ViewData["UserId"] = new SelectList(_context.ApplicationUser, "Id", "Id", viewModel.ViewLocation.UserId);
            return(View(viewModel));
        }
示例#2
0
        // GET: Legends/Create
        public IActionResult Create()
        {
            LocationsLegendViewModel location = new LocationsLegendViewModel()
            {
                AvailableLocations = _context.ViewLocation.Include(l => l.User).ToList()
            };



            return(View(location));
        }