protected void CreateUser_Click(object sender, EventArgs e) { var company = _companyDal.Get(Company.Text); if (company != null) { ErrorMessage.Text = "Company already exists."; return; } var addedCompany = _companyDal.Create(new Company { CompanyName = Company.Text }); var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>(); var user = new AspNetUser { UserName = Email.Text, Email = Email.Text }; var result = manager.Create(user, Password.Text); if (result.Succeeded) { AddRoleAndCompany(user, addedCompany.CompanyId); signInManager.SignIn(user, false, false); IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response); } else { ErrorMessage.Text = result.Errors.FirstOrDefault(); } }
public IResult Add(Company company) { _companyDal.Create(company); return(new Result(true, Messages.Added)); }