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; } }
// GET: Lichtrinh public void AddDiadiem(int DiadiemID, DateTime StartDate, DateTime EndDate) { if (Session["lichtrinhsession"] != null) { lichtrinh = Session["lichtrinhsession"] as Lichtrinh; var diadiem = diadiemDAO.GetSreachDiadiembyID(DiadiemID); ThoigianCCDD thoigianCCDD = new ThoigianCCDD() { Thoigianden = StartDate, Thoigiandi = EndDate, Diadiemthamquan = diadiem, }; foreach (var item in lichtrinh.ThoigianCCDDs) { if (item.Diadiemthamquan.DiadiemID == DiadiemID && item.Thoigianden == StartDate) { Session["lichtrinhsession"] = lichtrinh; break; } else { lichtrinh.ThoigianCCDDs.Add(thoigianCCDD); Session["lichtrinhsession"] = lichtrinh; break; } } } else { lichtrinh = new Lichtrinh(); var diadiem = diadiemDAO.GetSreachDiadiembyID(DiadiemID); ThoigianCCDD thoigianCCDD = new ThoigianCCDD() { Thoigianden = StartDate, Thoigiandi = EndDate, Diadiemthamquan = diadiem, }; thoigianCCDD.Diadiemthamquan = diadiem; lichtrinh.ThoigianCCDDs.Add(thoigianCCDD); Session["lichtrinhsession"] = lichtrinh; } }
public ActionResult CreateLichtrinh() { var rqDiadiem = HttpContext.Request.Form["idDiadiem"]; var rqDichvu = HttpContext.Request.Form["idDichvu"]; var rpStartdate = HttpContext.Request.Form["thoigianden"]; var rpEnddate = HttpContext.Request.Form["thoigiandi"]; if (rqDiadiem != "") { if (rpStartdate == null && rpEnddate == null) { lichtrinh = Session["lichtrinhsession"] as Lichtrinh; return(View(lichtrinh)); } else { DateTime Startdate = DateTime.Parse(rpStartdate); DateTime Enddate = DateTime.Parse(rpEnddate); int DiadiemID = Int32.Parse(rqDiadiem); AddDiadiem(DiadiemID, Startdate, Enddate); } } if (rqDichvu != "") { if (rpStartdate == null && rpEnddate == null) { lichtrinh = Session["lichtrinhsession"] as Lichtrinh; return(View(lichtrinh)); } else { DateTime Startdate = DateTime.Parse(rpStartdate); DateTime Enddate = DateTime.Parse(rpEnddate); int DichvuID = Int32.Parse(rqDichvu); AddDichvu(DichvuID, Startdate, Enddate); } } //var rpdichvu = HttpContext.Request.Form["submitdichvu"]; return(View(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) { } }