public async Task <IActionResult> AddEventFaculty(AdminAddFactultyToEventViewModel vm) { if (ModelState.IsValid) { vm.User = await _userManager.FindByIdAsync(vm.UserId); vm.Id = Guid.NewGuid().ToString(); if (vm.User != null) { if (await _repository.AddEventFaculty(Mapper.Map <EventFaculty>(vm))) { if (_repository.SaveAll()) { return(RedirectToAction("EventFaculty", new { id = vm.EventId })); } else { ModelState.AddModelError("", "Could not save to the database"); } } else { ModelState.AddModelError("", "Could not add event faculty"); } } else { ModelState.AddModelError("", "There was a problem getting the user from the database"); } } vm.Event = _repository.GetEvent(vm.EventId); var users = _repository.GetAllUsersNotInEvent(vm.EventId); if (users == null) { return(View(vm)); } ViewBag.userSelect = CreateFacultySelectDropdown(users); ModelState.AddModelError("", "There were no faculty to select for this event"); return(View(vm)); }