private void promocodeButton_Click(object sender, RoutedEventArgs e)
        {
            using (UserContext db = new UserContext())
            {
                Promocode promo = db.Promocodes.Where(p => p.Id != 1 && p.Value == promocodeTextbox.Text).FirstOrDefault();
                if (promo != null)
                {
                    MessageBox.Show("Промокод применен!");
                    promocodeTextbox.Text = "";
                    foreach (User u in db.Users.Include("Promocode").ToList())
                    {
                        if (u.Login == us.Login)
                        {
                            u.Promocode = promo;
                        }
                        if (u.Promocode.Effect == "Скидка 10%")
                        {
                            foreach (Car c in cars)
                            {
                                c.Price *= 0.9;
                            }
                        }
                        else if (u.Promocode.Effect == "Скидка 20%")
                        {
                            foreach (Car c in cars)
                            {
                                c.Price *= 0.8;
                            }
                        }
                        else if (u.Promocode.Effect == "Скидка 30%")
                        {
                            foreach (Car c in cars)
                            {
                                c.Price *= 0.7;
                            }
                        }
                        else if (u.Promocode.Effect == "1 прокат")
                        {
                            foreach (Car c in cars)
                            {
                                c.Price = 0;
                            }
                        }
                        usedPromoLabel.Content = "Активный промокод: " + u.Promocode.Effect;
                    }

                    refresh_Click(this, e);

                    db.SaveChanges();
                    return;
                }
                else
                {
                    MessageBox.Show("Такого промода нет");
                }
            }
        }
예제 #2
0
        public void firstHash(string userPassword, int numberOfItterations)
        {
            using (UserContext db = new UserContext())
            {
                Rfc2898DeriveBytes PBKDF2         = new Rfc2898DeriveBytes(userPassword, 8, numberOfItterations);
                byte[]             hashedPassword = PBKDF2.GetBytes(20);
                byte[]             salt           = PBKDF2.Salt;


                UserProfile profile = new UserProfile {
                    FirstName            = firstNameTextbox.Text,
                    SecondName           = secondNameTextbox.Text,
                    MiddleName           = middleNameTextbox.Text,
                    PhoneNumber          = phoneNumberTextbox.Text,
                    DateOfBirth          = dateOfBirthPicker.SelectedDate.GetValueOrDefault().ToShortDateString(),
                    PassportSerialNumber = passportSerialNumberTextbox.Text,
                    Email             = emailTextbox.Text,
                    RegistrationDate  = DateTime.Now.ToShortDateString(),
                    CountOfRentedCars = 0,
                    Admin             = false
                };
                Car       car   = db.Cars.Where(c => c.Id == 1).FirstOrDefault();
                Promocode promo = db.Promocodes.Where(p => p.Id == 1).FirstOrDefault();
                Review    rev   = db.Reviews.Where(r => r.Id == 1).FirstOrDefault();
                User      user  = new User
                {
                    Login     = loginTextbox.Text,
                    Hash      = hashedPassword,
                    Salt      = salt,
                    Car       = car,
                    Promocode = promo,
                    Review    = rev
                };
                profile.User = user;


                db.Users.Add(user);
                db.UserProfiles.Add(profile);
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        MessageBox.Show("Object: " + validationError.Entry.Entity.ToString());
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            MessageBox.Show(err.ErrorMessage + "");
                        }
                    }
                }
            }
        }
