/// <summary> /// Converts User object to API_User objeect as well as any associated Lists they own /// </summary> /// <param name="usr"></param> /// <returns></returns> public API_User ConvertToAPI_UserWithAssociatedLists(User usr) { var apiUsr = GetShellUserObject(usr); // If Lists are there - convert them // TODO: This seems like a hack, not sure if there is a better way to handle this though try { if ((usr.Lists != null) && (usr.Lists.Count > 0)) { var apiList = new API_List(); foreach (var l in usr.Lists) { apiUsr.Lists.Add(apiList.ConvertToAPI_ListWithoutItems(l)); } } } catch (ObjectDisposedException) { } return apiUsr; }
/// <summary> /// Creates the shell User object /// </summary> /// <param name="usr"></param> /// <returns></returns> private API_User GetShellUserObject(User usr) { var apiUsr = new API_User { FName = usr.FName, LName = usr.LName, PublicKey = usr.PublicKey, AvatarURL = usr.AvatarURL }; if ((usr.FName == string.Empty) && (usr.LName == string.Empty)) { if (usr.EmailAddresses.Where(e => e.IsDefault == true).Count() != 1) { apiUsr.DisplayName = "Unknown User"; } else { apiUsr.DisplayName = usr.EmailAddresses.SingleOrDefault(e => e.IsDefault == true).EmailAddress1; } } else { apiUsr.DisplayName = string.Format("{0} {1}", usr.FName, usr.LName.Substring(0, 1)); } return apiUsr; }
/// <summary> /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToUsers(User user) { base.AddObject("Users", user); }
/// <summary> /// Converts User object to API_User objeect ignoring any associated Lists they own /// </summary> /// <param name="usr"></param> /// <returns></returns> public API_User ConvertToAPI_UserWithoutAssociatedLists(User usr) { return GetShellUserObject(usr); ; }
/// <summary> /// Create a new User object. /// </summary> /// <param name="userID">Initial value of the UserID property.</param> public static User CreateUser(global::System.Int32 userID) { User user = new User(); user.UserID = userID; return user; }