예제 #1
0
        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));
        }
예제 #2
0
        public async Task <RoleByUser> Create(RoleByUser model)
        {
            _context.Add(model);
            await _context.SaveChangesAsync();

            return(model);
        }
예제 #3
0
        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));
        }
예제 #4
0
 public async Task Update(RoleByUser model)
 {
     _context.Update(model);
     await _context.SaveChangesAsync();
 }