예제 #3
0
 private void removePromocodeButton_Click(object sender, RoutedEventArgs e)
 {
     using (UserContext db = new UserContext())
     {
         Promocode promo = db.Promocodes.Where(p => p.Value == promocodeTextbox.Text).FirstOrDefault();
         db.Promocodes.Remove(promo);
         db.SaveChanges();
     }
     MessageBox.Show("Промокод удален");
     this.Close();
 }
        private void addPromocodeButton_Click(object sender, RoutedEventArgs e)
        {
            var x = (CarRental_Adm)this.Owner;

            if (x.editFlag)
            {
                Promocode p = new Promocode()
                {
                    Value  = promocodeTextbox.Text,
                    Effect = effectCombobox.Text
                };

                using (UserContext db = new UserContext())
                {
                    list = db.Promocodes.ToList();
                    foreach (Promocode pr in db.Promocodes)
                    {
                        if (pr.Value == list[x.promocodesDatagrid.SelectedIndex + 1].Value)
                        {
                            pr.Value  = p.Value;
                            pr.Effect = p.Effect;
                        }
                    }
                    db.SaveChanges();
                    x.refreshPromocodeButton_Click(this, null);
                }

                x.editFlag = false;
                this.Close();
                return;
            }
            else
            {
                using (UserContext db = new UserContext())
                {
                    Promocode promocode = new Promocode()
                    {
                        Value  = promocodeTextbox.Text,
                        Effect = effectCombobox.Text
                    };

                    db.Promocodes.Add(promocode);
                    db.SaveChanges();

                    x.refreshPromocodeButton_Click(this, null);
                }
                this.Close();
                return;
            }
        }
예제 #5
0
 private void addPromocodeButton_Click(object sender, RoutedEventArgs e)
 {
     using (UserContext db = new UserContext())
     {
         Promocode promocode = new Promocode
         {
             Value  = promocodeTextbox.Text,
             Effect = effectCombobox.Text
         };
         db.Promocodes.Add(promocode);
         db.SaveChanges();
     }
     MessageBox.Show("Промокод добавлен");
     this.Close();
 }
