public frmRezervasyon(ClassUser kullanici) { InitializeComponent(); _db = new OtelRezervasyonDBEntities(); this._kullanici = kullanici; _odaNumaralari = new HashSet <int>(); }
private void btnRezervasyonBitir_Click(object sender, EventArgs e) { using (OtelRezervasyonDBEntities _db = new OtelRezervasyonDBEntities()) { using (var transaction = _db.Database.BeginTransaction()) { try { #region Rezervasyon Ekleme int kisiId = (from c in _db.Customers where c.FirstName == kisi.FirstName select c.CustomerID ).First(); Reservation reservation = new Reservation(); reservation.CustomerID = kisiId; reservation.NumberOfAccomodation = lblToplamKisiSayisi.Text; reservation.Price = Convert.ToDecimal(lblToplamUcret.Text); reservation.ReleaseDate = Convert.ToDateTime(lblCikisTarihi.Text); reservation.EntryDate = Convert.ToDateTime(lblGirisTarihi.Text); reservation.IsActive = true; reservation.CreatedByID = kullanici.KullaniciID; reservation.CreatedDate = DateTime.Now; _db.Reservations.Add(reservation); _db.SaveChanges(); #endregion #region Konuk ve Rezervasyon Detayları Ekleme int odaNumaralariIndis = 0; int rezervasyonID = (from r in _db.Reservations orderby r.ReservationID descending select r.ReservationID).First(); for (int j = 0; j < misafirAdlari.Count; j++) { if (misafirAdlari[j] == "-") { odaNumaralariIndis++; continue; } Guest guest = new Guest(); guest.FirstName = misafirAdlari[j]; guest.LastName = misafirSoyadlari[j]; _db.Guests.Add(guest); _db.SaveChanges(); ReservationDetail reservationDetail = new ReservationDetail(); reservationDetail.GuestID = (from g in _db.Guests orderby g.GuestID descending select g.GuestID).First(); reservationDetail.RoomID = int.Parse(odaNumaralari[odaNumaralariIndis]); reservationDetail.ReservationID = rezervasyonID; _db.ReservationDetails.Add(reservationDetail); _db.SaveChanges(); } #endregion } catch (Exception) { MessageBox.Show("Bir Hata oluştu!"); transaction.Rollback(); } MessageBox.Show("Rezervasyon İşlemi Başarı ile Tamamlandı !"); transaction.Commit(); } } }
public frmRezervasyon(ClassUser kullanici) { InitializeComponent(); _db = new OtelRezervasyonDBEntities(); this.kullanici = kullanici; }
private void btnRezervasyonBitir_Click(object sender, EventArgs e) { using (OtelRezervasyonDBEntities _db = new OtelRezervasyonDBEntities()) { using (var transaction = _db.Database.BeginTransaction()) { try { #region Rezervasyon Ekleme int kisiId = (from c in _db.Customers where c.FirstName == kisi.FirstName select c.CustomerID ).First(); Reservation reservation = new Reservation(); reservation.CustomerID = kisiId; reservation.NumberOfAccomodation = lblToplamKisiSayisi.Text; reservation.Price = Convert.ToDecimal(lblToplamUcret.Text); reservation.ReleaseDate = Convert.ToDateTime(lblCikisTarihi.Text); reservation.EntryDate = Convert.ToDateTime(lblGirisTarihi.Text); reservation.IsActive = true; reservation.CreatedByID = kullanici.KullaniciID; reservation.CreatedDate = DateTime.Now; _db.Reservations.Add(reservation); _db.SaveChanges(); #endregion #region Konuk ve Rezervasyon Detayları Ekleme int odaNumaralariIndis = 0; int rezervasyonID = (from r in _db.Reservations orderby r.ReservationID descending select r.ReservationID).First(); ReservationDetail reservationDetail = new ReservationDetail(); Guest guest = new Guest(); guest.FirstName = "null"; guest.LastName = "null"; _db.Guests.Add(guest); _db.SaveChanges(); int guestID = (from r in _db.Guests orderby r.GuestID descending select r.GuestID).FirstOrDefault(); for (int i = 0; i < rezervasyonOzet.SecilenOdaNumaralari.Count; i++) { int odaNumara = rezervasyonOzet.SecilenOdaNumaralari.ToList()[i]; int roomID = (from r in _db.Rooms where r.RoomNumber == odaNumara select r.RoomID).First(); reservationDetail.GuestID = guestID; reservationDetail.RoomID = roomID; reservationDetail.ReservationID = rezervasyonID; _db.ReservationDetails.Add(reservationDetail); _db.SaveChanges(); } #endregion } catch (Exception ex) { MessageBox.Show("Bir Hata oluştu!"); transaction.Rollback(); } transaction.Commit(); MessageBox.Show("Rezervasyon İşlemi Başarı ile Tamamlandı !"); this.Close(); } } }