public IActionResult DeleteConfirmed(int id)
        {
            UserGroupApplicationUser userGroupApplicationUser = _context.UserGroupApplicationUser.Single(m => m.UserGroupID == id);

            _context.UserGroupApplicationUser.Remove(userGroupApplicationUser);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public IActionResult Edit(UserGroupApplicationUser userGroupApplicationUser)
 {
     if (ModelState.IsValid)
     {
         _context.Update(userGroupApplicationUser);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewData["ApplicationUserID"] = new SelectList(_context.Users, "Id", "ApplicationUser", userGroupApplicationUser.ApplicationUserID);
     ViewData["UserGroupID"]       = new SelectList(_context.UserGroup, "ID", "UserGroup", userGroupApplicationUser.UserGroupID);
     return(View(userGroupApplicationUser));
 }
Пример #3
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email    = model.Email,
                    NickName = model.NickName
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User created a new account with password.");

                    // 建立UserGroup
                    var uGroup = new UserGroup();
                    uGroup.Name = model.NickName;
                    _context.UserGroup.Add(uGroup);
                    _context.SaveChanges();

                    user.RepresentativeGroupID = uGroup.ID;

                    // 建立User & UserGroup對應關係
                    var userGroupAndApplicationUser = new UserGroupApplicationUser();
                    userGroupAndApplicationUser.ApplicationUserID = user.Id;
                    userGroupAndApplicationUser.UserGroupID       = uGroup.ID;
                    _context.UserGroupApplicationUser.Add(userGroupAndApplicationUser);
                    _context.SaveChanges();


                    return(RedirectToAction(nameof(HomeController.Index), "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        // GET: UserGroupApplicationUsers/Details/5
        public IActionResult Details(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            UserGroupApplicationUser userGroupApplicationUser = _context.UserGroupApplicationUser.Single(m => m.UserGroupID == id);

            if (userGroupApplicationUser == null)
            {
                return(HttpNotFound());
            }

            return(View(userGroupApplicationUser));
        }
        // GET: UserGroupApplicationUsers/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }

            UserGroupApplicationUser userGroupApplicationUser = _context.UserGroupApplicationUser.Single(m => m.UserGroupID == id);

            if (userGroupApplicationUser == null)
            {
                return(HttpNotFound());
            }
            ViewData["ApplicationUserID"] = new SelectList(_context.Users, "Id", "ApplicationUser", userGroupApplicationUser.ApplicationUserID);
            ViewData["UserGroupID"]       = new SelectList(_context.UserGroup, "ID", "UserGroup", userGroupApplicationUser.UserGroupID);
            return(View(userGroupApplicationUser));
        }
Пример #6
0
        public IActionResult Create(UserGroup userGroup)
        {
            if (ModelState.IsValid)
            {
                _context.UserGroup.Add(userGroup);
                _context.SaveChanges();

                var userId = User.GetUserId();

                // 建立User & UserGroup對應關係
                var userGroupAndApplicationUser = new UserGroupApplicationUser();
                userGroupAndApplicationUser.ApplicationUserID = userId;
                userGroupAndApplicationUser.UserGroupID       = userGroup.ID;
                _context.UserGroupApplicationUser.Add(userGroupAndApplicationUser);
                _context.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(userGroup));
        }