public User GetByToken(string token) { using (var context = new SsoModel()) { return context.SsoUsers.SingleOrDefault(u => u.Token == token); } }
public Admin Get(string key) { using (var context = new SsoModel()) { return context.SsoAdmins.SingleOrDefault(u => u.AuthKey == key); } }
public User GetByName(Guid ssoId, string name) { using (var context = new SsoModel()) { return context.SsoUsers.SingleOrDefault(u => u.Name == name && u.SsoId == ssoId); } }
public User Get(Guid ssoId, string key) { using (var context = new SsoModel()) { return context.SsoUsers.SingleOrDefault(u => u.AuthKey == key && u.SsoId == ssoId); } }
public string GetSettings(Guid userId, Guid appId) { using (var context = new SsoModel()) { var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId); return store?.Settings; } }
public void Update(string key, Action<Admin> update) { using (var context = new SsoModel()) { var admin = context.SsoAdmins.SingleOrDefault(u => u.AuthKey == key); if (admin == null) throw ExceptionHelper.UserNotFound(); update(admin); context.SaveChanges(); } }
public void Add(Admin admin) { using (var context = new SsoModel()) { var curentUser = context.SsoUsers.SingleOrDefault(u => u.Name.ToLower() == admin.Name.ToLower()); if (curentUser != null) throw ExceptionHelper.Conflict("User is already exist"); context.SsoAdmins.Add((SsoAdmin) admin); context.SaveChanges(); } }
public void UpdateByToken(string token, Action<User> update) { using (var context = new SsoModel()) { var user = context.SsoUsers.SingleOrDefault(u => u.Token == token); if (user == null) throw ExceptionHelper.UserNotFound(); update(user); context.SaveChanges(); } }
public void Update(Guid ssoId, string key, Action<User> update) { using (var context = new SsoModel()) { var user = context.SsoUsers.SingleOrDefault(u => u.AuthKey == key && u.SsoId == ssoId); if (user == null) throw ExceptionHelper.UserNotFound(); update(user); context.SaveChanges(); } }
public void Delete(Guid userId, Guid appId) { using (var context = new SsoModel()) { var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId); if (store != null) { context.SsoStores.Remove(store); context.SaveChanges(); } } }
public void Add(User user) { using (var context = new SsoModel()) { var curentUser = context.SsoUsers.SingleOrDefault( u => u.Name.ToLower() == user.Name.ToLower() && u.SsoId == user.SsoId); if (curentUser != null) throw ExceptionHelper.Conflict("User is already exist"); context.SsoUsers.Add((SsoUser) user); context.SaveChanges(); } }
public Store GetStore(Guid userId, Guid appId) { using (var context = new SsoModel()) { var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId); var storeValue = store != null ? store.Store : string.Empty; return new Store { Hash = storeValue.GetSHA1(), Value = storeValue }; } }
public void Add(Guid userId, Guid appId, string store, string settings) { using (var context = new SsoModel()) { context.SsoStores.Add(new SsoStore { UserId = userId, AppId = appId, Store = store, Settings = settings }); context.SaveChanges(); } }
public void Add(Guid userId, Guid appId, DateTime time, int type, string message) { using (var context = new SsoModel()) { context.SsoLogs.Add(new SsoLog { UserId = userId, AppId = appId, Time = time, Type = type, Message = message }); context.SaveChanges(); } }
public void UpdateSettings(Guid userId, Guid appId, string settings) { using (var context = new SsoModel()) { var store = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId); if (store != null) { store.Settings = settings; } else { context.SsoStores.Add(new SsoStore { AppId = appId, UserId = userId, Settings = settings }); } context.SaveChanges(); } }
public string UpdateStore(Guid userId, Guid appId, Diff diff) { using (var context = new SsoModel()) { var currentStore = context.SsoStores.SingleOrDefault(s => s.UserId == userId && s.AppId == appId); if (currentStore != null) { if (currentStore.Store.GetSHA1() != diff.Hash) throw ExceptionHelper.Conflict("hash is not relevant"); var store = string.Concat( currentStore.Store.Substring(0, diff.Start), diff.Value, currentStore.Store.Substring(currentStore.Store.Length - diff.End, diff.End)); currentStore.Store = store; context.SaveChanges(); return store.GetSHA1(); } context.SsoStores.Add(new SsoStore { AppId = appId, UserId = userId, Store = diff.Value }); context.SaveChanges(); return diff.Value.GetSHA1(); } }