public async Task <IActionResult> Edit(int id, [Bind("id_DatCho,NgayLap,TinhTrang,id_TheTinDung,id_KhachHang,id_ChiTietChuyenBay,SoluongDat,TenLH,HoLH,EmailLH,DienThoaiLH")] DatCho datCho) { if (id != datCho.id_DatCho) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(datCho); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DatChoExists(datCho.id_DatCho)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["id_ChiTietChuyenBay"] = new SelectList(_context.ChiTietChuyenBay, "id_ChiTietChuyenBay", "id_ChiTietChuyenBay", datCho.id_ChiTietChuyenBay); ViewData["id_KhachHang"] = new SelectList(_context.KhachHang, "id_KhachHang", "id_KhachHang", datCho.id_KhachHang); ViewData["id_TheTinDung"] = new SelectList(_context.TheTinDung, "id_TheTinDung", "id_TheTinDung", datCho.id_TheTinDung); return(View(datCho)); }
public async Task <IActionResult> Save() { DatCho datCho1 = new DatCho(); BookingVM b = HttpContext.Session.GetObject <BookingVM>(SessionManager.Booking); UserLogin currentUser = HttpContext.Session.GetObject <UserLogin>(SessionManager.UserLogin); BookingContactVM Contact = HttpContext.Session.GetObject <BookingContactVM>(SessionManager.BookingContact); datCho1.id_ChiTietChuyenBay = b.VeDi; datCho1.NgayLap = DateTime.Today; datCho1.TinhTrang = false; datCho1.id_KhachHang = currentUser.idUser; datCho1.TenLH = Contact.TenLH; datCho1.HoLH = Contact.HoLH; datCho1.EmailLH = Contact.EmailLH; datCho1.DienThoaiLH = Contact.DienThoaiLH; List <PassengerVM> PassengersList = HttpContext.Session.GetObject <List <PassengerVM> >(SessionManager.PassengerTempList); foreach (PassengerVM item in PassengersList) { datCho1.ChiTietDatCho.Add(new ChiTietDatCho() { TenHk = item.TenHK, HoHk = item.HoHK, DanhXung = item.DanhXung, NgaySinh = item.NgaySinh, id_DatCho = datCho1.id_DatCho }); } datCho1.SoluongDat = PassengersList.Count(); _context.DatCho.Add(datCho1); await _context.SaveChangesAsync(); if (b.VeVe != -1) { DatCho datCho2 = new DatCho(); datCho2.id_ChiTietChuyenBay = b.VeVe; datCho2.NgayLap = DateTime.Today; datCho2.TinhTrang = false; datCho2.id_KhachHang = currentUser.idUser; datCho2.TenLH = Contact.TenLH; datCho2.HoLH = Contact.HoLH; datCho2.EmailLH = Contact.EmailLH; datCho2.DienThoaiLH = Contact.DienThoaiLH; foreach (PassengerVM item in PassengersList) { datCho2.ChiTietDatCho.Add(new ChiTietDatCho() { TenHk = item.TenHK, HoHk = item.HoHK, DanhXung = item.DanhXung, NgaySinh = item.NgaySinh, id_DatCho = datCho1.id_DatCho }); } datCho2.SoluongDat = PassengersList.Count(); } return(RedirectToAction("History", "Customers")); }
public async Task <IActionResult> Create([Bind("id_DatCho,NgayLap,TinhTrang,id_TheTinDung,id_KhachHang,id_ChiTietChuyenBay,SoluongDat,TenLH,HoLH,EmailLH,DienThoaiLH")] DatCho datCho) { if (ModelState.IsValid) { _context.Add(datCho); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["id_ChiTietChuyenBay"] = new SelectList(_context.ChiTietChuyenBay, "id_ChiTietChuyenBay", "id_ChiTietChuyenBay", datCho.id_ChiTietChuyenBay); ViewData["id_KhachHang"] = new SelectList(_context.KhachHang, "id_KhachHang", "id_KhachHang", datCho.id_KhachHang); ViewData["id_TheTinDung"] = new SelectList(_context.TheTinDung, "id_TheTinDung", "id_TheTinDung", datCho.id_TheTinDung); return(View(datCho)); }
private void btnRequireOrder_Click(object sender, EventArgs e) { if (ListCus.Single(txtCode.Text) != null) { if (listOrder.Count > 0) { //Tao ra danh sach dat cho List <DatCho> temp = new List <DatCho>(); DatCho t = new DatCho(); foreach (Chuyen item in listOrder) { t.MChuyen = item.MChuyen; t.MKHang = txtCode.Text; temp.Add(t); } //Tim danh sach dat cho da ton tai va co trang thai chuyen di la dang cho List <Chuyen> oldTrip = ListTrips.Find(ListOrd.Find(Code), 1);//Tim ds chuyen dang mo cua ds dat cho cua khach hang //Tao ds dat cho cua khach hang da ton tai va trang thai dang mo List <DatCho> old = new List <DatCho>(); foreach (Chuyen item in oldTrip) { DatCho tp = new DatCho(); tp.MKHang = txtCode.Text; tp.MChuyen = item.MChuyen; old.Add(tp); } // So sanh voi temp de lay ra nhung cai them moi va nhung cai can xoa di List <DatCho> nw = new List <DatCho>(); //danh sach can them moi List <DatCho> dl = new List <DatCho>(); //danh sach can xoa di foreach (DatCho i in temp) { bool s = true; foreach (DatCho j in old) { if (i.MChuyen == j.MChuyen)//da ton tai, bo qua { s = false; break; } } if (s) { nw.Add(i);//Chua ton tai nen them duoc } } foreach (DatCho i in old) { bool r = true; foreach (DatCho j in temp) { if (i.MChuyen == j.MChuyen) { r = false; break; } } if (r)//co trong cai cu nhung khong co trong cai moi nen xoa di { dl.Add(i); } } // duong nhien ca hai old va temp deu la danh sach dat cho cua chuyen dang mo // Thuc hien xoa tren old va add tren nw la OK foreach (DatCho i in nw) { if (ListOrd.Add(i)) { MessageBox.Show(String.Format("You have add the trip which has code {0}!", i.MChuyen), "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(String.Format("You had been faile the trip which has code {0}!", i.MChuyen), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } foreach (DatCho i in dl) { if (ListOrd.Delete(i)) { MessageBox.Show(String.Format("You have delete the trip which has code {0}!", i.MChuyen), "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } else { MessageBox.Show(String.Format("You had been faile the trip which has code {0}!", i.MChuyen), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } btnRequireOrder.Enabled = false; } else { MessageBox.Show("You have not add the trips! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("You have not add this customer! Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }