public void AddSlotTuan(IEnumerable <LichDangKy> listDangKyTrongNgay, DangKyTheoTuanRow row, List <SlotIndex> skipEmptySlotIndexes, int rowIndex, int colIndex, Phong phong, DateTime ngayHienTai) { if (listDangKyTrongNgay.Count() > 0) { row.Slots.Add(new DangKyTheoTuanSlot { IsDay = true, isRoom = false, NgayHienTai = ngayHienTai, TenPhong = phong.TenPhong, IDPhong = phong.ID, IsDangKy = true, TieuDe = "Co nguoi dat", ListDangKyTrongNgay = listDangKyTrongNgay.ToList() }); } else if (skipEmptySlotIndexes.IsEmptySlotRequired(colIndex, rowIndex)) { row.Slots.Add(new DangKyTheoTuanSlot { NgayHienTai = ngayHienTai, IsDay = true, IsDangKy = false, TenPhong = phong.TenPhong, IDPhong = phong.ID, isRoom = false, TieuDe = "No one booking" }); } }
public DangKyTheoTuanTable GetDangKyTheoTuan(int IdKhuNha, int IdLoaiPhong, DateTime ngayHienTai) { List <WeeklyHeader> listDayofWeek = GetListCacNgayTrongTuan(ngayHienTai); IEnumerable <Phong> phongs = _dangKyPhongHopRepository.GetPhong(); if (IdKhuNha > 0) { phongs = phongs.Where(x => x.IDKhuNha == IdKhuNha); } if (IdLoaiPhong > 0) { phongs = phongs.Where(x => x.IDLoaiPhong == IdLoaiPhong); } DangKyTheoTuanTable tuanTable = new DangKyTheoTuanTable(); tuanTable.Today = ngayHienTai; tuanTable.Rows = new List <DangKyTheoTuanRow>(); DateTime dauTuan = ngayHienTai.Date; DateTime cuoiTuan = ngayHienTai.Date.AddDays(7).AddSeconds(-1); IEnumerable <LichDangKy> ListDangKyTheoTuan = _dangKyPhongHopRepository.GetLichDangKyTheoKhoangThoiGian(dauTuan, cuoiTuan); int rowIndex = 0; var skipEmptySlotIndexes = new List <SlotIndex>(); foreach (var phong in phongs) { DangKyTheoTuanRow row = new DangKyTheoTuanRow(); row.WeekDays = new List <WeeklyHeader>(); row.Slots = new List <DangKyTheoTuanSlot>(); row.Slots.Add(new DangKyTheoTuanSlot() { TenPhong = phong.TenPhong, isRoom = true }); int colIndex = 0; foreach (var day in listDayofWeek) { row.WeekDays.Add(new WeeklyHeader { Weekday = day.Weekday, DayOfWeek = day.DayOfWeek }); } for (var ngayDauTuan = dauTuan; ngayDauTuan <= cuoiTuan; ngayDauTuan = ngayDauTuan.AddDays(1)) { var listDangKyTrongNgay = ListDangKyTheoTuan.Where(d => d.NgayDangKy == ngayDauTuan && d.IDPhong == phong.ID).ToList(); AddSlotTuan(listDangKyTrongNgay, row, skipEmptySlotIndexes, rowIndex, colIndex, phong, ngayDauTuan); colIndex++; } tuanTable.Rows.Add(row); rowIndex++; } return(tuanTable); }