public PartialViewResult NoiDungYKienCuaCacCoQuan(int id)//TacNghiepId
        {
            var result = YKienCoQuanRepository.GetByTacNghiepId(id);
            var user   = AuthInfo();

            if ((!User.IsInRole(RoleConstant.ADMIN) || !User.IsInRole(RoleConstant.SUPPER_ADMIN)) && !User.IsInRole(RoleConstant.PHONGNOIVU))
            {
                result = result.Where(x => x.CoQuanId == user.CoQuanId);

                ExecuteTryLogException(() =>
                {
                    //Update Muc od hoan thanh la da xem
                    TacNghiepTinhHinhThucHienRepository.UpdateIncrementMucDoHoanThanh(id, user.CoQuanId, user.UserName, EnumMucDoHoanThanh.DAXEM);
                });
            }

            result.ToList().ForEach(x =>
            {
                //Get files by yKienCoQuanId
                string path = EnsureFolderTacNghiepWithCoQuan(x.TacNghiepId, x.Id);
                x.JsonFiles = GetPathFiles(path);
            });

            var model = new InitNoiDungYKienCuaCacCoQuanViewModel
            {
                CoQuanId                = user.CoQuanId,
                TacNghiepId             = id,
                CacYKienCuaCoQuanResult = result,
            };

            return(PartialView("_PartialPageNoiDungYKien", model));
        }
        public JsonResult AddYKien(int tacNghiepId, int coQuanId, string guid, string noiDung)
        {
            return(ExecuteWithErrorHandling(() =>
            {
                return ExecuteResult(() =>
                {
                    var add = new TacNghiepYKienCoQuanResult
                    {
                        CoQuanId = coQuanId,
                        TacNghiepId = tacNghiepId,
                        NoiDung = noiDung,
                        CreatedBy = UserName,
                    };

                    //1. Save data to DB
                    var save = YKienCoQuanRepository.Add(add);

                    ExecuteTryLogException(() =>
                    {
                        //2. Change status muc do hoan thanh
                        TacNghiepTinhHinhThucHienRepository.UpdateIncrementMucDoHoanThanh(tacNghiepId, coQuanId, UserName, EnumMucDoHoanThanh.DANGTHUCHIEN);

                        //3. Move files temp into the upload folder
                        MoveFilesYKienCuaCacCoQuan(guid, tacNghiepId, add.Id);
                    });

                    return save;
                });
            }));
        }
        public ActionResult StatisticCoQuan(ValueSearchStatisticViewModel model)
        {
            var find = Find(model);

            var tinhHinhThucHienByTacNghiep = TacNghiepTinhHinhThucHienRepository.GetAllByListTacNghiepId(find.Select(x => x.Id));

            var result = tinhHinhThucHienByTacNghiep.GroupBy(x => new { x.CoQuanId, x.CoQuanInfo.Name }, y => y, (a, b) =>
            {
                return(new ResultStatisticByCoQuanViewModel
                {
                    TenCoQuan = a.Name,

                    NotExecuteResults = b.Where(x => x.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.CHUATHUHIEN).Select(s => new ResultCongViecThucHien
                    {
                        LinhVucString = s.TacNghiepInfo.LinhVucTacNghiepInfo.Name,
                        VanBan = GetPathFiles(EnsureFolderTacNghiep(s.TacNghiepId)),
                        NoiDungCongViec = s.TacNghiepInfo.NoiDung,
                        NgayHoanThanh = s.NgayHoanThanh,
                        NgayTao = s.TacNghiepInfo.NgayTao,
                        NgayHetHan = s.TacNghiepInfo.NgayHetHan,
                        TrangThai = "Chưa thực hiện",
                    }),
                    ExecutingResults = b.Where(w => w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DANGTHUCHIEN).Select(s => new ResultCongViecThucHien
                    {
                        LinhVucString = s.TacNghiepInfo.LinhVucTacNghiepInfo.Name,
                        VanBan = GetPathFiles(EnsureFolderTacNghiep(s.TacNghiepId)),
                        NoiDungCongViec = s.TacNghiepInfo.NoiDung,
                        NgayHoanThanh = s.NgayHoanThanh,
                        NgayTao = s.TacNghiepInfo.NgayTao,
                        NgayHetHan = s.TacNghiepInfo.NgayHetHan,
                        TrangThai = "Đang thực hiện",
                    }),
                    ExecutedResults = b.Where(w => (w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DATHUCHIEN || w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DAHOANHTHANH) &&
                                              w.NgayHoanThanh.CompareDate(w.TacNghiepInfo.NgayHetHan)).Select(s => new ResultCongViecThucHien
                    {
                        LinhVucString = s.TacNghiepInfo.LinhVucTacNghiepInfo.Name,
                        VanBan = GetPathFiles(EnsureFolderTacNghiep(s.TacNghiepId)),
                        NoiDungCongViec = s.TacNghiepInfo.NoiDung,
                        NgayHoanThanh = s.NgayHoanThanh,
                        NgayTao = s.TacNghiepInfo.NgayTao,
                        NgayHetHan = s.TacNghiepInfo.NgayHetHan,
                        TrangThai = "Đã thực hiện/đúng hạn",
                    }),
                    ExecutedOverResults = b.Where(w => (w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DATHUCHIEN || w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DAHOANHTHANH) &&
                                                  !w.NgayHoanThanh.CompareDate(w.TacNghiepInfo.NgayHetHan)).Select(s => new ResultCongViecThucHien
                    {
                        LinhVucString = s.TacNghiepInfo.LinhVucTacNghiepInfo.Name,
                        VanBan = GetPathFiles(EnsureFolderTacNghiep(s.TacNghiepId)),
                        NoiDungCongViec = s.TacNghiepInfo.NoiDung,
                        NgayHoanThanh = s.NgayHoanThanh,
                        NgayTao = s.TacNghiepInfo.NgayTao,
                        NgayHetHan = s.TacNghiepInfo.NgayHetHan,
                        TrangThai = "Đã thực hiện/trễ hạn",
                        IsDeadline = true
                    }),
                });
            });

            return(PartialView("_PartialPageStatisticCoQuan", result));
        }
        public ActionResult StatisticCongViec(ValueSearchStatisticViewModel model)
        {
            var find = Find(model);
            var tinhHinhThucHienByTacNghiep = TacNghiepTinhHinhThucHienRepository.GetAllByListTacNghiepId(find.Select(x => x.Id));

            var result = tinhHinhThucHienByTacNghiep.GroupBy(x => new { x.TacNghiepInfo.NoiDung, x.TacNghiepId, x.TacNghiepInfo.NgayTao, x.TacNghiepInfo.NgayHoanThanh }, y => y, (a, b) =>
            {
                return(new ResultStatisticByCongViecViewModel
                {
                    NgayTao = a.NgayTao,
                    Name = a.NoiDung,
                    NotExecuteResults = b.Where(w => (w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.CHUATHUHIEN ||
                                                      w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DAXEM)).Select(s => new ResultCoQuanThucHien
                    {
                        Name = s.CoQuanInfo.Name,
                    }),
                    ExecutingResults = b.Where(w => w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DANGTHUCHIEN).Select(s => new ResultCoQuanThucHien
                    {
                        Name = s.CoQuanInfo.Name,
                    }),
                    ExecutedResults = b.Where(w => w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DATHUCHIEN ||
                                              w.MucDoHoanThanhId == (int)EnumMucDoHoanThanh.DAHOANHTHANH).Select(s => new ResultCoQuanThucHien
                    {
                        Name = s.CoQuanInfo.Name,
                        NgayHoanThanh = a.NgayHoanThanh,
                    }),
                });
            });

            return(PartialView("_PartialPageStatisticCongViec", result));
        }
        public JsonResult EditYKien(int id, string noiDung)//id y kien co quan
        {
            return(ExecuteWithErrorHandling(() =>
            {
                var model = YKienCoQuanRepository.Single(id);
                model.NoiDung = noiDung;

                ExecuteTryLogException(() =>
                {
                    TacNghiepTinhHinhThucHienRepository.UpdateIncrementMucDoHoanThanh(model.TacNghiepId, model.CoQuanId, UserName, EnumMucDoHoanThanh.DANGTHUCHIEN);
                });

                return ExecuteResult(() =>
                {
                    return YKienCoQuanRepository.Update(model);
                });
            }));
        }
        public ActionResult Detail(int id)
        {
            //Get all co quan lien qua by tacNghiepId
            var cqlq   = TacNghiepTinhHinhThucHienRepository.GetAllByTacNghiepId(id);
            var lvtn   = LinhVucTacNghiepRepository.GetAll().Select(x => x.ToDataInfo());
            var result = TacNghiepRepository.Single(id);
            var ncq    = new List <InitCoQuanCoLienQuan>();

            NhomCoQuanRepository.GetAllWithChildren().ToList().ForEach(x =>
            {
                ncq.Add(new InitCoQuanCoLienQuan
                {
                    NhomCoQuan  = x.ToDataInfo(),
                    CoQuanInfos = x.CoQuanResult.Select(s => s.ToDataInfo()).ToList().Update((r) =>
                    {
                        r.ToList().ForEach(f =>
                        {
                            f.IsSelected = cqlq.Where(w => w.CoQuanId == f.Id).Any();
                        });
                    }).ToList(),
                });
            });

            //get files in folder upload
            var urlFiles = EnsureFolderTacNghiep(id);

            var detail = new DetailTacNghiepViewModel
            {
                Id                       = id,
                NgayHetHan               = result.NgayHetHan,
                NgayHoanThanh            = result.NgayHoanThanh,
                NgayTao                  = result.NgayTao,
                NoiDung                  = result.NoiDung,
                NoiDungYKienTraoDoi      = result.NoiDungTraoDoi,
                LinhVucTacNghiepId       = result.LinhVucTacNghiepInfo.Id,
                CoQuanInfos              = cqlq,
                LinhVucTacNghiepInfo     = lvtn,
                NhomCoQuanCoLienQuanInfo = ncq,
                JsonFiles                = GetPathFiles(urlFiles),
                IsRoleAdmin              = User.IsInRole(RoleConstant.SUPPER_ADMIN) || User.IsInRole(RoleConstant.ADMIN),
            };

            return(View(detail));
        }
        public PartialViewResult TinhHinhThucHien(int id)//TacNghiepId
        {
            var result = TacNghiepTinhHinhThucHienRepository.GetAll().Where(x => x.TacNghiepId == id);

            return(PartialView("_PartialPageTinhHinhThucHien", result));
        }