public async Task <IActionResult> Edit(int id, [Bind("RoleByUserId,RoleId,UserId")] RoleByUser roleByUser) { if (id != roleByUser.RoleByUserId) { return(NotFound()); } if (ModelState.IsValid) { try { await _roleByUserRepository.Update(roleByUser); } catch (DbUpdateConcurrencyException) { if (!RoleByUserExists(roleByUser.RoleByUserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(await _roleRepository.GetAll(), "RoleId", "Name", roleByUser.RoleId); ViewData["UserId"] = new SelectList(await _userRepository.GetAll(), "UserId", "Name", roleByUser.UserId); return(View(roleByUser)); }
public async Task <RoleByUser> Create(RoleByUser model) { _context.Add(model); await _context.SaveChangesAsync(); return(model); }
public async Task <IActionResult> Create([Bind("RoleByUserId,RoleId,UserId")] RoleByUser roleByUser) { if (ModelState.IsValid) { await _roleByUserRepository.Create(roleByUser); return(RedirectToAction(nameof(Index))); } ViewData["RoleId"] = new SelectList(await _roleRepository.GetAll(), "RoleId", "Name", roleByUser.RoleId); ViewData["UserId"] = new SelectList(await _userRepository.GetAll(), "UserId", "Name", roleByUser.UserId); return(View(roleByUser)); }
public async Task Update(RoleByUser model) { _context.Update(model); await _context.SaveChangesAsync(); }