コード例 #1
0
        /// <summary>
        /// Сохранить нового пользователя.
        /// </summary>
        public void CreateUser(string userName, string genderName, DateTime birthday, string budgetName)
        {
            if (string.IsNullOrWhiteSpace(genderName))
            {
                throw new ArgumentNullException(nameof(genderName));
            }
            if (string.IsNullOrWhiteSpace(budgetName))
            {
                throw new ArgumentNullException(nameof(budgetName));
            }
            if (birthday.Year < 1900 || birthday > DateTime.Now)
            {
                throw new ArgumentException(nameof(birthday));
            }
            if (Users.Contains(Users.SingleOrDefault(u => u.Name == userName)))
            {
                throw new ArgumentException(nameof(userName));
            }
            UserBudget budget = Budgets.SingleOrDefault(b => b.Name == budgetName);

            if (budget == null)
            {
                budget = new UserBudget(budgetName);
                Budgets.Add(budget);
                SaveBudgets();
            }
            Gender gender = Genders.SingleOrDefault(g => g.Name == genderName);

            if (gender == null)
            {
                gender = new Gender(genderName);
                Genders.Add(gender);
                SaveGenders();
            }

            var user = new User(userName, gender, birthday, budget.Id);

            Users.Add(user);
            SaveUsers();
        }
コード例 #2
0
 /// <summary>
 /// Загрузить пол пользователя из файла.
 /// </summary>
 /// <returns>Пол пользователя приложения.</returns>
 public Gender GetGender(int id)
 {
     return(Genders.SingleOrDefault(g => g.Id == id));
 }