Esempio n. 1
0
        // GET: YeuCauTamUngLuongController
        public async Task <ActionResult> Index()
        {
            ICollection <YeuCauTamUngLuong> yeuCauTamUngLuongs = null;

            var phongNhanSu = await phongBanRepository.FindByName("Nhân sự");

            if (User.IsInRole("Nhân viên phòng nhân sự"))
            {
                yeuCauTamUngLuongs = (await _YeuCauTamUngLuongRepo.FindAll())
                                     .Where(q => q.NhanVienGuiYeuCau.MaPhongBan != phongNhanSu.MaPhongBan)
                                     .ToList();
            }
            else
            {
                yeuCauTamUngLuongs = await _YeuCauTamUngLuongRepo.FindAll();
            }


            var YeuCauTamUngLuongsModel = _mapper.Map <List <YeuCauTamUngLuongVM> >(yeuCauTamUngLuongs);

            foreach (var yeucau in YeuCauTamUngLuongsModel)
            {
                var phieuChi = await phieuChi_TamUngLuongRepository.FindByMaYeuCauTamUng(yeucau.MaYeuCau);

                if (phieuChi != null)
                {
                    if (phieuChi.MaNhanVienThuHoi != null)
                    {
                        yeucau.TinhTrangPheDuyet = PhieuChiStatusString[PhieuChiStatus.DaBiThuHoi];
                    }
                    else if (phieuChi.MaNhanVienChiTien != null)
                    {
                        yeucau.TinhTrangPheDuyet = PhieuChiStatusString[PhieuChiStatus.DaChiTien];
                    }
                }
            }

            var model = new AdminYeuCauTamUngLuongViewVM
            {
                TotalRequests   = YeuCauTamUngLuongsModel.Count,
                ApprovedRequets = YeuCauTamUngLuongsModel
                                  .Count(q => q.TinhTrangPheDuyet == YeuCauTamUngLuongStatusString[YeuCauTamUngLuongStatus.DaDuocChapThuan]),
                PendingRequests = YeuCauTamUngLuongsModel
                                  .Count(q => q.TinhTrangPheDuyet == YeuCauTamUngLuongStatusString[YeuCauTamUngLuongStatus.DangCho]),
                RejectedRequests = YeuCauTamUngLuongsModel
                                   .Count(q => q.TinhTrangPheDuyet == YeuCauTamUngLuongStatusString[YeuCauTamUngLuongStatus.DaBiTuChoi]),
                CancelledRequests = YeuCauTamUngLuongsModel
                                    .Count(q => q.TinhTrangPheDuyet == YeuCauTamUngLuongStatusString[YeuCauTamUngLuongStatus.DaBiHuy]),
                DaChiTienRequests = YeuCauTamUngLuongsModel
                                    .Count(q => q.TrangThaiPhieuChi == PhieuChiStatusString[PhieuChiStatus.DaChiTien]),

                YeuCauTamUngLuongs = YeuCauTamUngLuongsModel
            };

            return(View(model));
        }