public void AddDichvu(int IDDichvuNcc, DateTime StartDate, DateTime EndDate) { if (Session["lichtrinhsession"] != null) { lichtrinh = Session["lichtrinhsession"] as Lichtrinh; var DichvuNcc = dichvuNccDAO.GetDichvuNccByID(IDDichvuNcc); var Dichvu = dichvuDAO.GetDichvuByID(Int32.Parse(DichvuNcc.DichvuID.ToString())); LichtrinhDVNCC lichtrinhDVNCC = new LichtrinhDVNCC() { DichvuNcc = DichvuNcc, Thoigianden = StartDate, Thoigiandi = EndDate, Dichvu = Dichvu, }; lichtrinh.LichtrinhDVNCCs.Add(lichtrinhDVNCC); Session["lichtrinhsession"] = lichtrinh; } else { lichtrinh = new Lichtrinh(); var DichvuNcc = dichvuNccDAO.GetDichvuNccByID(IDDichvuNcc); var Dichvu = dichvuDAO.GetDichvuByID(Int32.Parse(DichvuNcc.DichvuID.ToString())); LichtrinhDVNCC lichtrinhDVNCC = new LichtrinhDVNCC() { DichvuNcc = DichvuNcc, Thoigianden = StartDate, Thoigiandi = EndDate, Dichvu = Dichvu, }; lichtrinh.LichtrinhDVNCCs.Add(lichtrinhDVNCC); Session["lichtrinhsession"] = lichtrinh; } }
public void SetData(String nameTour, String soVe, String moTa, DateTime ngayxuatphat, DateTime ngayketthuc, int?huongdanvien) { tour = Session["Tour"] as Tour; tour.TourName = nameTour; tour.SoVe = Int32.Parse(soVe); tour.Ngayxuatphat = ngayxuatphat; tour.Ngaytao = DateTime.Now; tour.Ngayketthuc = ngayketthuc; var nhanvien = nhanvienDAO.GethuongdanvienbyID(Int32.Parse(huongdanvien.ToString())); tour.IDNhanvien = nhanvien.IDNhanvien; try { using (TransactionScope ts = new TransactionScope()) { using (SchudletourDbContext dbContext = new SchudletourDbContext()) { Tour setTour = new Tour() { IDNhanvien = tour.IDNhanvien, Ngaytao = tour.Ngaytao, Ngayxuatphat = tour.Ngayxuatphat, Ngayketthuc = tour.Ngayketthuc, SoVe = tour.SoVe, TourName = tour.TourName, }; dbContext.Tours.Add(setTour); dbContext.SaveChanges(); int?idTour = setTour.TourID; foreach (var lichtrinh in tour.Lichtrinhs) { Lichtrinh setlichtrinh = new Lichtrinh() { lichtrinhName = lichtrinh.lichtrinhName, LichtrinhMoTa = lichtrinh.LichtrinhMoTa, TourID = idTour, }; dbContext.Lichtrinhs.Add(setlichtrinh); dbContext.SaveChanges(); int?lichtrinhID = setlichtrinh.LichtrinhID; foreach (var thoigianCCDD in lichtrinh.ThoigianCCDDs) { ThoigianCCDD setthoigianCCDD = new ThoigianCCDD() { Thoigianden = thoigianCCDD.Thoigianden, Thoigiandi = thoigianCCDD.Thoigiandi, DiadiemID = thoigianCCDD.Diadiemthamquan.DiadiemID, IDLichtrinh = lichtrinhID, }; dbContext.ThoigianCCDDs.Add(setthoigianCCDD); dbContext.SaveChanges(); } foreach (var LichtrinhDVNCC in lichtrinh.LichtrinhDVNCCs) { LichtrinhDVNCC setlichtrinhDVNCC = new LichtrinhDVNCC() { Thoigianden = LichtrinhDVNCC.Thoigianden, Thoigiandi = LichtrinhDVNCC.Thoigiandi, GiaTien = LichtrinhDVNCC.DichvuNcc.Dichvu.Dongia, Mota = LichtrinhDVNCC.Mota, LichtrinhID = lichtrinhID, IDDichvu = LichtrinhDVNCC.DichvuNcc.Dichvu.DichvuID, IDDichvuNcc = LichtrinhDVNCC.DichvuNcc.IDDichvuNcc, ID = 3, }; dbContext.LichtrinhDVNCCs.Add(setlichtrinhDVNCC); dbContext.SaveChanges(); } } } ts.Complete(); } } catch (Exception ex) { } }