示例#1
0
 private void ExexuteUpdatePlaneCommand()
 {
     using (CP.UnitOfWork.UnitOfWork unitOfWork = new CP.UnitOfWork.UnitOfWork())
     {
         Users = unitOfWork.UserRepository.GetAll().ToList();
     }
 }
示例#2
0
 private void ExexuteDeleteUserCommand()
 {
     try
     {
         if (SelectedUser.IdUser == 0)
         {
             throw new Exception("Нельзя удалить\nадминистратора");
         }
         if (SelectedUser == null)
         {
             throw new Exception("Необходимо выбрать пользователя");
         }
         using (CP.UnitOfWork.UnitOfWork unitOfWork = new CP.UnitOfWork.UnitOfWork())
         {
             if (unitOfWork.ReservationRepository.GetAll().Where(a => a.IdUser == SelectedUser.IdUser).Count() != 0)
             {
                 throw new Exception("Выбранного пользователя\nнельзя удалить.\nОн забронировал рейс");
             }
             unitOfWork.UserRepository.Delete(SelectedUser.IdUser);
             unitOfWork.Save();
             SelectedUser = unitOfWork.UserRepository.GetAll().Last();
             Users        = unitOfWork.UserRepository.GetAll().ToList();
         }
     }
     catch (Exception ex)
     {
         Message message = new Message(ex.Message);
         message.Show();
     }
 }
示例#3
0
 public UsersPageViewModel()
 {
     using (CP.UnitOfWork.UnitOfWork unitOfWork = new CP.UnitOfWork.UnitOfWork())
     {
         Users = unitOfWork.UserRepository.GetAll().ToList();
     }
 }
 private void ExexuteUpdateCommand(object obj)
 {
     try
     {
         var values = (object[])obj;
         if (_name != "" || _surname != "" || _mail != "" || Phone != "")
         {
             using (CP.UnitOfWork.UnitOfWork unitOfWork = new CP.UnitOfWork.UnitOfWork())
             {
                 User        user           = unitOfWork.UserRepository.Get(id);
                 PasswordBox password       = (PasswordBox)values[0];
                 PasswordBox repeatPassword = (PasswordBox)values[1];
                 if (password.Password != "")
                 {
                     MD5    md5      = new MD5CryptoServiceProvider();
                     byte[] checkSum = md5.ComputeHash(Encoding.UTF8.GetBytes(password.Password));
                     string pass     = BitConverter.ToString(checkSum).Replace("-", String.Empty);
                     if (pass != user.Password)
                     {
                         throw new Exception("Неверный пароль!!!");
                     }
                     if (repeatPassword == null)
                     {
                         throw new Exception("Новый пароль не указан!!!");
                     }
                     if (repeatPassword.Password.Length != 8)
                     {
                         throw new Exception("Новый пароль\nнедопустимой длины!!!");
                     }
                     checkSum      = md5.ComputeHash(Encoding.UTF8.GetBytes(repeatPassword.Password));
                     pass          = BitConverter.ToString(checkSum).Replace("-", String.Empty);
                     user.Password = pass;
                 }
                 if (unitOfWork.UserRepository.GetAll().Where(a => a.Name == Name).Count() == 1 &&
                     user.Name != Name)
                 {
                     throw new Exception("Такой ник уже существует");
                 }
                 user.Name         = Name;
                 user.Surname      = Surname;
                 user.Mail         = Mail;
                 user.Phone_number = Phone;
                 unitOfWork.Save();
                 throw new Exception("Сохранено успешно");
             }
         }
         else
         {
             throw new Exception("Поля не могут быть пустыми");
         }
     }
     catch (Exception a)
     {
         Message message = new Message(a.Message);
         message.Show();
     }
 }
示例#5
0
 public AirFlightsRegViewModel(int idFlight)
 {
     using (CP.UnitOfWork.UnitOfWork unitOfWork = new CP.UnitOfWork.UnitOfWork())
     {
         Flight flight = unitOfWork.FlightRepository.Get(idFlight);
         DateStart       = flight.DateStart;
         DateEnd         = flight.DateEnd;
         Price           = flight.Price;
         FirstCity       = flight.FirstCity;
         SecondCity      = flight.SecondCity;
         SelectedIdPlane = flight.Plane.IdPlane;
         PlanesId        = unitOfWork.PlaneRepository.GetAll()
                           .Select(a => a.IdPlane).ToList();
     }
 }
 public PlainRegViewModel(int idPlain)
 {
     _idplane = idPlain;
     if (_idplane != -1)
     {
         using (CP.UnitOfWork.UnitOfWork unitOfWork = new CP.UnitOfWork.UnitOfWork())
         {
             Plane plane = unitOfWork.PlaneRepository.Get(_idplane);
             Name          = plane.Name;
             Seats         = plane.Seats;
             CruisingSpeed = plane.CruisingSpeed;
             MaxHeight     = plane.MaxHeight;
         }
     }
 }
 private void ExexuteAddPlaneCommand(object obj)
 {
     try
     {
         Window window = (Window)obj;
         if (_name == null || _name == "" || _seats == 0 || _cruisingSpeed == 0 || _maxHeight == 0)
         {
             throw new Exception("Все поля\nнеобходимо заполнить!");
         }
         using (CP.UnitOfWork.UnitOfWork unitOfWork = new CP.UnitOfWork.UnitOfWork())
         {
             if (_idplane != -1)
             {
                 Plane plane = unitOfWork.PlaneRepository.Get(_idplane);
                 if (unitOfWork.PlaneRepository.GetAll().Where(a => a.Name == _name).Count() == 1 &&
                     plane.Name != Name)
                 {
                     throw new Exception("Такой самолет уже существует\nВыберите другое имя");
                 }
                 plane.Name = Name;
                 if (plane.Seats > Seats)
                 {
                     IEnumerable <int> Flight = unitOfWork.FlightRepository.GetAll()
                                                .Where(a => a.IdPlane == plane.IdPlane)
                                                .Select(a => a.IdFlight);
                     foreach (int idFlightCurrentPlane in Flight)
                     {
                         if (unitOfWork.ReservationRepository.GetAll()
                             .Where(a => a.IdFlight == idFlightCurrentPlane)
                             .Where(a => a.YourSeat > Seats)
                             .Select(a => a.YourSeat)
                             .Count() != 0)
                         {
                             throw new Exception("Недопустимо\nизменение вместимости\nМестa забронированы");
                         }
                     }
                 }
                 plane.Seats         = Seats;
                 plane.CruisingSpeed = CruisingSpeed;
                 plane.MaxHeight     = MaxHeight;
                 unitOfWork.Save();
                 window.Close();
             }
             else
             {
                 if (unitOfWork.PlaneRepository.GetAll().Where(a => a.Name == _name).Count() == 1)
                 {
                     throw new Exception("Такой самолет уже существует\nВыберите другое имя");
                 }
                 unitOfWork.PlaneRepository.Create(new Plane(Name, Seats, CruisingSpeed, MaxHeight));
                 unitOfWork.Save();
                 window.Close();
             }
         }
     }
     catch (Exception ex)
     {
         Message message = new Message(ex.Message);
         message.Show();
     }
 }