예제 #6
0
        public MainWindow()
        {
            InitializeComponent();
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;


            using (UserContext db = new UserContext())
            {
                if (!db.Users.Any(u => u.Login == "thanatos"))
                {
                    using (System.IO.FileStream fs = new System.IO.FileStream(@"D:\Work\Labs\Labs 4\ООП\КП-бэкап\Kursach_1.2\Cars\Mustang.jpg", FileMode.Open))
                    {
                        imageData1 = new byte[fs.Length];
                        fs.Read(imageData1, 0, imageData1.Length);
                    }

                    using (System.IO.FileStream fs = new System.IO.FileStream(@"D:\Work\Labs\Labs 4\ООП\КП-бэкап\Kursach_1.2\no_image.jpg", FileMode.Open))
                    {
                        imageData2 = new byte[fs.Length];
                        fs.Read(imageData2, 0, imageData2.Length);
                    }

                    using (System.IO.FileStream fs = new System.IO.FileStream(@"D:\Work\Labs\Labs 4\ООП\КП-бэкап\Kursach_1.2\Cars\Golf.jfif", FileMode.Open))
                    {
                        imageData3 = new byte[fs.Length];
                        fs.Read(imageData3, 0, imageData3.Length);
                    }


                    Rfc2898DeriveBytes PBKDF2          = new Rfc2898DeriveBytes("donatos", 8, 25);
                    byte[]             hashedPassword1 = PBKDF2.GetBytes(20);
                    byte[]             salt1           = PBKDF2.Salt;

                    Rfc2898DeriveBytes PBKDF3          = new Rfc2898DeriveBytes("thanatos", 8, 25);
                    byte[]             hashedPassword2 = PBKDF3.GetBytes(20);
                    byte[]             salt2           = PBKDF3.Salt;


                    Promocode promo = new Promocode {
                        Value = null, Effect = null
                    };
                    Promocode promo1 = new Promocode {
                        Value = "holidays30", Effect = "Скидка 30%"
                    };
                    Promocode promo2 = new Promocode {
                        Value = "happy10", Effect = "Скидка 10%"
                    };
                    Promocode promo3 = new Promocode {
                        Value = "freerent", Effect = "1 прокат"
                    };


                    Review rev1 = new Review {
                        Text = null
                    };
                    Review rev2 = new Review {
                        Text = "Очень красивое и удобное приложение."
                    };


                    Car car1 = new Car
                    {
                        Image        = imageData2,
                        EngineVolume = 0,
                        Mileage      = 0,
                        Price        = 0,
                        IsAvailable  = false
                    };


                    Car car2 = new Car
                    {
                        Image        = imageData1,
                        Name         = "Ford",
                        Model        = "Mustang GT",
                        Description  = "Очень хороший автомобиль. Крайне привлекательный внешний вид, большая мощность. Своих денег стоит.",
                        EngineVolume = 5,
                        ReleaseDate  = "23.04.2015",
                        Category     = "Спортивные",
                        Color        = "Серебристый",
                        Mileage      = 25158,
                        Price        = 250,
                        IsAvailable  = true
                    };


                    Car car3 = new Car
                    {
                        Image        = imageData3,
                        Name         = "Volkswagen",
                        Model        = "Golf GTI 8 Series",
                        Description  = "Очень хороший автомобиль. Крайне привлекательный внешний вид, большая мощность. Своих денег стоит.",
                        EngineVolume = 2,
                        ReleaseDate  = "21.09.2017",
                        Category     = "Эконом",
                        Color        = "Белый",
                        Mileage      = 7530,
                        Price        = 150,
                        IsAvailable  = true
                    };


                    UserProfile userProfile1 = new UserProfile
                    {
                        FirstName            = "Егор",
                        SecondName           = "Сирош",
                        MiddleName           = "Александрович",
                        PhoneNumber          = "+375297322435",
                        DateOfBirth          = "25.06.2001",
                        PassportSerialNumber = "HB1234567",
                        Email             = "*****@*****.**",
                        RegistrationDate  = "23.04.2020",
                        CountOfRentedCars = 0,
                        Admin             = true
                    };

                    UserProfile userProfile2 = new UserProfile
                    {
                        FirstName            = "Егор",
                        SecondName           = "Сирош",
                        MiddleName           = "Александрович",
                        PhoneNumber          = "+375297322435",
                        DateOfBirth          = "25.06.2001",
                        PassportSerialNumber = "HB1234567",
                        Email             = "*****@*****.**",
                        RegistrationDate  = "23.04.2020",
                        CountOfRentedCars = 0,
                        Admin             = false
                    };


                    User user1 = new User
                    {
                        Login       = "******",
                        Hash        = hashedPassword1,
                        Salt        = salt1,
                        UserProfile = userProfile1,
                        Car         = car1,
                        Promocode   = promo,
                        Review      = rev1
                    };

                    User user2 = new User
                    {
                        Login       = "******",
                        Hash        = hashedPassword2,
                        Salt        = salt2,
                        UserProfile = userProfile2,
                        Car         = car1,
                        Promocode   = promo,
                        Review      = rev2
                    };



                    db.Users.AddRange(new List <User> {
                        user1, user2
                    });
                    db.UserProfiles.Add(userProfile1);
                    db.Cars.AddRange(new List <Car> {
                        car1, car2, car3
                    });
                    db.Promocodes.AddRange(new List <Promocode> {
                        promo, promo1, promo2, promo3
                    });



                    try
                    {
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                        {
                            MessageBox.Show("Object: " + validationError.Entry.Entity.ToString());
                            foreach (DbValidationError err in validationError.ValidationErrors)
                            {
                                MessageBox.Show(err.ErrorMessage + "");
                            }
                        }
                    }
                }
            }
        }
