public async Task <IdentityResult> CreateUserOnlyForAdmins(User userModel) { CorparateRepository corprepo = new CorparateRepository(); IdentityUser user = new IdentityUser { UserName = userModel.UserName, }; //Saving the user to the ASP.NET user tables var result = await _userManager.CreateAsync(user, userModel.Password); //If above was successfull then we will add the user accounts if (result.Succeeded) { //Set the user id to the ASP.net User id userModel.UserId = user.Id; //set User's active = false userModel.Activated = true; //- Create Approval Entry for given Org to visible to Supper User await corprepo.CreateUserOnly(userModel); } return(result); }
/// <summary> /// This will create a buyer and the organisation at the same time. /// </summary> /// <param name="userModel"></param> /// <returns></returns> public async Task <IdentityResult> CreateUserOnly(User userModel) { try { CorparateRepository corprepo = new CorparateRepository(); var path = System.Configuration.ConfigurationManager.AppSettings["ActivationPath"]; IdentityUser user = new IdentityUser { UserName = userModel.UserName, }; //Saving the user to the ASP.NET user tables var result = await _userManager.CreateAsync(user, userModel.Password); //If above was successfull then we will add the user accounts if (result.Succeeded) { //Set the user id to the ASP.net User id userModel.UserId = user.Id; //check orgId is a valied one. bool orgValied = await corprepo.CheckOrganizationExits(userModel.OrganizationID); if (!orgValied) { //IdentityUser useride = new IdentityUser(userModel.UserName); var xres = _userManager.Delete(user); throw new Exception("Invalied Organization"); } //set User's active = false userModel.Activated = false; //Set supperuser false by defualt. becouse system not allowed more than one supper user for organization //This controller create users for existing orgs and 100% certenty that the org has supperuser already userModel.IsSupperUser = false; //- Create Approval Entry for given Org to visible to Supper User await corprepo.CreateUserOnly(userModel); //Send an email await corprepo.SendMail(new EmailVM() { UserId = userModel.UserId, ToAddress = userModel.Email }, path); } else { throw new Exception("User name you have given is already taken from another user.PleaseTry different user name "); } return(result); } catch (Exception ex) { throw ex; } }