Ejemplo n.º 1
0
        /// <summary>
        /// Check exist this nikname in the users list
        /// </summary>
        /// <param name="nikName">Nikname of the user</param>
        /// <returns></returns>
        private static bool IsExistNikName(string nikName)
        {
            if (_userDataList.Count == 0)
            {
                return false;
            }
            // here I use a lambda expression for the searching the nikname in the user data list
            _user = _userDataList.FirstOrDefault(userData => userData.Nikname == nikName);

            if (String.IsNullOrEmpty(_user.Nikname))
            {
                return false;
            }

            return true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saving the new user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static bool Save(UserData user)
        {
            if (!IsExistNikName(user.Nikname))
            {

                _userDataList.Add(user);

                using (Stream fileStream = File.Create(FileName))
                {
                    var serializer = new XmlSerializer(typeof(List<UserData>));
                    serializer.Serialize(fileStream, _userDataList);
                }

                return true;
            }

            return false;
        }