Exemplo n.º 1
0
        public User(int userId)
        {
            using (Entity db = new Entity())
            {
                byte languageId = IidCulture.CurrentLanguageId;

                t_user user = db.t_user.Find(userId);

                if (user == null)
                {
                    throw new ArgumentException("Invalid userId: " + UserId);
                }

                v_user[] roles = db.v_user.Where(e => e.user_id == user.user_id).ToArray();

                v_site site = null;
                if (user.site_id.HasValue)
                {
                    site = db.v_site.Find(user.site_id.Value);
                }

                UserId           = user.user_id;
                OrganizationId   = user.organization_id;
                Email            = user.email;
                UserStatusId     = user.user_status_id;
                SiteId           = user.site_id;
                SiteName         = site?.get_name_translated(languageId);
                FirstName        = user.first_name;
                LastName         = user.last_name;
                FullName         = user.first_name + " " + user.last_name + " (" + user.email + ")";
                Phone            = user.phone;
                Title            = user.title;
                LastLogin        = user.last_login_activity;
                CreatedByUserId  = user.createdby_userid;
                CreatedDate      = user.created_date;
                UpdatedDate      = user.updated_date;
                UpdatedByUserId  = user.updatedby_userid;
                UserRoleFieldIds = roles.Select(e => e.user_role_fieldid).ToArray();
                UserRoleValues   = roles.Select(e => e.user_role_fieldid_value).ToArray();
                Active           = user.active;

                var userAccess = db.v_user_access.Where(e => e.user_id == userId);
                AssignedActivities = userAccess.Where(e => e.access_level_type == "Activity").OrderBy(e => e.activity_name).ToArray();
                AssignedCountries  = userAccess.Where(e => e.access_level_type == "Country").OrderBy(e => e.country).ToArray();
                AssignedRegions    = userAccess.Where(e => e.access_level_type == "Regional").OrderBy(e => e.access_level_name).ToArray();
                AssignedSites      = userAccess.Where(e => e.access_level_type == "Site").OrderBy(e => e.site_name).ToArray();

                // Get all active sites. If the user is assigned to an inactive site, include it, too!
                int inactiveSiteId = (site != null && site.active == false) ? site.site_id : 0;
                Expression <Func <v_site, bool> > predicate = e => e.active == true || e.site_id == inactiveSiteId;
                AllSites = SelectLists.GetSites(predicate, true);
            }
        }
Exemplo n.º 2
0
 public User()
 {
     AllSites = SelectLists.GetSites(e => e.active == true, true);
 }