Пример #1
0
        /// <summary>
        /// Loads years from the birth year
        /// TODO change birth date
        /// </summary>
        public async Task LoadYears()
        {
            //if (AppSession.User != null && !string.IsNullOrEmpty(AppSession.User.BirthDate))
            //{
            //}

            var birthDateTime = new DateTime(1998, 2, 27);

            //if (DateTime.TryParse(AppSession.User.BirthDate, Settings.CultureInfo, DateTimeStyles.None, out DateTime birthDateTime))
            if (birthDateTime != null)
            {
                var currentYear = DateTime.Now.Year;

                if (birthDateTime.Year < currentYear)
                {
                    for (int i = 0; i < (currentYear - birthDateTime.Year) + 1; i++)
                    {
                        Years.Add(new Year()
                        {
                            YearNumber = birthDateTime.Year + i
                        });
                    }

                    Years      = Years.OrderByDescending(x => x.YearNumber).ToList();
                    TargetYear = Years.First();

                    return;
                }
                else if (birthDateTime.Year > currentYear)
                {
                    MessageBox.Show("Birth year bigger than curren year, check your birth date and system date time settings");
                    return;
                }
            }

            // default year = current year
            TargetYear.YearNumber = DateTime.Now.Year;
            Years.Add(TargetYear);
        }