コード例 #1
0
        private void SaveChanges(object sender, RoutedEventArgs e)
        {
            Gender  gender  = (Gender)genderBox.SelectedItem;
            Country country = (Country)countryBox.SelectedItem;

            string filename;

            byte[] imageToDb = { 0 };

            if (photoBox.Text != "")
            {
                filename  = photoBox.Text;
                imageToDb = RegistrationClass.ConvertToByte(filename);
            }

            var runner = db.Runner
                         .Where(r => r.Email == CurrentUser.Email)
                         .FirstOrDefault();
            var user = db.User
                       .Where(u => u.Email == CurrentUser.Email)
                       .FirstOrDefault();

            if (runner == null) //проверка на наличие бегуна в таблице, если нет, то создается новый бегун с присвоением нынешнего email
            {
                Runner r = new Runner();
                r.Email        = CurrentUser.Email;
                user.FirstName = firstNameBox.Text;
                user.LastName  = secondNameBox.Text;
                r.DateOfBirth  = datePicker.SelectedDate;
                r.Gender       = gender.GenderRow;
                r.Photo        = imageToDb;

                foreach (Country c in db.Country)
                {
                    if (c.CountryName == country.CountryName)
                    {
                        r.CountryCode = c.CountryCode;
                        break;
                    }
                }

                db.Runner.Add(r);
                db.SaveChanges();
            }
            else //иначе редактируется имеющийся бегун
            {
                user.FirstName     = firstNameBox.Text;
                user.LastName      = secondNameBox.Text;
                runner.DateOfBirth = datePicker.SelectedDate;
                runner.Gender      = gender.GenderRow;
                runner.Photo       = imageToDb;

                foreach (Country c in db.Country)
                {
                    if (c.CountryName == country.CountryName)
                    {
                        runner.CountryCode = c.CountryCode;
                        break;
                    }
                }
            }

            if (RegistrationClass.AgeCheck(datePicker))
            {
                db.SaveChanges();
                Manager.MainFrame.Navigate(new RunnerMenu());
            }
        }
コード例 #2
0
        private void Registration(object sender, RoutedEventArgs e)
        {
            Gender  gender  = (Gender)genderBox.SelectedItem;
            Country country = (Country)countryBox.SelectedItem;

            string image = photoBox.Text;

            byte[] byteImg = RegistrationClass.ConvertToByte(image);

            User user = new User
            {
                Email     = emailBox.Text,
                Password  = passBox.Text,
                FirstName = firstNameBox.Text,
                LastName  = secondNameBox.Text,
                RoleId    = "R"
            };

            Runner runner = new Runner
            {
                Email       = emailBox.Text,
                Gender      = gender.GenderRow,
                DateOfBirth = datePicker.SelectedDate,
            };

            if (byteImg != null)
            {
                runner.Photo = byteImg;
            }

            foreach (Country c in db.Country)
            {
                if (c.CountryName == country.CountryName)
                {
                    runner.CountryCode = c.CountryCode;
                    break;
                }
            }

            if ((RegistrationClass.PasswordCheck(passBox.Text, passConfirm.Text)) && (RegistrationClass.EmailCheck(emailBox.Text)) && RegistrationClass.AgeCheck(datePicker))
            {
                db.User.Add(user);
                db.Runner.Add(runner);
                db.SaveChanges();

                MessageBox.Show("Регистрация успешно завершена!");

                CurrentUser.RunnerId = runner.RunnerId;
                CurrentUser.Email    = emailBox.Text;

                Manager.MainFrame.Navigate(new RegisterAnEvent());
                ;
            }
        }