예제 #7
0
        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            var  x    = (CarRental_Adm)this.Owner;
            bool flag = false;

            if (adminCheckbox.IsChecked == true)
            {
                flag = true;
            }

            if (x.editFlag)
            {
                try
                {
                    UserProfile u = new UserProfile()
                    {
                        FirstName            = firstNameTextbox.Text,
                        SecondName           = secondNameTextbox.Text,
                        MiddleName           = middleNameTextbox.Text,
                        PhoneNumber          = phoneNumberTextbox.Text,
                        DateOfBirth          = dateOfBirthPicker.SelectedDate.GetValueOrDefault().ToShortDateString(),
                        PassportSerialNumber = passportSerialNumberTextbox.Text,
                        Email = emailTextbox.Text,
                        Admin = flag
                    };

                    using (UserContext db = new UserContext())
                    {
                        foreach (User user in db.Users.Include("UserProfile"))
                        {
                            list.Add(new FullUser
                            {
                                Login                = user.Login,
                                Hash                 = user.Hash,
                                Salt                 = user.Salt,
                                FirstName            = user.UserProfile.FirstName,
                                SecondName           = user.UserProfile.SecondName,
                                MiddleName           = user.UserProfile.MiddleName,
                                PhoneNumber          = user.UserProfile.PhoneNumber,
                                DateOfBirth          = user.UserProfile.DateOfBirth,
                                PassportSerialNumber = user.UserProfile.PassportSerialNumber,
                                Email                = user.UserProfile.Email,
                                RegistrationDate     = user.UserProfile.RegistrationDate,
                                CountOfRentedCars    = user.UserProfile.CountOfRentedCars,
                                Admin                = user.UserProfile.Admin
                            });
                        }
                        foreach (User us in db.Users.Include("UserProfile"))
                        {
                            if (us.Login == list[x.usersDatagrid.SelectedIndex].Login)
                            {
                                us.UserProfile.FirstName            = u.FirstName;
                                us.UserProfile.SecondName           = u.SecondName;
                                us.UserProfile.MiddleName           = u.MiddleName;
                                us.UserProfile.PhoneNumber          = u.PhoneNumber;
                                us.UserProfile.DateOfBirth          = u.DateOfBirth;
                                us.UserProfile.PassportSerialNumber = u.PassportSerialNumber;
                                us.UserProfile.Email = u.Email;
                                us.UserProfile.Admin = u.Admin;
                            }
                        }
                        db.SaveChanges();
                        x.refreshButton_Click(this, null);
                    }

                    x.editFlag = false;
                    this.Close();
                    return;
                }
                catch
                {
                    MessageBox.Show("Выберите пользователя");
                }
            }
            else
            {
                using (UserContext db = new UserContext())
                {
                    Rfc2898DeriveBytes PBKDF2         = new Rfc2898DeriveBytes(passwordPasswordbox.Password, 8, 25);
                    byte[]             hashedPassword = PBKDF2.GetBytes(20);
                    byte[]             salt           = PBKDF2.Salt;

                    User        user    = new User();
                    UserProfile profile = new UserProfile();
                    Car         car     = db.Cars.Where(c => c.Id == 1).FirstOrDefault();
                    Promocode   promo   = db.Promocodes.Where(p => p.Id == 1).FirstOrDefault();
                    Review      rev     = db.Reviews.Where(r => r.Id == 1).FirstOrDefault();

                    user.Login     = loginTextbox.Text;
                    user.Hash      = hashedPassword;
                    user.Salt      = salt;
                    user.Car       = car;
                    user.Promocode = promo;
                    user.Review    = rev;


                    profile.FirstName            = firstNameTextbox.Text;
                    profile.SecondName           = secondNameTextbox.Text;
                    profile.MiddleName           = middleNameTextbox.Text;
                    profile.PhoneNumber          = phoneNumberTextbox.Text;
                    profile.DateOfBirth          = dateOfBirthPicker.SelectedDate.GetValueOrDefault().ToShortDateString();
                    profile.PassportSerialNumber = passportSerialNumberTextbox.Text;
                    profile.Email             = emailTextbox.Text;
                    profile.Admin             = flag;
                    profile.RegistrationDate  = DateTime.Now.ToShortDateString();
                    profile.CountOfRentedCars = 0;
                    profile.User = user;



                    db.Users.Add(user);
                    db.UserProfiles.Add(profile);
                    db.SaveChanges();

                    x.refreshButton_Click(this, null);
                }
                this.Close();
                return;
            }
        }