public async Task <IActionResult> AdminRegister(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.UserName, Email = model.Email, UserType = model.UserType
                };
                var result = await _userManager.CreateAsync(user, model.Password);


                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);


                    await _userManager.AddToRoleAsync(user, "Admin");

                    User_Profile_Controller user_Profile_Controller = new User_Profile_Controller
                    {
                        Id = user.Id,
                        Profile_Activated = "0",
                        Account_Activated = "1",
                        User_Role         = user.UserType
                    };
                    _db.User_Profile_Controller.Add(user_Profile_Controller);

                    Admin_Profile admin_Profile = new Admin_Profile
                    {
                        Id        = user.Id,
                        CreatedBy = _db.Admin_Profile.Find(_userManager.GetUserId(User)).FirstName,
                        Email     = ""
                    };
                    _db.Admin_Profile.Add(admin_Profile);
                    _db.SaveChanges();

                    return(RedirectToAction("Index", "Admin"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View("~/Views/Home/Register.cshtml", model));
            // return View(model);
        }
Beispiel #2
0
        public IActionResult CreateProfile(Admin_Profile admin)
        {
            var check = _db.Admin_Profile.Find(_userManager.GetUserId(User));

            if (_signInManager.IsSignedIn(User))
            {
                if (check != null)
                {
                    //admin.Id = _userManager.GetUserId(User);
                    //admin.CreatedBy = "";
                    //_db.SaveChanges();

                    //Search for an existing profile and update it
                    var search  = _db.User_Profile_Controller.Find(_userManager.GetUserId(User));
                    var search1 = _db.Admin_Profile.Find(_userManager.GetUserId(User));
                    if (search != null && search1 != null)
                    {
                        search.Profile_Activated = "1"; //Profile Activated codes 1(Fully Activated) 2(Pending to be Activated by Admin) 0(Disactivated)
                        search.Account_Activated = "1"; //Account_Activated codes 1(Fully Activated) 0(Disactivated)
                        search1.Email            = admin.Email;
                        search1.FirstName        = admin.FirstName;
                        search1.LastName         = admin.LastName;
                        search1.OtherNames       = admin.OtherNames;
                        search1.PhoneNumber      = admin.PhoneNumber;
                        search1.TItle            = admin.TItle;
                        _db.SaveChanges();
                    }
                    return(RedirectToAction("Index", "Admin"));
                }
            }
            else
            {
                return(RedirectToAction("Index", "Admin"));
            }
            return(View());
        }