Example #1
0
        private static void InsertUsers(InsuranceCompanyContext context)
        {
            var users = new List <User>()
            {
                new User()
                {
                    UserName = "******",
                    Password = EncryptionUtil.Encode("admin"),
                    Role     = new Role()
                    {
                        Rol = "Admin"
                    }
                },
                new User()
                {
                    UserName = "******",
                    Password = EncryptionUtil.Encode("user"),
                    Role     = new Role()
                    {
                        Rol = "User"
                    }
                }
            };

            context.Users.AddRange(users);
        }
Example #2
0
        public User ValidateUser(string userName, string password)
        {
            User user;

            try
            {
                var encodedPassword = EncryptionUtil.Encode(password);
                user = _context.Users.FirstOrDefault(us => us.UserName == userName && us.Password == encodedPassword);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(InvalidOperationException))
                {
                    return(null);
                }
                throw new HttpResponseException(System.Net.HttpStatusCode.InternalServerError);
            }

            return(user);
        }