Exemple #1
0
 public EntityManager(SPDataAccess spDataAccess, KPUser kpUser)
 {
     this.spDataAccess = spDataAccess;
     // diagnostics timer
     this.timer = this.spDataAccess.Timer;
     this.User  = kpUser;
 }
        /// <summary>
        /// Get all items and populate Teams property
        /// This method does not create the hierarchy.
        /// Call GetTeamHierarchy to create the tree
        /// </summary>
        /// <returns></returns>
        public List <T> GetAllItems(KPUser kpUser)
        {
            List <T> items = new List <T>();

            // get the rest of the items from the user's additional teams list
            foreach (Team team in kpUser.Teams)
            {
                items.AddRange(this.GetAllItemsByTeam(team.ID));
            }
            return(items);
        }
        /// <summary>
        /// Get the SPUser by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        internal KPUser GetUserById(int id)
        {
            SPWeb  web    = this.GetCommonWeb();
            SPUser user   = web.AllUsers.GetByID(id);
            KPUser kpUser = new KPUser();

            kpUser.Email = user.Email;
            kpUser.Alias = user.LoginName;

            return(kpUser);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="kpUser"></param>
        /// <returns></returns>
        public List <T> GetAllFiles(KPUser kpUser)
        {
            List <T> items = new List <T>();

            // initialize object list
            if (!this.isInitialized)
            {
                // get the rest of the items from the user's additional teams list
                foreach (Team team in kpUser.Teams)
                {
                    items.AddRange(this.GetAllFilesByTeam(team.ID));
                }
                // here for caching - NOT IMPLEMENTED
                this.isInitialized = true;
            }
            return(items);
        }
Exemple #5
0
 /// <summary>
 /// Gets the user account information including
 /// the info from KPConfigList and KPAdmins
 /// TODO: should consider collapsing these lists
 /// into a single account list that includes access control
 /// </summary>
 /// <returns></returns>
 public void GetCurrentUserAccount(KPUser kpUser)
 {
     this.Init();
     // fetch config list to get list of teams
     //if (userCache.ContainsKey(kpUser.Alias) && cacheTimestamp.AddMinutes(30) < new DateTime())
     if (userCache.ContainsKey(kpUser.Alias))
     {
         kpUser = userCache[kpUser.Alias];
     }
     else
     {
         ConfigList     config         = this.Items.Find(c => c.KPUserName == kpUser.Alias);
         TeamRepository teamRepository = new TeamRepository(this.dataAccess);
         List <Team>    teams          = teamRepository.GetAllItems();
         kpUser.PrimaryTeam = teams.Find(t => t.KPID == config.PrimaryTeam);
         kpUser.Teams       = teams.FindAll(t => config.AdditionalTeams.Contains(t.KPID));
     }
 }
Exemple #6
0
        /// <summary>
        /// User object is embedded in the field value as SPUserField object
        /// </summary>
        /// <param name="item"></param>
        /// <param name="field"></param>
        /// <returns></returns>
        private string GetSPUser(SPListItem item, SPField field)
        {
            string alias = string.Empty;
            // get the FieldUser object
            SPFieldUser fieldUser = item.Fields[field.Title] as SPFieldUser;

            // get the FieldUserValue object
            if (item[field.Title] != null)
            {
                SPFieldUserValue spUserValue = fieldUser.GetFieldValue(item[field.Title].ToString()) as SPFieldUserValue;
                // split out the name if we have one
                string[] name = (!string.IsNullOrEmpty(spUserValue.User.Name)) ? spUserValue.User.Name.Split(GlobalConstants.COMMA_DELIMITER) : new string[] { string.Empty, string.Empty };

                // sometimes Share Point User does not have full name
                string firstName = string.Empty;
                string lastName  = string.Empty;
                if (name.Length == 1)
                {
                    firstName = name[0].Trim();
                    lastName  = name[0].Trim();
                }
                else
                {
                    firstName = name[1].Trim();
                    lastName  = name[0].Trim();
                }

                // create a new KPUser object - consider using this?
                KPUser kpUser = new KPUser()
                {
                    ID        = spUserValue.User.ID,
                    Alias     = spUserValue.User.LoginName,
                    FirstName = firstName,
                    LastName  = lastName,
                    Email     = spUserValue.User.Email
                };
                // returning only the name and alias pipe (|) delimited for now
                alias = string.Format("{0}|{1}", spUserValue.User.Name, kpUser.Alias.Split('\\')[1]);
            }
            return(alias);
        }