public async Task <List <CongViecDto> > GetAll(DanhSachCongViecInput input)
        {
            var UserCache = await _globalCache.GetUserCache((long)AbpSession.UserId);

            if (UserCache.Id == 0)
            {
                return(new List <CongViecDto>());
            }

            var query = from CongViec in _congViecRepository.GetAll()
                        .WhereIf(input.TrangThaiIds.Length > 0, w => input.TrangThaiIds.ToList().Contains(w.TrangThaiId))
                        .WhereIf(UserCache.IsCustomer, w => w.KhachHangId == UserCache.CustomerId)
                        .WhereIf(!UserCache.IsCustomer, w => w.NhanVienId == AbpSession.UserId)
                        join DichVu in _dichVuRepository.GetAll() on CongViec.DichVuId equals DichVu.Id into J1
                        from DichVu in J1.DefaultIfEmpty()
                        join NhomDichVu in _nhomDichVuRepository.GetAll() on DichVu.NhomDichVuId equals NhomDichVu.Id into J6
                        from NhomDichVu in J6.DefaultIfEmpty()

                        join TramDichVu in _tramDichVuRepository.GetAll() on CongViec.TramDichVuId equals TramDichVu.Id into J5
                        from TramDichVu in J5.DefaultIfEmpty()

                        join NhanVien in _nhanVienRepository.GetAll() on CongViec.NhanVienId equals NhanVien.Id into J2
                        from NhanVien in J2.DefaultIfEmpty()

                        join TinhThanh in _tinhThanhRepository.GetAll() on CongViec.DiaChiTinhThanhId equals TinhThanh.Id into J3
                        from TinhThanh in J3.DefaultIfEmpty()

                        join QuanHuyen in _quanHuyenRepository.GetAll() on CongViec.DiaChiQuanHuyenId equals QuanHuyen.Id into J4
                        from QuanHuyen in J4.DefaultIfEmpty()

                        select new
            {
                CongViec,
                NhomDichVuId   = NhomDichVu != null ? NhomDichVu.Id : 0,
                NhomDichVuName = NhomDichVu.Name,
                DichVuName     = DichVu.Name,
                TramDichVuName = TramDichVu.Name,
                NhanVienName   = NhanVien.Name,
                NhanVienPhone  = NhanVien.PhoneNumber,
                TinhThanhName  = TinhThanh.Name,
                QuanHuyenName  = QuanHuyen.Name
            };

            var CongViecs = await query.OrderBy(o => o.CongViec.NgayGioHen).Skip((input.Page - 1) * 10).Take(10).ToListAsync();

            var CongViecDtos = new List <CongViecDto>();

            foreach (var item in CongViecs)
            {
                var CongViec = ObjectMapper.Map <CongViecDto>(item.CongViec);

                if (item.NhomDichVuId > 0)
                {
                    CongViec.NhomDichVuId = item.NhomDichVuId;
                }
                CongViec.NhomDichVuName = item.NhomDichVuName;
                CongViec.DichVuName     = item.DichVuName;
                CongViec.TramDichVuName = item.TramDichVuName;
                CongViec.NhanVienName   = item.NhanVienName;
                CongViec.NhanVienPhone  = item.NhanVienPhone;
                CongViec.DiaChi        += string.IsNullOrWhiteSpace(item.QuanHuyenName) ? "" : ", " + item.QuanHuyenName;
                CongViec.DiaChi        += string.IsNullOrWhiteSpace(item.TinhThanhName) ? "" : ", " + item.TinhThanhName;
                CongViec.TrangThaiName  = item.CongViec.TrangThaiId >= 0 && GlobalModel.TrangThaiCongViec.ContainsKey((int)item.CongViec.TrangThaiId) ? GlobalModel.TrangThaiCongViec[(int)item.CongViec.TrangThaiId] : "";

                CongViec.Image1          = string.IsNullOrWhiteSpace(CongViec.Image1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.Image1);
                CongViec.Image2          = string.IsNullOrWhiteSpace(CongViec.Image2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.Image2);
                CongViec.Image3          = string.IsNullOrWhiteSpace(CongViec.Image3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.Image3);
                CongViec.ImageHoanThanh1 = string.IsNullOrWhiteSpace(CongViec.ImageHoanThanh1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageHoanThanh1);
                CongViec.ImageHoanThanh2 = string.IsNullOrWhiteSpace(CongViec.ImageHoanThanh2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageHoanThanh2);
                CongViec.ImageHoanThanh3 = string.IsNullOrWhiteSpace(CongViec.ImageHoanThanh3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageHoanThanh3);
                CongViec.ImageKhachHang1 = string.IsNullOrWhiteSpace(CongViec.ImageKhachHang1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageKhachHang1);
                CongViec.ImageKhachHang2 = string.IsNullOrWhiteSpace(CongViec.ImageKhachHang2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageKhachHang2);
                CongViec.ImageKhachHang3 = string.IsNullOrWhiteSpace(CongViec.ImageKhachHang3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", item.CongViec.TimeId, CongViec.ImageKhachHang3);

                CongViecDtos.Add(CongViec);
            }

            return(CongViecDtos);
        }
        public async Task <CongViecDto> Get(long Id)
        {
            var UserCache = await _globalCache.GetUserCache((long)AbpSession.UserId);

            if (UserCache.Id == 0)
            {
                throw new UserFriendlyException(L("UserIsNotLogin"));
            }

            var query = await(from CongViec in _congViecRepository.GetAll().Where(w => w.Id == Id)
                              .WhereIf(UserCache.IsCustomer, w => w.KhachHangId == UserCache.CustomerId)
                              .WhereIf(!UserCache.IsCustomer, w => w.NhanVienId == AbpSession.UserId)

                              join DichVu in _dichVuRepository.GetAll() on CongViec.DichVuId equals DichVu.Id into J1
                              from DichVu in J1.DefaultIfEmpty()
                              join NhomDichVu in _nhomDichVuRepository.GetAll() on DichVu.NhomDichVuId equals NhomDichVu.Id into J6
                              from NhomDichVu in J6.DefaultIfEmpty()

                              join TramDichVu in _tramDichVuRepository.GetAll() on CongViec.TramDichVuId equals TramDichVu.Id into J2
                              from TramDichVu in J2.DefaultIfEmpty()

                              join NhanVien in _nhanVienRepository.GetAll() on CongViec.NhanVienId equals NhanVien.Id into J3
                              from NhanVien in J3.DefaultIfEmpty()

                              join TinhThanh in _tinhThanhRepository.GetAll() on CongViec.DiaChiTinhThanhId equals TinhThanh.Id into J4
                              from TinhThanh in J4.DefaultIfEmpty()

                              join QuanHuyen in _quanHuyenRepository.GetAll() on CongViec.DiaChiQuanHuyenId equals QuanHuyen.Id into J5
                              from QuanHuyen in J5.DefaultIfEmpty()

                              select new
            {
                CongViec,
                NhomDichVuId   = NhomDichVu != null ? NhomDichVu.Id : 0,
                NhomDichVuName = NhomDichVu.Name,
                DichVuName     = DichVu.Name,
                TramDichVuName = TramDichVu.Name,
                NhanVienName   = NhanVien.Name,
                NhanVienPhone  = NhanVien.PhoneNumber,
                TinhThanhName  = TinhThanh.Name,
                QuanHuyenName  = QuanHuyen.Name
            }).FirstOrDefaultAsync();

            if (query == null)
            {
                throw new UserFriendlyException(L("CongViecIsNotFound"));
            }

            var result = ObjectMapper.Map <CongViecDto>(query.CongViec);

            if (query.NhomDichVuId > 0)
            {
                result.NhomDichVuId = query.NhomDichVuId;
            }
            result.NhomDichVuName = query.NhomDichVuName;
            result.DichVuName     = query.DichVuName;
            result.TramDichVuName = query.TramDichVuName;
            result.NhanVienName   = query.NhanVienName;
            result.NhanVienPhone  = query.NhanVienPhone;
            result.DiaChi        += string.IsNullOrWhiteSpace(query.QuanHuyenName) ? "" : ", " + query.QuanHuyenName;
            result.DiaChi        += string.IsNullOrWhiteSpace(query.TinhThanhName) ? "" : ", " + query.TinhThanhName;
            result.TrangThaiName  = query.CongViec.TrangThaiId >= 0 && GlobalModel.TrangThaiCongViec.ContainsKey((int)query.CongViec.TrangThaiId) ? GlobalModel.TrangThaiCongViec[(int)query.CongViec.TrangThaiId] : "";

            result.Image1          = string.IsNullOrWhiteSpace(result.Image1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.Image1);
            result.Image2          = string.IsNullOrWhiteSpace(result.Image2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.Image2);
            result.Image3          = string.IsNullOrWhiteSpace(result.Image3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.Image3);
            result.ImageHoanThanh1 = string.IsNullOrWhiteSpace(result.ImageHoanThanh1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageHoanThanh1);
            result.ImageHoanThanh2 = string.IsNullOrWhiteSpace(result.ImageHoanThanh2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageHoanThanh2);
            result.ImageHoanThanh3 = string.IsNullOrWhiteSpace(result.ImageHoanThanh3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageHoanThanh3);
            result.ImageKhachHang1 = string.IsNullOrWhiteSpace(result.ImageKhachHang1) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageKhachHang1);
            result.ImageKhachHang2 = string.IsNullOrWhiteSpace(result.ImageKhachHang2) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageKhachHang2);
            result.ImageKhachHang3 = string.IsNullOrWhiteSpace(result.ImageKhachHang3) ? "" : string.Format("/Common/CongViecs/{0}/{1}", query.CongViec.TimeId, result.ImageKhachHang3);

            // Lấy danh sách hạng mục công việc
            result.DanhSachHangMuc = await(from CongViecHangMuc in _congViecHangMucRepository.GetAll().Where(w => w.CongViecId == query.CongViec.Id)
                                           join DanhMucHangMuc in _hangMucRepository.GetAll() on CongViecHangMuc.HangMucId equals DanhMucHangMuc.Id

                                           select new CongViecHangMucDto
            {
                HangMucId = DanhMucHangMuc.Id,
                Name      = DanhMucHangMuc.Name,
                DonViTinh = DanhMucHangMuc.DonViTinh,
                SoLuong   = CongViecHangMuc.SoLuong,
                DonGia    = CongViecHangMuc.DonGia,
                ThanhTien = CongViecHangMuc.ThanhTien
            }).ToListAsync();

            // Tạm tính thành tiền của công việc bằng cách lấy tổng
            result.ThanhTien = result.PhuPhi ?? 0 + result.DanhSachHangMuc.Sum(s => s.ThanhTien);

            return(result);
        }