public static List <MvvMUserEnvironment> SetUserEnvironments(List <MvvMUserEnvironment> userEnvironments) { using (var context = new YodaClockDbContext()) { var toReturn = new List <MvvMUserEnvironment>(); var existingUser = context.Users.FirstOrDefault(u => u.Username == userEnvironments[0].Username && u.Token == userEnvironments[0].Token); if (existingUser != null) { context.UserEnvironments.RemoveRange(context.UserEnvironments.Where(upm => upm.UserId == existingUser.Id)); context.SaveChanges(); foreach (var userEnvironment in userEnvironments) { var environment = new UserEnvironment() { Id = userEnvironment.Id, UserId = existingUser.Id, Illumination = userEnvironment.Illumination, Noise = userEnvironment.Noise }; context.UserEnvironments.Add(environment); context.SaveChanges(); userEnvironment.Id = environment.Id; } } return(toReturn); } }
/// <summary> /// Removes a user from the <see cref="Server.ServerUsers"/> of current users /// </summary> /// <param name="server">Server for user connection</param> /// <param name="userEnvironment">The user to add</param> public static void RemoveConnection(this Server server, UserEnvironment userEnvironment) { if (userEnvironment == null) { return; } server.ServerUsers.Remove(userEnvironment); }
private static void SetEnvironment(MvvMLoginRegister loginRegister, YodaClockDbContext context, User existingUser) { var environment = new UserEnvironment() { UserId = existingUser.Id, Illumination = loginRegister.Precondition.Illumination, Noise = loginRegister.Precondition.Noise }; context.UserEnvironments.Add(environment); context.SaveChanges(); }
public static UserEnvironment GetUserEnvironment(Request request) { using (var context = new YodaClockDbContext()) { var toReturn = new UserEnvironment(); var existingUser = context.Users.FirstOrDefault(u => u.Username == request.Username && u.Token == request.Token); if (existingUser != null) { toReturn = context.UserEnvironments.FirstOrDefault(e => e.UserId == existingUser.Id); } return(toReturn); } }
/// <summary> /// Adds a new user to the list of <see cref="Server.ServerUsers"/> /// connected to the server /// </summary> /// <param name="server">Server for user connection</param> /// <param name="userEnvironment">The user to add</param> public static void AddConnection(this Server server, UserEnvironment userEnvironment) { server.ServerUsers.Add(userEnvironment); }