Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        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();
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
 /// <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);
 }