// 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;
            }
        }
Ejemplo n.º 2
0
        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)
            {
            }
        }