private object GetThongTinTuyen_TheoID(long idTuyen)
        {
            QLVanTai_2017   dbc = new QLVanTai_2017();
            QLVT_LuongTuyen ltt = dbc.QLVT_LuongTuyen.Where(u => u.LT_IdLuongTuyen == idTuyen).FirstOrDefault();
            var             ob  = new
            {
                LT_IdLuongTuyen     = ltt.LT_IdLuongTuyen,
                LT_MaTuyen          = ltt.LT_MaTuyen,
                LT_DC_IdBen_01      = ltt.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_IdBen_01,
                LT_DC_IdBen_02      = ltt.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_IdBen_02,
                LT_DC_TenBen_01     = ltt.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_TenBen_01,
                LT_DC_TenBen_02     = ltt.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_TenBen_02,
                TuyenDuong          = ltt.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_TenBen_01 + " - " + ltt.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_TenBen_02,
                LT_DC_IdLuongTuyen  = ltt.LT_DC_IdLuongTuyen,
                LT_HanhTrinhChay    = ltt.LT_HanhTrinhChay,
                LT_LuuLuongQuyDinh  = ltt.LT_LuuLuongQuyDinh,
                LT_PL_IdLuongTuyen  = ltt.LT_PL_IdLuongTuyen,
                TT_IdTrangThaiTuyen = ltt.TT_IdTrangThaiTuyen
            };

            return(ob);
        }
        public ActionResult ThemTTLuongTuyen(string benDi, string benDen, string maTuyen,
                                             string hanhTrinhChay, string cuLy, string luuLuong, string idTrangThai,
                                             string idPhanLoai)
        {
            try
            {
                var context         = new QLVanTai_2017();
                var checkLuongTuyen = context.QLVT_LuongTuyen
                                      .FirstOrDefault(u => (u.LT_HanhTrinhChay.CompareTo(hanhTrinhChay) == 0) || u.LT_MaTuyen.CompareTo(maTuyen) == 0);

                if (checkLuongTuyen != null)
                {
                    if (checkLuongTuyen.LT_HanhTrinhChay.CompareTo(hanhTrinhChay) == 0)
                    {
                        return(Json(new { status = false, error = "Hành trình chạy đã tồn tại" }, JsonRequestBehavior.AllowGet));
                    }
                    if (checkLuongTuyen.LT_MaTuyen.CompareTo(maTuyen) == 0)
                    {
                        return(Json(new { status = false, error = "Mã tuyến đã tồn tại" }, JsonRequestBehavior.AllowGet));
                    }
                }
                else
                {
                    int idBenDi  = Convert.ToInt32(benDi);
                    int idBenDen = Convert.ToInt32(benDen);

                    var diemDauCuoi = context.QLVT_LuongTuyen_DiemDauCuoi
                                      .FirstOrDefault(u => u.LT_DC_IdBen_01 == idBenDi && u.LT_DC_IdBen_02 == idBenDen);
                    if (diemDauCuoi == null)
                    {
                        var objDiemCuoi = new QLVT_LuongTuyen_DiemDauCuoi()
                        {
                            LT_DC_IdBen_01  = idBenDi,
                            LT_DC_IdBen_02  = idBenDen,
                            LT_DC_TenBen_01 = context.QLVT_ThongTinBenXe.FirstOrDefault(u => u.BX_IdBenXe == idBenDi)
                                              .TenBenXe,
                            LT_DC_TenBen_02 = context.QLVT_ThongTinBenXe.FirstOrDefault(u => u.BX_IdBenXe == idBenDen)
                                              .TenBenXe,
                            LT_DC_TT_IdTrangThai = 1,
                        };

                        context.QLVT_LuongTuyen_DiemDauCuoi.Add(objDiemCuoi);
                        context.SaveChanges();

                        diemDauCuoi = context.QLVT_LuongTuyen_DiemDauCuoi
                                      .FirstOrDefault(u => u.LT_DC_IdBen_01 == idBenDi && u.LT_DC_IdBen_02 == idBenDen);
                    }

                    var LuongTuyen = new QLVT_LuongTuyen()
                    {
                        LT_MaTuyen          = maTuyen,
                        LT_HanhTrinhChay    = hanhTrinhChay,
                        LT_CuLy             = Convert.ToInt32(cuLy),
                        LT_LuuLuongQuyDinh  = Convert.ToInt32(luuLuong),
                        TT_IdTrangThaiTuyen = Convert.ToInt32(idTrangThai),
                        LT_PL_IdLuongTuyen  = Convert.ToInt32(idPhanLoai),
                        LT_DC_IdLuongTuyen  = diemDauCuoi.LT_DC_IdLuongTuyen
                    };
                    context.QLVT_LuongTuyen.Add(LuongTuyen);
                    context.SaveChanges();

                    var TinhSo1 = context.QLVT_ThongTinBenXe
                                  .FirstOrDefault(c => c.BX_IdBenXe == LuongTuyen.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_IdBen_01)
                                  .TS_IdTinh_So;
                    var TinhSo2 = context.QLVT_ThongTinBenXe
                                  .FirstOrDefault(c => c.BX_IdBenXe == LuongTuyen.QLVT_LuongTuyen_DiemDauCuoi.LT_DC_IdBen_02)
                                  .TS_IdTinh_So;

                    var CapTuyen1 = new QLVT_CapTuyenChoTinh_So()
                    {
                        LT_IdLuongTuyen = LuongTuyen.LT_IdLuongTuyen,
                        TS_IdTinh_So    = TinhSo1
                    };

                    var CapTuyen2 = new QLVT_CapTuyenChoTinh_So()
                    {
                        LT_IdLuongTuyen = LuongTuyen.LT_IdLuongTuyen,
                        TS_IdTinh_So    = TinhSo2
                    };

                    context.QLVT_CapTuyenChoTinh_So.Add(CapTuyen1);
                    if (CapTuyen1.TS_IdTinh_So != CapTuyen2.TS_IdTinh_So)
                    {
                        context.QLVT_CapTuyenChoTinh_So.Add(CapTuyen2);
                    }

                    context.SaveChanges();
                    return(Json(new { status = true, message = "Thêm thành công." }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                return(Json(new { status = false, error = "Thêm không thành công." }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
        }