示例#1
0
 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();
     }
 }
示例#2
0
 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();
     }
 }
示例#3
0
 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();
     }
 }
示例#4
0
 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();
     }
 }
示例#5
0
 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();
         }
     }
 }
示例#6
0
 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();
     }
 }
示例#7
0
 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();
     }
 }
示例#8
0
 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();
     }
 }
示例#9
0
        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();
            }
        }
示例#10
0
        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();
            }
        }