Exemplo n.º 1
0
 public DatPhongCartController(ApplicationDbContext dbContext)
 {
     _Context      = dbContext;
     _DatPhongCart = new DatPhongCartVM()
     {
         LsPhongDatPhongs  = new List <Phong>(),
         LsDichVuDatPhongs = new List <DichVu>(),
     };
 }
Exemplo n.º 2
0
        public async Task <IActionResult> XacNhanDatPhong(DatPhongCartVM ab)
        {
            if (ModelState.IsValid)
            {
                List <int> lstsPhongCart = HttpContext.Session.Get <List <int> >("ssPhongCart");
                if (lstsPhongCart != null)
                {
                    if (lstsPhongCart.Count != 0)
                    {
                        foreach (var i in lstsPhongCart)
                        {
                            _Context.Database.ExecuteSqlRaw($"EXECUTE dbo.AddChiTietDatPhongHeap {i}");
                        }
                    }
                }

                List <int> lstsDichVuCart = HttpContext.Session.Get <List <int> >("ssDichVuCart");
                if (lstsDichVuCart != null)
                {
                    if (lstsDichVuCart.Count != 0)
                    {
                        foreach (var i in lstsDichVuCart)
                        {
                            _Context.Database.ExecuteSqlRaw($"EXECUTE dbo.AddChiTietDichVuHeap {i}");
                        }
                    }
                }

                var Tenkh    = new SqlParameter("@Tenkh", ab.newDatPhong.TenNguoiDat);
                var DiaChi   = new SqlParameter("@DiaChi", ab.newDatPhong.Address);
                var CMND     = new SqlParameter("@CMND", ab.newDatPhong.Cmnd);
                var SDT      = new SqlParameter("@SDT", ab.newDatPhong.Sdt);
                var TienCoc  = new SqlParameter("@TienCoc", ab.newDatPhong.TienDatCoc);
                var NgayNhan = new SqlParameter("@NgayNhan", ab.newDatPhong.ThoiGianNhanPhongDuKien.ToShortDateString());
                var NgayTra  = new SqlParameter("@NgayTra", ab.newDatPhong.ThoiGianTraPhongDuKien.ToShortDateString());

                _Context.Database.ExecuteSqlRaw(
                    $"EXECUTE  dbo.AddDatPhong @Tenkh , @DiaChi, @CMND, @SDT,@TienCoc,@NgayNhan ='{ab.newDatPhong.ThoiGianNhanPhongDuKien.ToShortDateString()}',@NgayTra ='{ab.newDatPhong.ThoiGianTraPhongDuKien.ToShortDateString()}'", Tenkh, DiaChi, CMND, SDT, TienCoc);

                // xoa sestion
                lstsDichVuCart = null;
                HttpContext.Session.Set("ssPhongCart", lstsDichVuCart);
                lstsPhongCart = null;
                HttpContext.Session.Set("ssPhongCart", lstsPhongCart);


                return(RedirectToAction("Index", "DatPhongs", new { area = "Admin" }));
            }
            return(RedirectToAction("Index", "DatPhongCart", new { area = "Admin" }));
        }
Exemplo n.º 3
0
        // xác nhận đặt phòng
        public async Task <IActionResult> XacNhanDatPhong(DatPhongCartVM ab)
        {
            if (ModelState.IsValid)
            {
                // lấy đc id vừa add vào db : đã lấy đc
                _Context.Add(ab.newDatPhong);
                await _Context.SaveChangesAsync();

                int newDatPhongId = ab.newDatPhong.Id;

                #region Phong

                // list Id Phong
                List <int> lstsPhongCart = HttpContext.Session.Get <List <int> >("ssPhongCart");
                // xác định số dòng cần thêm cho mỗi phòng
                var soNgay = (int)(ab.newDatPhong.ThoiGianTraPhongDuKien.Date - ab.newDatPhong.ThoiGianNhanPhongDuKien.Date).TotalDays;
                var thoiGianinChiTietDatPhong = ab.newDatPhong.ThoiGianTraPhongDuKien.Date;
                for (int j = 0; j < soNgay; j++)
                {
                    foreach (var i in lstsPhongCart)
                    {
                        var objChiTietDatPhong = new ChiTietDatPhong
                        {
                            DatPhongId  = newDatPhongId,
                            PhongId     = i,
                            TrangThaiId = 1,
                            ThoiGian    = thoiGianinChiTietDatPhong
                        };
                        // nếu không tồn tại cùng ngày cùng tháng thì ghi vô
                        var IsTonTai = from m in _Context.ChiTietDatPhongs
                                       where m == objChiTietDatPhong
                                       select m;
                        if (IsTonTai.Count() != 0)
                        {
                            break;
                        }
                        _Context.ChiTietDatPhongs.Add(objChiTietDatPhong);
                        await _Context.SaveChangesAsync();
                    }
                    thoiGianinChiTietDatPhong.AddDays(1);
                }

                #endregion

                #region dichvu

                List <int> lstsDichVuCart = HttpContext.Session.Get <List <int> >("ssDichVuCart");

                foreach (var i in lstsDichVuCart)
                {
                    var objChiTietDichVuDatPhong = new ChiTietDichVuDatPhong()
                    {
                        DatPhongId = newDatPhongId,
                        DichVuId   = i,
                        SoLuong    = 1 // đang test mặc định số lượng dịch vụ là 1;
                    };
                    _Context.ChiTietDichVuDatPhongs.Add(objChiTietDichVuDatPhong);
                    await _Context.SaveChangesAsync();
                }
                #endregion
            }
            return(RedirectToAction("Index", "DatPhongs", new { area = "Admin" }));
        }