/// <summary> /// Добавить или обновить работника отеля /// </summary> /// <param name="value"></param> /// <returns></returns> /// <exception cref="ArgumentException" /// <exception cref="MyException" public static HotelWorker AddOrUpdate(HotelWorker value) { if (value == null) { throw new ArgumentException("HotelWorker is null"); } try { if (IsContains(value)) { HotelWorker existingModel = EntityConnection.HotelWorkers.Where(x => x.Id == value.Id).First(); if (existingModel != null) { existingModel = value; return(existingModel); } else { throw new MyException("HotelWorker.HotelCreator.AddOrUpdateHotelNumber()"); } } else { return(EntityConnection.HotelWorkers.Add(value)); } } finally { EntityConnection.SaveChanges(); } }
private void Button_Enter_Click(object sender, EventArgs e) { //Проверка на существование пользователя if (HotelCreator.IsUserExists(this.TextBox_Login.Text, this.ComboBox_Hotels.Text)) { // Если существует то не будет null Director = HotelCreator.IsUserCorrect(this.TextBox_Login.Text, this.TextBox_Password.Text, this.ComboBox_Hotels.Text); if (Director != null) { if (Director.AcessLvl == 0) //Ур.доступа { DialogResult = DialogResult.OK; } else { MessageBox.Show("Доступ ограничен"); } } else { MessageBox.Show("Пароль введен не правильно!"); this.TextBox_Password.Text = string.Empty; } } else { MessageBox.Show("Пользователь не найден"); } }
/// <summary> /// Проверка на существование /// </summary> /// <param name="value">Работник отеля</param> /// <returns>true-существует, false-нет</returns> public static bool IsContains(HotelWorker value) { if (EntityConnection.HotelWorkers.AsEnumerable().Contains(value)) { return(true); } return(false); }
/// <summary> /// Заполнение данных в форму /// </summary> /// <param name="worker"></param> private void Update(HotelWorker worker) { this.TextBox_Surname.Text = worker.Surname; this.TextBox_Name.Text = worker.Name; this.TextBox_Patronymic.Text = worker.Patronymic; this.TextBox_Login.Text = worker.Login; this.TextBox_Password.Text = worker.Password; this.TextBox_Phonenumber.Text = worker.Phonenumber.ToString(); this.TextBox_Post.Text = worker.ThePost; this.ComboBox_Access.SelectedIndex = worker.AcessLvl; }
/// <summary> /// Директор /// </summary> /// <param name="admin"></param> public Options_Director(HotelWorker admin) : this() { // Если админ if (admin == null) { WorkerInfo = new HotelWorker(); } else { Update(admin); } WorkerInfo = admin; WorkerInfo.AcessLvl = 0; workerType = EnumWorkerType.Admin; this.ComboBox_Access.SelectedIndex = 0; }