public async Task <ActionResult> EmployerRegister([System.Web.Http.FromBody] EmployerRegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var appDataPath = Server.MapPath("~/App_Data/employer_logo"); var logoSystemName = Guid.NewGuid().ToString() + ".dat"; model.CompanyLogo.SaveAs(appDataPath + "/" + logoSystemName); db.Employers.Add(new Employer { ApplicationUserId = user.Id, CompanyDescription = model.CompanyDescription, Name = model.CompanyName, CompanyLogoFileName = Path.GetFileName(model.CompanyLogo.FileName), CompanyLogoSystemFileName = logoSystemName, CountryId = model.CountryId, AddressLatitude = model.AddressLatitude, AddressLongitude = model.AddressLongitude, AddressState = model.AddressState, AddressStreet = model.AddressStreet, AddressTown = model.AddressTown, AddressPostalCode = model.AddressPostalCode, EmployerTypeId = model.EmployerTypeId }); await db.SaveChangesAsync(); IdentityService.AddUserToRole(user.Id, "Employer", db); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home", new { acct_created = 1 })); } AddErrors(result); } // If we got this far, something failed, redisplay form model.Industries = new SelectList(db.Industries.Include(x => x.Category), "Id", "Name", "Category.Name", null, null); model.EmployerTypes = db.EmployerTypes.ToList(); model.Countries = db.Countries.ToList(); return(View(model)); }
//Edit User //update af de ting der skal være til brugeren //Update User Roles public bool UpdateUserRole(string userid, string rolename, bool add = true) { //toggle user on/off if (add) { _identityService.AddUserToRole(userid, rolename); } else { _identityService.RemoveUserFromRole(userid, rolename); } return(true); }