private async Task <string> GetUser(Yaaf.Xmpp.JabberId value) { using (var context = contextCreator()) { var username = value.Localpart.Value; var um = new UserManager <ApplicationUser> ( new UserStore <ApplicationUser> (context)); var user = await um.FindByNameAsync(username); if (user == null) { // create user user = new ApplicationUser() { UserName = username }; var res = await um.CreateAsync(user); if (!res.Succeeded) { throw new Exception(string.Format("Error while creating new user: {0}", string.Join(", ", res.Errors))); } await context.MySaveChanges(); if (string.IsNullOrEmpty(user.Id)) { Console.Error.WriteLine("User Entity was not refreshed, Please remove me!"); user = await um.FindByNameAsync(username); } } if (string.IsNullOrEmpty(user.Id)) { throw new Exception(string.Format("Could not find or create user: {0}", username)); } context.Entry(user).State = System.Data.Entity.EntityState.Detached; return(user.Id); } }
public async Task <Server.IUserRoster> GetRoster(Yaaf.Xmpp.JabberId value) { return(new SqlUserStore(contextCreator, await GetUser(value))); }
public bool ExistsUser(Yaaf.Xmpp.JabberId value) { return(GetUser(value) != null); }