예제 #1
0
        /// <summary>
        /// Deletes a profile from the Profiles Dictionary.
        /// </summary>
        /// <param name="profile">Valid profile you want to remove.</param>
        /// <returns>True if profile was removed, False if something went wrong.</returns>
        public static bool DeleteProfile(ProfileModel profile)
        {
            if (_profiles.ContainsKey(profile.Username) && _profiles[profile.Username].Password == profile.Password)
            {
                _profiles.Remove(profile.Username);
                SQLManager.SaveProfiles(_profiles);
                return(true);
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Creates a profile and adds it to the Profiles Dictionary.
        /// </summary>
        /// <param name="profile">Valid profile you want to add.</param>
        /// <returns>True if profile was created, False if something went wrong.</returns>
        public static ProfileModel CreateProfile(ProfileModel profile)
        {
            if (!_profiles.ContainsKey(profile.Username))
            {
                profile.Key = GetRandomKey();
                _profiles.Add(profile.Username, profile);
                SQLManager.SaveProfiles(_profiles);
                return(_profiles[profile.Username]);
            }

            return(null);
        }
예제 #3
0
        /// <summary>
        /// Signs into profile using the Profile Model.
        /// </summary>
        /// <param name="profile">Profile you are signing into.</param>
        /// <returns>Returns the profile.</returns>
        public static ProfileModel SignIntoProfile(ProfileModel profile)
        {
            if (_profiles.ContainsKey(profile.Username) && _profiles[profile.Username].Password == profile.Password)
            {
                if (string.IsNullOrEmpty(_profiles[profile.Username].Key))
                {
                    _profiles[profile.Username].Key = GetRandomKey();
                    SQLManager.SaveProfiles(_profiles);
                }
                return(_profiles[profile.Username]);
            }

            return(null);
        }
예제 #4
0
        /// <summary>
        /// Creates a profile and adds it to the Profiles Dictionary.
        /// </summary>
        /// <param name="username">Profile's unique username.</param>
        /// <param name="password">Password for new profile.</param>
        /// <returns>True if profile was created, False if something went wrong.</returns>
        public static bool CreateProfile(string username, string password)
        {
            if (!_profiles.ContainsKey(username))
            {
                ProfileModel profile = new ProfileModel
                {
                    Username = username,
                    Password = password,
                    Key      = GetRandomKey()
                };

                _profiles.Add(profile.Username, profile);
                SQLManager.SaveProfiles(_profiles);
                return(true);
            }

            return(false);
        }
예제 #5
0
        /// <summary>
        /// Adds a specified profile as a favorite
        /// of another specified profile
        /// </summary>
        /// <param name="baseProfile">The profile name who is receiving a new favorite</param>
        /// <param name="newFavorite">The name of the profile that is being added as a favorite</param>
        /// <returns></returns>
        public static bool AddFavorite(string baseProfile, string newFavorite)
        {
            //Retrieves the specified profiles
            ProfileModel retrievedBase     = _profiles[baseProfile];
            ProfileModel retrievedFavorite = _profiles[newFavorite];

            /**
             * Multiple checks of the following:
             * The two profile names are not the same
             * The retrieved profiles are not null
             * The base profile does not already have the favorite profile
             */
            if (!baseProfile.Equals(newFavorite) && retrievedBase != null && retrievedFavorite != null && !retrievedBase.FavoritesList.Contains(newFavorite))
            {
                retrievedBase.FavoritesList.Add(retrievedFavorite.Username);

                SQLManager.SaveProfiles(_profiles);

                return(true);
            }

            return(false);
        }
예제 #6
0
 /// <summary>
 /// Simple method that saves all current profiles
 /// into the sql database
 /// </summary>
 public static void SaveProfiles()
 {
     SQLManager.SaveProfiles(_profiles);
 }