public static async Task Update(User user) { await using ContraWebDBContext contraDB = new ContraWebDBContext(); user match = contraDB.user.Single(v => v.username == user.Username); match.salt = user.Salt; match.password = user.Password; match.role = UserRole.RoleToDatabaseName(user.Role); match.macs = user.MACs.ToArray(); await contraDB.SaveChangesAsync(); }
public static async Task Delete(User user, string token) { await using ContraWebDBContext contraDB = new ContraWebDBContext(); user_session?match = contraDB.user_session.FirstOrDefault(v => v.username == user.Username && v.token == token); if (match == null) { return; } contraDB.Remove(match); await contraDB.SaveChangesAsync(); }
public static async Task Create(User user, string token) { await using ContraWebDBContext contraDB = new ContraWebDBContext(); user_session dbSession = new user_session { username = user.Username, token = token, created_at = DateTime.Now, refreshed_at = DateTime.Now }; contraDB.Add(dbSession); await contraDB.SaveChangesAsync(); }
public static async Task Refresh(User user, string token) { await using ContraWebDBContext contraDB = new ContraWebDBContext(); user_session?match = contraDB.user_session.SingleOrDefault(v => v.username == user.Username && v.token == token); if (match == null) { return; } match.refreshed_at = DateTime.Now; contraDB.Update(match); await contraDB.SaveChangesAsync(); }