// GET: Directors/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } var director = await _DB.Directors .Include(i => i.Movies) .FirstOrDefaultAsync(m => m.id == id); if (director == null) { return(NotFound()); } var movies = await _DB.Movies.Where(i => !i.DirectorID.HasValue).ToArrayAsync(); var model = new DirectorVM { Director = director, DirectorID = director.id, }; model.Movies = new SelectList( movies.Select(i => new SelectListItem { Text = i.Title, Value = i.id.ToString(), }), "Value", "Text"); return(View(model)); }
public async Task <IActionResult> AddNew() { var users = _userManager.Users.ToList(); var model = new DirectorVM(); var list = new List <Empl>(); foreach (var item in users) { bool isDirector = await _userManager.IsInRoleAsync(item, Roles.director.ToString()); //bool isOwner = await _userManager.IsInRoleAsync(item, Roles.director.ToString()); if (isDirector) { model.Name = item.UserName; model.Id = item.Id; } else { list.Add(new Empl { Name = item.UserName, Id = item.Id }); } } model.Employees = list; return(View(model)); }
public async Task <IActionResult> DeleteCurrent(DirectorVM director) { User user = await _userManager.FindByIdAsync(director.Id); await _userManager.RemoveFromRoleAsync(user, Roles.director); await _userManager.AddToRoleAsync(user, Roles.employee); return(RedirectToAction("AddNew")); }
public async Task <IActionResult> AddMovie(DirectorVM model) { if (model.MovieID.HasValue) { var movie = await _DB.Movies.FindAsync(model.MovieID); movie.DirectorID = model.DirectorID; _DB.Movies.Update(movie); await _DB.SaveChangesAsync(); } return(RedirectToAction(nameof(Details), new { id = model.DirectorID })); }
public async Task <IActionResult> DeleteCurrent() { var users = _userManager.Users.ToList(); var currentDirector = new DirectorVM(); foreach (var item in users) { bool isDirector = await _userManager.IsInRoleAsync(item, Roles.director.ToString()); if (isDirector) { currentDirector.Name = item.UserName; currentDirector.Id = item.Id; } } return(View(currentDirector)); }