Exemplo n.º 1
0
        private readonly Model.UserContext _context;         //private property use underscore
        public UserController(Model.UserContext context)
        {
            _context = context;

            if (_context.User.Count() == 0)
            {
                User a = new User();
                a.Name         = "Kenley";
                a.UserName     = "******";
                a.Password     = "******";
                a.Park         = "Disneyland";
                a.Gender       = "Female";
                a.Age          = 23;
                a.City         = "San Clemente";
                a.MobileNumber = "3334445555";
                a.Email        = "*****@*****.**";
                _context.User.Add(a);
                _context.SaveChanges();

                User b = new User();
                b.Name         = "Tyler";
                b.UserName     = "******";
                b.Password     = "******";
                b.Park         = "Universal";
                b.Gender       = "Female";
                b.Age          = 25;
                b.City         = "Charleston";
                b.MobileNumber = "5557776666";
                b.Email        = "*****@*****.**";
                _context.User.Add(b);
                _context.SaveChanges();

                User c = new User();
                c.Name         = "Jerri";
                c.UserName     = "******";
                c.Password     = "******";
                c.Park         = "Disneyland";
                c.Gender       = "Female";
                c.Age          = 25;
                c.City         = "Fountain Valley";
                c.MobileNumber = "1115558888";
                c.Email        = "*****@*****.**";
                _context.User.Add(c);
                _context.SaveChanges();
            }
        }
        public Model.UserContext AuthenticateUser(string userName, string password)
        {
            Model.UserContext newUserContext = null;

            User users = _repository.GetList <User>(u => u.UserName == userName && u.Password == password).FirstOrDefault();

            if (users != null && users.UserID > 0)
            {
                AuthContext context = new AuthContext();
                Client      client  = new Client();
                client = _repository.GetList <Client>(u => u.ClientId == users.ClientId).FirstOrDefault();
                if (client != null)
                {
                    context.Address             = client.Address1;
                    context.ClientID            = client.ClientId;
                    context.ClientName          = client.ClientName;
                    context.Country             = client.CountryId.HasValue ? client.CountryId.Value : 0;
                    context.CustomizationFolder = client.CustomizationFolder;
                    context.Email      = client.Email;
                    context.FirstName  = users.FirstName;
                    context.LastName   = users.LastName;
                    context.MasterPage = client.MasterPage;
                    context.Phone      = client.Phone;
                    context.UserRoleID = users.UserRoleID;
                    context.StateId    = client.StateId;
                    context.Theme      = client.Theme;
                    context.UserID     = users.UserID;
                    context.UserName   = users.UserName;
                    context.Culture    = client.Culture;
                    context.TimeZone   = client.TimeZone;
                }
                context.FunctionList = _repository.DataContext.tblRoleFunctionMapping.Where(u => u.UserRoleID == context.UserRoleID).Select(m => m.FunctionID).ToList();

                newUserContext = new Model.UserContext(context);
            }
            return(newUserContext);
        }