コード例 #1
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());
                ;
            }
        }
コード例 #2
0
        private void SaveChanges(object sender, RoutedEventArgs e)
        {
            var charity = db.Charity
                          .Where(c => c.CharityName == currentCharity.CharityName)
                          .FirstOrDefault();

            string filename = tbFilename.Text;

            if (charity == null) //проверка для выбора редактирования или создания спонсора
            {                    //если такой нет, то создаем
                filename = tbFilename.Text;
                byte[] image = null;
                if (filename != "")
                {
                    image = RegistrationClass.ConvertToByte(filename);
                }

                Charity AddCharity = new Charity
                {
                    CharityName        = tbName.Text,
                    CharityDescription = tbDescription.Text,
                    CharityLogo        = image,
                };

                db.Charity.Add(AddCharity);
                db.SaveChanges();
            }
            else //иначе редачим текущую
            {
                charity.CharityName        = tbName.Text;
                charity.CharityDescription = tbDescription.Text;

                filename = tbFilename.Text;

                if (filename != "")
                {
                    byte[] image = RegistrationClass.ConvertToByte(filename);
                    charity.CharityLogo = image;
                }

                db.SaveChanges();
            }
        }
コード例 #3
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());
            }
        }