예제 #1
0
        public List <SelectListItem> FindAllByWorkerRegionIDs(string programIDs, string regionIDs)
        {
            List <DropDownViewModel> subprogram = null;
            string        loggedinworkers       = String.Join(",", CurrentLoggedInWorkerRoleIDs);
            StringBuilder sqlQuery = new StringBuilder();

            sqlQuery.Append("SELECT JK.ID,JK.Name ");
            sqlQuery.Append("FROM WorkerInRoleNew AS WIR ");
            sqlQuery.Append("INNER JOIN WorkerRolePermissionNew AS WRP ON WIR.WorkerRoleID = WRP.WorkerRoleID ");
            sqlQuery.Append("INNER JOIN Permission AS P ON WRP.PermissionID = P.ID ");
            sqlQuery.Append("INNER JOIN PermissionRegion AS PR ON P.ID = PR.PermissionID ");
            sqlQuery.Append("INNER JOIN Jamatkhana AS JK ON PR.RegionID = JK.RegionID ");
            sqlQuery.Append("WHERE JK.IsActive = 1 ");
            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && CurrentLoggedInWorker.ID > 0)
            {
                sqlQuery.Append("AND WIR.WorkerID = " + CurrentLoggedInWorker.ID + " AND WIR.WorkerRoleID IN (" + loggedinworkers + ") ");
            }
            if (!string.IsNullOrEmpty(programIDs))
            {
                sqlQuery.Append("AND PR.ProgramID IN (" + programIDs + ") ");
            }
            if (!string.IsNullOrEmpty(regionIDs))
            {
                sqlQuery.Append("AND PR.RegionID IN (" + regionIDs + ") ");
            }
            sqlQuery.Append("GROUP BY JK.ID,JK.Name ");
            sqlQuery.Append("ORDER BY JK.Name ");

            subprogram = context.Database.SqlQuery <DropDownViewModel>(sqlQuery.ToString()).ToList();

            return(subprogram.AsEnumerable().Select(item => new SelectListItem()
            {
                Text = item.Name, Value = item.ID.ToString()
            }).ToList());
        }
        public bool HasPermission(List <int> workerRoleIDs, int workerID, int programID, int regionID, int subProgramID, int?JamatkhanaID, string areaName, string controllerName, string actionName, bool useCache = false)
        {
            //if (workerRoleIDs.Contains("1") || (workerRoleIDs.Contains(SiteConfigurationReader.RegionalManagerRoleID.ToString()) && CurrentLoggedInWorkerRegionIDs.Contains(regionID.ToString())))
            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1 || (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1 && CurrentLoggedInWorkerRegionIDs.IndexOf(regionID) != -1))
            {
                return(true);
            }

            workerRoleIDs = null;

            //List<WorkerInRole> workerRoleList = context.WorkerInRole.Join(context.WorkerSubProgram, left => left.ID, right => right.WorkerInRoleID, (left, right) => new { left, right }).Where(item => item.left.WorkerID == workerID && item.left.ProgramID == programID && item.left.RegionID == regionID && item.right.SubProgramID == subProgramID).Select(item => item.left).ToList();
            workerRoleIDs = GetWorkerInRoleNew(workerID, programID, regionID, subProgramID, JamatkhanaID);
            //List<WorkerInRoleNew> workerRoleList = GetWorkerInRoleNew(workerID,programID,regionID,subProgramID);
            //if (workerRoleList != null)
            //{
            //    foreach (WorkerInRoleNew workerRole in workerRoleList)
            //    {
            //        if (!workerRoleIDs.Contains(workerRole.WorkerRoleID.ToString()))
            //        {
            //            workerRoleIDs = workerRoleIDs.Concate(',', workerRole.WorkerRoleID.ToString());
            //        }
            //    }
            //}
            return(HasPermission(workerRoleIDs, areaName, controllerName, actionName, useCache));
        }
예제 #3
0
        public ActionResult LoadWorkNotes([DataSourceRequest] DataSourceRequest dsRequest, bool isGoalOnly, int caseGoalId, int caseActionId)
        {
            if (dsRequest.Filters == null)
            {
                dsRequest.Filters = new List <IFilterDescriptor>();
            }

            bool hasEditPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Edit, true);
            bool hasDeletePermission = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Delete, true);
            bool hasReadPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Read, true);
            bool IsUserAdminWorker   = CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1;
            //bool IsUserRegionalManager = workerroleRepository.IsWorkerRegionalAdmin() > 0 ? true : false;//CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1;

            //FilterDescriptor newDesc = new FilterDescriptor("CaseID", FilterOperator.IsEqualTo, caseId);
            //dsRequest.Filters.Add(newDesc);

            //var primaryWorkerID = GetPrimaryWorkerOfTheCase(caseId);

            //List<CaseGoalNew> caseGoalNew = caseGoalNewRepository.CaseGoalNewByCaseID(caseId);
            //return Json(caseGoalNew, JsonRequestBehavior.AllowGet);

            DataSourceResult result = goalActionWorkNoteRepository.Search(dsRequest, isGoalOnly, caseGoalId, caseActionId);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
        /// <summary>
        /// Load Case Worker DropDownList Asynchronously
        /// </summary>
        /// <returns>Data in JSON</returns>
        public JsonResult LoadCaseWorkerMemberListAjax(int caseID)
        {
            IEnumerable <SelectListItem> workerList;
            List <SelectListItem>        memberList = new List <SelectListItem>();

            //Case Worker
            workerList = workerRepository.FindAllByCaseID(caseID);//.Select(item => new { ID = item.ID, Name = item.FirstName + " " + item.LastName });

            //Case Member
            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1)
            {
                memberList = casememberRepository.FindAllByCaseIDForDropDownList(caseID);
            }
            else
            {
                memberList = casememberRepository.FindAllByCaseIDAndWorkerIDForDropDownList(caseID, CurrentLoggedInWorker.ID);
            }
            if (memberList != null && memberList.Count > 0)
            {
                memberList = memberList.Select(x => new SelectListItem {
                    Text = x.Text + "-M", Value = x.Value + "-M"
                }).ToList();
            }
            if (workerList != null && workerList.Count() > 0)
            {
                workerList = workerList.Select(x => new SelectListItem {
                    Text = x.Text + "-W", Value = x.Value + "-W"
                }).ToList();
            }
            if (memberList != null && memberList.Count > 0)
            {
                workerList = workerList.Concat(memberList);
            }
            return(Json(workerList, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
 // GET: CaseManagement/CaseTraining
 public ActionResult Index()
 {
     ViewBag.HasPermissionToAdd = false;
     if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1)
     {
         ViewBag.HasPermissionToAdd = true;
     }
     return(View());
 }
예제 #6
0
        public DataSourceResult Search(DataSourceRequest dsRequest, int caseId, int workerId, int?caseMemberId)
        {
            if (dsRequest.Filters == null)
            {
                dsRequest.Filters = new List <IFilterDescriptor>();
            }
            if (caseMemberId.HasValue && caseMemberId > 0)
            {
                FilterDescriptor filterDescriptor = new FilterDescriptor("CaseMemberID", FilterOperator.IsEqualTo, caseMemberId.Value);
                dsRequest.Filters.Add(filterDescriptor);
            }
            bool hasReadPermission     = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMemberProfile, Constants.Actions.Read, true);
            bool hasEditPermission     = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMemberProfile, Constants.Actions.Edit, true);
            bool hasDeletePermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMemberProfile, Constants.Actions.Delete, true);
            bool IsUserAdminWorker     = CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1;
            bool IsUserRegionalManager = CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1;

            List <CaseAssessment> caseAssessmentList = context.CaseAssessment
                                                       //.Join(context.CaseWorkerMemberAssignment, left => left.CaseMemberID, right => right.CaseMemberID, (left, right) => new { left, right })
                                                       //.Where(item => item.left.CaseMember.CaseID == caseId && item.right.CaseWorker.WorkerID == workerId)
                                                       .Where(item => item.CaseMember.CaseID == caseId)
                                                       //<JL:Comment:06/18/2017>
                                                       //.Where(item => context.CaseWorkerMemberAssignment.Where(worker => worker.CaseWorker.WorkerID == workerId).Select(member => member.CaseMemberID).Contains(item.CaseMemberID) || IsUserAdminWorker)
                                                       .OrderByDescending(item => item.CreateDate).AsEnumerable().ToList()
                                                       .Select(
                caseassessment => new CaseAssessment()
            {
                ID                      = caseassessment.ID,
                CaseMemberID            = caseassessment.CaseMemberID,
                AssessmentTypeID        = caseassessment.AssessmentTypeID,
                AssessmentTypeName      = caseassessment.AssessmentType != null ? caseassessment.AssessmentType.Name : "",
                MemberStatusID          = caseassessment.MemberStatusID,
                DocumentedByID          = caseassessment.DocumentedByID,
                DocumentedByName        = caseassessment.DocumentedBy != null && caseassessment.DocumentedBy.Worker != null ? caseassessment.DocumentedBy.Worker.FirstName + " " + caseassessment.DocumentedBy.Worker.LastName : "",
                CaseMemberName          = caseassessment.CaseMember != null ? caseassessment.CaseMember.FirstName + " " + caseassessment.CaseMember.LastName : string.Empty,
                StartDate               = caseassessment.StartDate,
                EndDate                 = caseassessment.EndDate,
                ReasonsForDischargeName = caseassessment.ReasonsForDischarge != null ? caseassessment.ReasonsForDischarge.Name : "",
                CaseID                  = caseId,
                HasPermissionToRead     = hasReadPermission ? "" : "display:none;",
                //HasPermissionToEdit = IsUserAdminWorker || (caseassessment.AssessmentTypeID != 2 && hasEditPermission) || IsUserRegionalManager ? "" : "display:none;",
                HasPermissionToEdit   = IsUserAdminWorker || hasEditPermission || IsUserRegionalManager ? "" : "display:none;",
                HasPermissionToDelete = hasDeletePermission ? "" : "display:none;"
            }
                ).ToList();

            if (caseAssessmentList != null)
            {
                foreach (CaseAssessment caseAssessment in caseAssessmentList)
                {
                    caseAssessment.QualityOfLifeNames = string.Join(",", context.CaseAssessmentLivingCondition.Where(item => item.CaseAssessmentID == caseAssessment.ID).Select(item => item.QualityOfLife.Name));
                }
            }
            DataSourceResult dsResult = caseAssessmentList.ToDataSourceResult(dsRequest);

            return(dsResult);
        }
예제 #7
0
        public BaseModel CloseAction(string ids)
        {
            int       totalSelected    = 0;
            int       totalUpdated     = 0;
            int       perrmissionCount = 0;
            BaseModel statusModel      = new BaseModel();

            if (ids.IsNotNullOrEmpty())
            {
                string[] arrayIds = ids.ToStringArray(',');
                foreach (string id in arrayIds)
                {
                    totalSelected++;
                    CaseAction caseAction = Find(id.ToInteger(true));
                    if (caseAction.CreatedByWorkerID != CurrentLoggedInWorker.ID && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
                    {
                        perrmissionCount++;
                    }
                    else
                    {
                        if (caseAction != null && !caseAction.IsCompleted)
                        {
                            caseAction.IsCompleted    = true;
                            caseAction.LastUpdateDate = DateTime.Now;
                            totalUpdated++;
                        }
                        else
                        {
                            Remove(caseAction);
                        }
                    }
                }
                Save();
            }
            if (totalSelected == 0)
            {
                statusModel.ErrorMessage = "Please select at least one action to close";
            }
            else if (totalSelected > 0 && totalUpdated > 0 && totalUpdated == totalSelected)
            {
                statusModel.SuccessMessage = "All the selected actions have been closed successfully";
            }
            else if (totalSelected > 0 && totalUpdated == 0)
            {
                statusModel.ErrorMessage = "All the selected actions are already closed";
            }
            else if (totalSelected > 0 && totalUpdated > 0 && totalUpdated != totalSelected)
            {
                statusModel.SuccessMessage = totalUpdated + " out of " + totalSelected + " selected actions have been closed successfully";
            }
            if (perrmissionCount > 0)
            {
                statusModel.ErrorMessage = "Some of the actions are not closed as you do not have permission for this action";
            }
            return(statusModel);
        }
예제 #8
0
        public bool HasPermission(List <int> workerRoleIds, string areaName, string controllerName, string actionName, bool useCache = false)
        {
            try
            {
                if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1)
                {
                    return(true);
                }
                areaName       = areaName.ToLower();
                controllerName = controllerName.ToLower();
                actionName     = actionName.ToLower();
                WorkerRoleActionPermission permission = null;
                if (useCache)
                {
                    List <WorkerRoleActionPermission> permissionList = WebHelper.CurrentSession.Content.WorkerRoleActionPermissionList;
                    if (permissionList == null || (permissionList != null && permissionList.Count == 0))
                    {
                        permissionList = context.WorkerRoleActionPermission.ToList();
                        WebHelper.CurrentSession.Content.WorkerRoleActionPermissionList = permissionList;
                    }

                    if (areaName.IsNotNullOrEmpty() && controllerName.IsNotNullOrEmpty() && actionName.IsNotNullOrEmpty())
                    {
                        permission = permissionList.FirstOrDefault(item => item.AreaName.ToLower() == areaName && item.ControllerName.ToLower() == controllerName && item.ActionName.ToLower() == actionName && CurrentLoggedInWorkerRoleIDs.IndexOf(item.WorkerRoleID) != -1);
                    }
                    else if (controllerName.IsNotNullOrEmpty() && actionName.IsNotNullOrEmpty())
                    {
                        permission = permissionList.FirstOrDefault(item => item.ControllerName.ToLower() == controllerName && item.ActionName.ToLower() == actionName && CurrentLoggedInWorkerRoleIDs.IndexOf(item.WorkerRoleID) != -1);
                    }
                    if (permission != null)
                    {
                        return(true);
                    }
                }
                else
                {
                    if (areaName.IsNotNullOrEmpty() && controllerName.IsNotNullOrEmpty() && actionName.IsNotNullOrEmpty())
                    {
                        permission = context.WorkerRoleActionPermission.FirstOrDefault(item => item.AreaName.ToLower() == areaName && item.ControllerName.ToLower() == controllerName && item.ActionName.ToLower() == actionName && CurrentLoggedInWorkerRoleIDs.IndexOf(item.WorkerRoleID) != -1);
                    }
                    else if (controllerName.IsNotNullOrEmpty() && actionName.IsNotNullOrEmpty())
                    {
                        permission = context.WorkerRoleActionPermission.FirstOrDefault(item => item.ControllerName.ToLower() == controllerName && item.ActionName.ToLower() == actionName && CurrentLoggedInWorkerRoleIDs.IndexOf(item.WorkerRoleID) != -1);
                    }
                    if (permission != null)
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
예제 #9
0
 /// <summary>
 /// Load Worker role  DropDownList Asynchronously
 /// </summary>
 /// <returns>Data in JSON</returns>
 public JsonResult LoadWorkerRoleAjax()
 {
     if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1)
     {
         return(Json(workerroleRepository.AllActiveForDropDownList.Where(item => item.Value != "1"), JsonRequestBehavior.AllowGet));
     }
     else
     {
         //return Json(workerroleRepository.AllActiveForDropDownList.Where(item => item.Value != "1" && item.Value != SiteConfigurationReader.RegionalAdministratorRoleID.ToString() && item.Value != SiteConfigurationReader.RegionalManagerRoleID.ToString()), JsonRequestBehavior.AllowGet);
         return(Json(workerroleRepository.GetWorkerRoleByWorkerID(), JsonRequestBehavior.AllowGet));
     }
 }        /// <summary>
예제 #10
0
 /// <summary>
 /// Load Case Member DropDownList Asynchronously
 /// </summary>
 /// <returns>Data in JSON</returns>
 public JsonResult LoadCaseMemberListAjax(int caseID)
 {
     if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1)
     {
         var data = casememberRepository.FindAllByCaseIDForDropDownList(caseID);
         return(Json(data, JsonRequestBehavior.AllowGet));
     }
     else
     {
         var data = casememberRepository.FindAllByCaseIDAndWorkerIDForDropDownList(caseID, CurrentLoggedInWorker.ID);
         return(Json(data, JsonRequestBehavior.AllowGet));
     }
 }
예제 #11
0
        public JsonResult LoadWorkerRoleByRegionProgram(int caseID)
        {
            var varCase = caseRepository.Find(caseID);

            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1)
            {
                return(Json(workerroleRepository.AllActiveForDropDownList.Where(item => item.Value != "1"), JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(workerroleRepository.GetWorkerRoleByProgramAndRegionID(varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID), JsonRequestBehavior.AllowGet));
            }
        }
예제 #12
0
        public DataSourceResult FindAllByRegion(Service searchService, DataSourceRequest paramDSRequest)
        {
            StringBuilder sqlQuery = new StringBuilder(@"SElect s.ID,
s.CreateDate,
s.LastUpdateDate,
s.Name,
s.Description,
s.IsActive,
sp.Name as ServiceProviderName,
r.Name as RegionName
from Service s
left join ServiceProvider sp on sp.ID =s.ServiceProviderID
left join Region r on r.ID =sp.RegionID where s.ID>0");

            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1)
            {
                sqlQuery.Append(@" AND RegionID in(
SElect RegionID from WorkerInRole
Where WorkerID=" + CurrentLoggedInWorker.ID + "");
                sqlQuery.Append(")");
            }
            if (searchService.ServiceTypeID == 1)
            {
                sqlQuery.Append(" And sp.IsExternal=0");
            }
            else if (searchService.ServiceTypeID == 2)
            {
                sqlQuery.Append(" And sp.IsExternal=1");
            }
            if (searchService.ServiceProviderID > 0)
            {
                sqlQuery.Append(" And s.ServiceProviderID=" + searchService.ServiceProviderID + "");
            }
            if (!string.IsNullOrEmpty(searchService.Name))
            {
                sqlQuery.Append(" And s.Name='" + searchService.Name + "'");
            }
            if (!string.IsNullOrEmpty(searchService.Description))
            {
                sqlQuery.Append(" And s.Description='" + searchService.Description + "'");
            }
            if (searchService.RegionID > 0)
            {
                sqlQuery.Append(" And sp.RegionID=" + searchService.RegionID + "");
            }


            DataSourceResult dataSourceResult = context.Database.SqlQuery <ServiceListViewModel>(sqlQuery.ToString()).AsEnumerable().GroupBy(m => m.ID).Select(m => m.First()).ToDataSourceResult(paramDSRequest);

            return(dataSourceResult);
        }
예제 #13
0
        public ActionResult Index([DataSourceRequest(Prefix = "Grid")] DataSourceRequest dsRequest)
        {
            if (!ViewBag.HasAccessToAdminModule)
            {
                WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }));
            }
            //create a new instance of role
            ViewBag.IsWorkerAdministrator = (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 ? false : true);
            WorkerRole role = new WorkerRole();

            //return view result
            return(View(role));
        }
        public void FindVisiblity(int workerID,
                                  ref VisibilityStatus regionVisiblity,
                                  ref VisibilityStatus programVisiblity,
                                  ref VisibilityStatus subProgramVisiblity,
                                  ref VisibilityStatus caseVisiblity)
        {
            //List<WorkerRolePermissionNew> permissionList = context.WorkerInRoleNew.Join(context.WorkerRolePermissionNew, left => left.WorkerRoleID, right => right.WorkerRoleID, (left, right) => new { left, right }).
            //    Where(item => item.left.WorkerID == workerID).Select(item => item.right).ToList();

            //int count = permissionList.Where(item => item.Permission == 1 || item.Permission == 2 || item.Permission == 3 || item.Permission == 4 || item.Permission == 5 || item.Permission == 6 || item.Permission == 7 || item.Permission == 8).Count();
            //if (count > 0 && (regionVisiblity == VisibilityStatus.None || regionVisiblity == VisibilityStatus.UnDefined))
            //{
            //regionVisiblity = VisibilityStatus.Assigned;
            //}

            //count = permissionList.Where(item => item.Permission == 1 || item.Permission == 2 || item.Permission == 5 || item.Permission == 6 || item.Permission == 3 || item.Permission == 4 || item.Permission == 7 || item.Permission == 8).Count();
            //if (count > 0 && (programVisiblity == VisibilityStatus.None || programVisiblity == VisibilityStatus.UnDefined))
            //{
            //programVisiblity = VisibilityStatus.Assigned;
            //subProgramVisiblity = VisibilityStatus.Assigned;
            //}

            ////Case Visibility
            //count = permissionList.Where(item => item.Permission == 1 || item.Permission == 3 || item.Permission == 5 || item.Permission == 7).Count();
            //if (count > 0)
            //{
            //    caseVisiblity = VisibilityStatus.All;
            //}
            //count = permissionList.Where(item => item.Permission == 2 || item.Permission == 4 || item.Permission == 6 || item.Permission == 8).Count();
            //if (count > 0 && (caseVisiblity == VisibilityStatus.None || caseVisiblity == VisibilityStatus.UnDefined))
            //{
            //caseVisiblity = VisibilityStatus.Assigned;

            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1)
            {
                regionVisiblity     = VisibilityStatus.All;
                programVisiblity    = VisibilityStatus.All;
                subProgramVisiblity = VisibilityStatus.All;
                caseVisiblity       = VisibilityStatus.All;
            }
            else
            {
                regionVisiblity     = VisibilityStatus.Assigned;
                programVisiblity    = VisibilityStatus.Assigned;
                subProgramVisiblity = VisibilityStatus.Assigned;
                caseVisiblity       = VisibilityStatus.Assigned;
            }
            //}
        }
예제 #15
0
        public DataSourceResult Search(DataSourceRequest dsRequest, int caseId, int workerId, int?caseMemberId)
        {
            if (dsRequest.Filters == null)
            {
                dsRequest.Filters = new List <IFilterDescriptor>();
            }
            if (caseMemberId.HasValue && caseMemberId > 0)
            {
                FilterDescriptor filterDescriptor = new FilterDescriptor("CaseMemberID", FilterOperator.IsEqualTo, caseMemberId.Value);
                dsRequest.Filters.Add(filterDescriptor);
            }
            bool             hasReadPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMemberProfile, Constants.Actions.Read, true);
            bool             hasEditPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMemberProfile, Constants.Actions.Edit, true);
            bool             hasDeletePermission = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMemberProfile, Constants.Actions.Delete, true);
            bool             IsUserAdminWorker   = CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1;
            DataSourceResult dsResult            = context.CaseMemberProfile
                                                   //.Join(context.CaseWorkerMemberAssignment, left => left.CaseMemberID, right => right.CaseMemberID, (left, right) => new { left, right })
                                                   //.Where(item => item.left.CaseMember.CaseID == caseId && item.right.CaseWorker.WorkerID == workerId)
                                                   .Where(item => item.CaseMember.CaseID == caseId)
                                                   //<JL:Comment:06/18/2017>
                                                   //.Where(item => context.CaseWorkerMemberAssignment.Where(worker => worker.CaseWorker.WorkerID == workerId).Select(member => member.CaseMemberID).Contains(item.CaseMemberID) || IsUserAdminWorker)
                                                   .OrderByDescending(item => item.ProfileDate).ToList()
                                                   .AsEnumerable()
                                                   .Select(
                item => new CaseMemberProfile()
            {
                ID = item.ID,
                CreatedByWorkerName         = item.CreatedByWorker.FirstName + " " + item.CreatedByWorker.LastName,
                ProfileDate                 = item.ProfileDate,
                ProfileTypeName             = item.ProfileType != null ? item.ProfileType.Name : "",
                HighestLevelOfEducationName = item.HighestLevelOfEducation != null ? item.HighestLevelOfEducation.Name : "",
                AnnualIncomeName            = item.AnnualIncome != null ? item.AnnualIncome.Name : "",
                HousingQualityName          = item.HousingQuality != null ? item.HousingQuality.Name : "",
                HousingQualityNote          = item.HousingQualityNote,
                HealthCondition             = item.HealthCondition,
                Occupation          = item.Occupation,
                CaseID              = item.CaseMember.CaseID,
                CaseMemberID        = item.CaseMemberID,
                ProfileTypeID       = item.ProfileTypeID,
                HasPermissionToRead = IsUserAdminWorker || hasReadPermission ? "" : "display:none;",
                //HasPermissionToEdit = IsUserAdminWorker || (item.ProfileTypeID != 2 && hasEditPermission) ? "" : "display:none;",
                HasPermissionToEdit   = IsUserAdminWorker || hasEditPermission ? "" : "display:none;",
                HasPermissionToDelete = IsUserAdminWorker || hasDeletePermission ? "" : "display:none;"
            }
                ).ToDataSourceResult(dsRequest);

            return(dsResult);
        }
예제 #16
0
        public ActionResult DeleteAjax(int id)
        {
            //find the varCase in database
            BaseModel      statusModel = new BaseModel();
            TrainingModule varTraining = caseTrainingRepository.Find(id);

            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
            {
                statusModel.ErrorMessage = "You are not eligible to do this action";
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, statusModel) }));
            }
            try
            {
                //delete varCase from database
                caseTrainingRepository.Delete(id);
                caseTrainingRepository.Save();



                //set success message
                statusModel.SuccessMessage = "Training Module has been deleted successfully";
            }
            catch (CustomException ex)
            {
                statusModel.ErrorMessage = ex.UserDefinedMessage;
            }
            catch (Exception ex)
            {
                if (ex.Message == "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.")
                {
                    statusModel.SuccessMessage = "Training Module has been deleted successfully";
                }
                else
                {
                    ExceptionManager.Manage(ex);
                    statusModel.ErrorMessage = Constants.Messages.UnhandelledError;
                }
            }
            //return action status in json to display on a message bar
            if (!string.IsNullOrEmpty(statusModel.ErrorMessage))
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, statusModel) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, statusModel) }));
            }
        }
예제 #17
0
        public ActionResult IndexAjax([DataSourceRequest] DataSourceRequest dsRequest, int caseID)
        {
            if (dsRequest.Filters == null)
            {
                dsRequest.Filters = new List <IFilterDescriptor>();
            }

            bool hasEditPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Edit, true);
            bool hasDeletePermission = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Delete, true);
            bool hasReadPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Read, true);
            bool IsUserAdminWorker   = CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1;

            DataSourceResult result = caseStatusHistoryRepository.AllCaseStatusByCaseID(caseID).AsEnumerable().ToDataSourceResult(dsRequest);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
예제 #18
0
        public bool HasPermission(int caseId, List <int> workerRoleIDs, int workerID, int programID, int regionID, int subProgramID, string areaName, string controllerName, string actionName, bool useCache = false)
        {
            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1 || (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1 && CurrentLoggedInWorkerRegionIDs.IndexOf(regionID) != -1))
            {
                return(true);
            }
            bool isAssigned = false;
            int  count      = context.CaseWorker.Where(item => item.CaseID == caseId && item.WorkerID == workerID).Count();

            if (count > 0)
            {
                isAssigned = true;
            }
            if (isAssigned)
            {
                return(HasPermission(workerRoleIDs, workerID, programID, regionID, subProgramID, areaName, controllerName, actionName, useCache));
            }
            return(false);
        }
예제 #19
0
        public bool HasPermission(List <int> workerRoleIDs, int workerID, int programID, int regionID, int subProgramID, string areaName, string controllerName, string actionName, bool useCache = false)
        {
            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1 || (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1 && CurrentLoggedInWorkerRegionIDs.IndexOf(regionID) != -1))
            {
                return(true);
            }
            workerRoleIDs = null;
            List <WorkerInRole> workerRoleList = context.WorkerInRole.Join(context.WorkerSubProgram, left => left.ID, right => right.WorkerInRoleID, (left, right) => new { left, right }).Where(item => item.left.WorkerID == workerID && item.left.ProgramID == programID && item.left.RegionID == regionID && item.right.SubProgramID == subProgramID).Select(item => item.left).ToList();

            if (workerRoleList != null)
            {
                foreach (WorkerInRole workerRole in workerRoleList)
                {
                    if (workerRoleIDs.IndexOf(workerRole.WorkerRoleID) == -1)
                    {
                        workerRoleIDs.Add(workerRole.WorkerRoleID);
                    }
                }
            }
            return(HasPermission(workerRoleIDs, areaName, controllerName, actionName, useCache));
        }
        public bool HasPermission(int caseId, List <int> workerRoleIDs, int workerID, int programID, int regionID, int subProgramID, int?JamatkhanaID, string areaName, string controllerName, string actionName, bool useCache = false)
        {
            //if (workerRoleIDs.Contains("1") || (workerRoleIDs.Contains(SiteConfigurationReader.RegionalManagerRoleID.ToString()) && CurrentLoggedInWorkerRegionIDs.Contains(regionID.ToString())))
            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1 || (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1 && CurrentLoggedInWorkerRegionIDs.IndexOf(regionID) != -1))
            {
                return(true);
            }

            bool isAssigned = false;

            if (HasAllCasesPermissionAction(workerRoleIDs, workerID, programID, regionID, subProgramID, JamatkhanaID, areaName, controllerName, actionName) > 0)
            {
                //return HasPermission(workerRoleIDs, workerID, programID, regionID, subProgramID, JamatkhanaID, areaName, controllerName, actionName, useCache);
                return(true);
            }
            else
            {
                int count = context.CaseWorker.Where(item => item.CaseID == caseId && item.WorkerID == workerID).Count();
                if (count > 0)
                {
                    isAssigned = true;
                }
                if (isAssigned)
                {
                    return(HasPermission(workerRoleIDs, workerID, programID, regionID, subProgramID, JamatkhanaID, areaName, controllerName, actionName, useCache));
                }
            }
            //int count = context.CaseWorker.Where(item => item.CaseID == caseId && item.WorkerID == workerID).Count();
            //if (count > 0)
            //{
            //    isAssigned = true;
            //}
            //if (isAssigned)
            //{
            //    return HasPermission(workerRoleIDs, workerID, programID, regionID, subProgramID, areaName, controllerName, actionName, useCache);
            //}

            return(false);
        }
예제 #21
0
        public ActionResult Read(int id, int caseID)
        {
            //find the existing varCase from database
            Case varCase = caseRepository.Find(caseID);

            if (varCase == null)
            {
                return(RedirectToAction(Constants.Actions.Create, Constants.Controllers.Case, new { area = Constants.Areas.CaseManagement }));
            }

            ViewBag.HasAccessToAssignmentModule     = false;
            ViewBag.HasAccessToIndividualModule     = false;
            ViewBag.HasAccessToInitialContactModule = false;
            ViewBag.HasAccessToCaseAuditLogModule   = true;
            if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1)
            {
                ViewBag.HasAccessToAssignmentModule     = workerroleactionpermissionnewRepository.HasPermission(caseID, CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseWorker, Constants.Actions.Index, true);
                ViewBag.HasAccessToIndividualModule     = workerroleactionpermissionnewRepository.HasPermission(caseID, CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Index, true);
                ViewBag.HasAccessToInitialContactModule = workerroleactionpermissionnewRepository.HasPermission(caseID, CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseProgressNote, Constants.Actions.InitialContact, true);
            }
            else
            {
                ViewBag.HasAccessToAssignmentModule     = true;
                ViewBag.HasAccessToIndividualModule     = true;
                ViewBag.HasAccessToInitialContactModule = true;
            }

            bool hasAccess = workerroleactionpermissionnewRepository.HasPermission(caseID, CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Read, true);

            if (!hasAccess)
            {
                WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }));
            }

            CaseMember casemember = casememberRepository.Find(id);

            return(View(casemember));
        }
예제 #22
0
        public ActionResult EditorAjax(int id)
        {
            WorkerRole role = null;

            if (id > 0)
            {
                //find an existing role from database
                role = workerroleRepository.Find(id);
                if (role == null)
                {
                    //throw an exception if id is provided but data does not exist in database
                    return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "Role not found"));
                }
            }
            else
            {
                //create a new instance if id is not provided
                role = new WorkerRole();
            }
            ViewBag.IsWorkerAdministrator = (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 ? false : true);
            //return the html of editor to display on popup
            return(Content(this.RenderPartialViewToString(Constants.PartialViews.CreateOrEdit, role)));
        }
예제 #23
0
        public ActionResult IndexAjax([DataSourceRequest] DataSourceRequest dsRequest, int caseId)
        {
            if (dsRequest.Filters == null)
            {
                dsRequest.Filters = new List <IFilterDescriptor>();
            }

            bool hasEditPermission     = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Edit, true);
            bool hasDeletePermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Delete, true);
            bool hasReadPermission     = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Read, true);
            bool IsUserAdminWorker     = CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1;
            bool IsUserRegionalManager = workerroleRepository.IsWorkerRegionalAdmin() > 0 ? true : false;//CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1;

            FilterDescriptor newDesc = new FilterDescriptor("CaseID", FilterOperator.IsEqualTo, caseId);

            dsRequest.Filters.Add(newDesc);

            var primaryWorkerID = GetPrimaryWorkerOfTheCase(caseId);

            List <CaseWorker> caseworker = caseworkerRepository.FindAllByCaseID(caseId).Where(x => x.WorkerID == CurrentLoggedInWorker.ID).ToList();

            DataSourceResult result = casememberRepository.AllIncluding(caseId.ToInteger(true), casemember => casemember.CreatedByWorker,
                                                                        casemember => casemember.LastUpdatedByWorker, casemember => casemember.Case, casemember => casemember.RelationshipStatus,
                                                                        casemember => casemember.Language, casemember => casemember.Gender, casemember => casemember.Ethnicity,
                                                                        casemember => casemember.MaritalStatus, casemember => casemember.MemberStatus).OrderBy(item => item.LastUpdateDate).AsEnumerable().Select(casemember =>
                                                                                                                                                                                                                  new CaseMember()
            {
                ID                      = casemember.ID,
                CreateDate              = casemember.CreateDate,
                LastUpdateDate          = casemember.LastUpdateDate,
                CreatedByWorkerID       = casemember.CreatedByWorkerID,
                CreatedByWorkerName     = casemember.CreatedByWorker.FirstName + " " + casemember.CreatedByWorker.LastName,
                LastUpdatedByWorkerID   = casemember.LastUpdatedByWorkerID,
                LastUpdatedByWorkerName = casemember.LastUpdatedByWorker.FirstName + " " + casemember.LastUpdatedByWorker.LastName,
                IsArchived              = casemember.IsArchived,
                CaseID                  = casemember.CaseID,
                FirstName               = casemember.FirstName,
                LastName                = casemember.LastName,
                EnrollDate              = casemember.EnrollDate,
                RelationshipStatusID    = casemember.RelationshipStatusID,
                RelationshipStatusName  = casemember.RelationshipStatus != null ? casemember.RelationshipStatus.Name : String.Empty,
                LanguageID              = casemember.LanguageID,
                LanguageName            = casemember.Language != null ? casemember.Language.Name : String.Empty,
                DateOfBirth             = casemember.DateOfBirth,
                GenderID                = casemember.GenderID,
                GenderName              = casemember.Gender != null ? casemember.Gender.Name : String.Empty,
                EthnicityID             = casemember.EthnicityID,
                EthnicityName           = casemember.Ethnicity != null ? casemember.Ethnicity.Name : caseEthinicityRepository.FindEthnicityNames(casemember.ID),
                MaritalStatusID         = casemember.MaritalStatusID,
                MaritalStatusName       = casemember.MaritalStatus != null ? casemember.MaritalStatus.Name : String.Empty,
                MemberStatusID          = casemember.MemberStatusID,
                MemberStatusName        = casemember.MemberStatus != null ? casemember.MemberStatus.Name : String.Empty,
                IsPrimary               = casemember.IsPrimary,
                HasPermissionToEdit     = (((caseworker == null || caseworker.Count() == 0) && casemember.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID && !IsUserAdminWorker && !IsUserRegionalManager) ? "display:none;" : String.Empty),
                //HasPermissionToEdit = (((caseworker != null && caseworker.Count() > 0)
                //&& casemember.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID
                //&& IsUserNotAdminWorker && IsUserNotRegionalManager) ? "display:none;" : String.Empty),
                HasPermissionToRead   = hasReadPermission ? "" : "display:none;",
                HasPermissionToDelete = hasDeletePermission ? "" : "display:none;"
                                        //HasPermissionToEdit = casemember.MemberStatus!=null ? casemember.MemberStatus.Name.Contains("Closed") ? "display:none;" : String.Empty : String.Empty
            }).ToDataSourceResult(dsRequest);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
예제 #24
0
        public DataSourceResult Search(DataSourceRequest dsRequest, int caseId, int workerId, int?caseMemberId, bool isClosed)
        {
            if (dsRequest.Filters == null)
            {
                dsRequest.Filters = new List <IFilterDescriptor>();
            }
            if (caseMemberId.HasValue && caseMemberId > 0)
            {
                FilterDescriptor filterDescriptor = new FilterDescriptor("CaseMemberID", FilterOperator.IsEqualTo, caseMemberId.Value);
                dsRequest.Filters.Add(filterDescriptor);
            }
            bool hasReadPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoal, Constants.Actions.Read, true);
            bool hasEditPermission   = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoal, Constants.Actions.Edit, true);
            bool hasDeletePermission = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoal, Constants.Actions.Delete, true);
            //bool hasDeletePermission = IsCurrentLoggedInWorkerAdministrator;
            bool hasTrackGoalPermission = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoalProgress, Constants.Actions.Index, true);
            bool IsUserAdminWorker      = CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1;

            List <CaseSmartGoal> caseSmartGoalList = context.CaseSmartGoal
                                                     .Join(context.CaseGoal, left => left.CaseGoalID, right => right.ID, (left, right) => new { left, right })
                                                     //.Join(context.CaseWorkerMemberAssignment, secondleft => secondleft.right.CaseMemberID, secondright => secondright.CaseMemberID, (secondleft, secondright) => new { secondleft, secondright })
                                                     //.Where(item => item.secondleft.right.CaseMember.CaseID == caseId && item.secondright.CaseWorker.WorkerID == workerId)
                                                     .Where(item => item.right.CaseMember.CaseID == caseId)
                                                     //<JL:Comment:06/18/2017>
                                                     //.Where(item => context.CaseWorkerMemberAssignment.Where(worker => worker.CaseWorker.WorkerID == workerId).Select(member => member.CaseMemberID).Contains(item.right.CaseMemberID) || IsUserAdminWorker)
                                                     .OrderBy(item => item.left.StartDate)
                                                     .AsEnumerable()
                                                     .ToList()
                                                     .Select(
                casesmartgoal => new CaseSmartGoal()
            {
                ID                        = casesmartgoal.left.ID,
                CreateDate                = casesmartgoal.left.CreateDate,
                CaseMemberID              = casesmartgoal.right.CaseMemberID,
                CaseMemberName            = casesmartgoal.right.CaseMember.FirstName + " " + casesmartgoal.right.CaseMember.LastName,
                ServiceLevelOutcomeID     = casesmartgoal.left.ServiceLevelOutcomeID,
                ServiceLevelOutcomeName   = casesmartgoal.left.ServiceLevelOutcome != null ? casesmartgoal.left.ServiceLevelOutcome.Name : "",
                QualityOfLifeCategoryName = casesmartgoal.left.QualityOfLifeCategory != null ? casesmartgoal.left.QualityOfLifeCategory.Name : "",
                StartDate                 = casesmartgoal.left.StartDate,
                EndDate                   = casesmartgoal.left.EndDate,
                CaseID                    = caseId,
                IsCompleted               = casesmartgoal.left.IsCompleted,
                HasPermissionToRead       = hasReadPermission ? "" : "display:none;",
                HasPermissionToEdit       = hasEditPermission ? "" : "display:none;",
                HasPermissionToDelete     = hasDeletePermission ? "" : "display:none;",
                HasPermissionToTrackGoal  = hasTrackGoalPermission ? "" : "display:none;"
            }
                ).ToList();

            if (caseSmartGoalList != null)
            {
                foreach (CaseSmartGoal caseSmartGoal in caseSmartGoalList)
                {
                    caseSmartGoal.TotalActionCount = context.CaseAction.Where(item => item.CaseSmartGoalID == caseSmartGoal.ID && item.CaseSmartGoalServiceProviderID == null).Count();
                    caseSmartGoal.OpenActionCount  = context.CaseAction.Where(item => (item.CaseSmartGoalID == caseSmartGoal.ID && item.CaseSmartGoalServiceProviderID == null) && item.IsCompleted == false).Count();
                    caseSmartGoal.CloseActionCount = context.CaseAction.Where(item => (item.CaseSmartGoalID == caseSmartGoal.ID && item.CaseSmartGoalServiceProviderID == null) && item.IsCompleted == true).Count();
                    List <CaseSmartGoalAssignment> goalAssignmentList = context.CaseSmartGoalAssignment.Where(item => item.CaseSmartGoalID == caseSmartGoal.ID).ToList();
                    if (goalAssignmentList != null)
                    {
                        foreach (CaseSmartGoalAssignment goalAssignment in goalAssignmentList)
                        {
                            caseSmartGoal.SmartGoalName = caseSmartGoal.SmartGoalName.Concate(",", goalAssignment.SmartGoal.Name);
                        }
                    }
                }
            }
            if (isClosed)
            {
                if (dsRequest.Filters == null || (dsRequest.Filters != null && dsRequest.Filters.Count == 0))
                {
                    if (dsRequest.Filters == null)
                    {
                        dsRequest.Filters = new List <IFilterDescriptor>();
                    }
                }
                FilterDescriptor newFilterDescriptor = new FilterDescriptor("IsCompleted", FilterOperator.IsEqualTo, true);
                dsRequest.Filters.Add(newFilterDescriptor);
            }
            else
            {
                if (dsRequest.Filters == null || (dsRequest.Filters != null && dsRequest.Filters.Count == 0))
                {
                    if (dsRequest.Filters == null)
                    {
                        dsRequest.Filters = new List <IFilterDescriptor>();
                    }
                }
                FilterDescriptor newFilterDescriptor = new FilterDescriptor("IsCompleted", FilterOperator.IsEqualTo, false);
                dsRequest.Filters.Add(newFilterDescriptor);
            }
            DataSourceResult dsResult = caseSmartGoalList.ToDataSourceResult(dsRequest);

            return(dsResult);
        }
 public ActionResult Edit(CaseWorker caseworker, int caseId)
 {
     caseworker.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
     try
     {
         //validate data
         if (ModelState.IsValid)
         {
             var primaryWorkerID = GetPrimaryWorkerOfTheCase(caseworker.CaseID);
             if (caseworker.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID && CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
             {
                 WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                 //return Json(new { success = true, url = Url.Action(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }) });
                 return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }));
             }
             caseworkerRepository.InsertOrUpdate(caseworker);
             caseworkerRepository.Save();
             if (caseworker.CaseWorkerNote.ContactMethodID > 0)
             {
                 caseworker.CaseWorkerNote.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
                 caseworker.CaseWorkerNote.CaseID = caseworker.CaseID;
                 //caseMember.CaseWorkerNote.CaseStatusID = varCase.CaseStatusID;
                 //caseMember.CaseWorkerNote.ProgramID = varCase.ProgramID;
                 caseworker.CaseWorkerNote.IsFamily                 = true;
                 caseworker.CaseWorkerNote.IsFamilyMember           = false;
                 caseworker.CaseWorkerNote.WorkerNoteActivityTypeID = (int)WorkerNoteActivityType.CaseWorker;
                 //varCase.CaseWorkerNote.NoteDate = Convert.ToDateTime(varCase.ContactDate);
                 caseWorkerNoteRepository.InsertOrUpdate(caseworker.CaseWorkerNote);
                 caseWorkerNoteRepository.Save();
             }
             //return RedirectToAction(Constants.Views.Index, new { caseId = caseId });
             return(RedirectToAction(Constants.Actions.Index, Constants.Controllers.CaseSummary, new { caseID = caseId }));
         }
         else
         {
             foreach (var modelStateValue in ViewData.ModelState.Values)
             {
                 foreach (var error in modelStateValue.Errors)
                 {
                     caseworker.ErrorMessage = error.ErrorMessage;
                     break;
                 }
                 if (caseworker.ErrorMessage.IsNotNullOrEmpty())
                 {
                     break;
                 }
             }
         }
     }
     catch (CustomException ex)
     {
         caseworker.ErrorMessage = ex.UserDefinedMessage;
     }
     catch (Exception ex)
     {
         ExceptionManager.Manage(ex);
         caseworker.ErrorMessage = Constants.Messages.UnhandelledError;
     }
     ViewBag.PossibleCreatedByWorkers     = workerRepository.All;
     ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All;
     ViewBag.PossibleWorkers = workerRepository.All;
     //return view with error message if the operation is failed
     return(View(caseworker));
 }
예제 #26
0
        public DataSourceResult Search(DataSourceRequest dsRequest, int caseId, int workerId, int?caseMemberId)
        {
            if (dsRequest.Filters == null)
            {
                dsRequest.Filters = new List <IFilterDescriptor>();
            }
            if (caseMemberId.HasValue && caseMemberId > 0)
            {
                FilterDescriptor filterDescriptor = new FilterDescriptor("CaseMemberID", FilterOperator.IsEqualTo, caseMemberId.Value);
                dsRequest.Filters.Add(filterDescriptor);
            }
            bool hasReadPermission    = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseGoal, Constants.Actions.Read, true);
            bool hasEditPermission    = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseGoal, Constants.Actions.Edit, true);
            bool hasDeletePermission  = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseGoal, Constants.Actions.Delete, true);
            bool hasSetGoalPermission = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.CaseManagement, Constants.Controllers.CaseSmartGoal, Constants.Actions.Create, true);
            bool IsUserAdminWorker    = CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1;
            //DataSourceResult dsResult = context.CaseGoal
            //    //.Join(context.CaseWorkerMemberAssignment, left => left.CaseMemberID, right => right.CaseMemberID, (left, right) => new { left, right })
            //    //.Where(item => item.left.CaseMember.CaseID == caseId && item.right.CaseWorker.WorkerID == workerId)
            //    .Where(item => item.CaseMember.CaseID == caseId)
            //    .Where(item => context.CaseWorkerMemberAssignment.Where(worker => worker.CaseWorker.WorkerID == workerId).Select(member => member.CaseMemberID).Contains(item.CaseMemberID) || workerRoleIDs.Contains("1"))
            //    .OrderByDescending(item => item.CreateDate).ToList()
            //    .Select(
            //    caseGoal => new
            //    {
            //        caseGoal.ID,
            //        caseGoal.CaseMemberID,
            //        CaseMemberName = caseGoal.CaseMember.FirstName + " " + caseGoal.CaseMember.LastName,
            //        caseGoal.StartDate,
            //        caseGoal.EndDate,
            //        caseGoal.WishInLife,
            //        CaseID = caseId,
            //        HasPermissionToEdit = CurrentLoggedInWorkerRoleIDs.IndexOf(1) != -1 || hasEditPermission ? "" : "display:none;",
            //        HasPermissionToDelete = hasDeletePermission ? "" : "display:none;",
            //        HasPermissionToCreateSmartGoal = hasSetGoalPermission ? "" : "display:none;"
            //    }
            //    ).ToDataSourceResult(dsRequest);

            List <CaseGoal> caseGoalList = context.CaseGoal
                                           .Where(item => item.CaseMember.CaseID == caseId)
                                           //<JL:Comment:06/18/2017>
                                           //.Where(item => context.CaseWorkerMemberAssignment.Where(worker => worker.CaseWorker.WorkerID == workerId).Select(member => member.CaseMemberID).Contains(item.CaseMemberID) || IsUserAdminWorker)
                                           .OrderByDescending(item => item.CreateDate).AsEnumerable().ToList()
                                           .Select(
                caseGoal => new CaseGoal()
            {
                ID                             = caseGoal.ID,
                CaseMemberID                   = caseGoal.CaseMemberID,
                CaseMemberName                 = caseGoal.CaseMember.FirstName + " " + caseGoal.CaseMember.LastName,
                StartDate                      = caseGoal.StartDate,
                EndDate                        = caseGoal.EndDate,
                WishInLife                     = caseGoal.WishInLife,
                CaseID                         = caseId,
                HasPermissionToRead            = IsUserAdminWorker || hasReadPermission ? "" : "display:none;",
                HasPermissionToEdit            = IsUserAdminWorker || hasEditPermission ? "" : "display:none;",
                HasPermissionToDelete          = hasDeletePermission ? "" : "display:none;",
                HasPermissionToCreateSmartGoal = hasSetGoalPermission ? "" : "display:none;"
            }
                ).ToList();

            if (caseGoalList != null)
            {
                foreach (CaseGoal caseGoal in caseGoalList)
                {
                    List <CaseGoalLivingCondition> qolList = context.CaseGoalLivingCondition.Where(item => item.CaseGoalID == caseGoal.ID).ToList();
                    if (qolList != null)
                    {
                        foreach (CaseGoalLivingCondition qol in qolList)
                        {
                            caseGoal.QualityOfLifeCategoryNames = caseGoal.QualityOfLifeCategoryNames.Concate(",", qol.QualityOfLifeCategory.Name);
                        }
                    }
                }
            }

            return(caseGoalList.ToDataSourceResult(dsRequest));
        }
예제 #27
0
        public ActionResult DeleteAjax(int id)
        {
            //find the casemembercontact in database
            CaseMemberContact casemembercontact = casemembercontactRepository.Find(id);

            if (casemembercontact == null)
            {
                //set error message if it does not exist in database
                casemembercontact = new CaseMemberContact();
                casemembercontact.ErrorMessage = "CaseMemberContact not found";
            }
            else
            {
                try
                {
                    var primaryWorkerID = GetPrimaryWorkerOfTheCase(casemembercontact.CaseMember.CaseID);
                    if (casemembercontact.ID > 0 && casemembercontact.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID && CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
                    {
                        WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                        return(Json(new { success = true, url = Url.Action(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }) }));
                        //return RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty });
                    }
                    //delete casemembercontact from database
                    casemembercontactRepository.Delete(casemembercontact);
                    casemembercontactRepository.Save();
                    //set success message
                    casemembercontact.SuccessMessage = "Case Member Contact has been deleted successfully";
                }
                catch (CustomException ex)
                {
                    casemembercontact.ErrorMessage = ex.UserDefinedMessage;
                }
                catch (Exception ex)
                {
                    if (ex.Message == "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.")
                    {
                        casemembercontact.SuccessMessage = "Case Member Contact has been deleted successfully";
                    }
                    else
                    {
                        ExceptionManager.Manage(ex);
                        casemembercontact.ErrorMessage = Constants.Messages.UnhandelledError;
                    }
                }
            }
            //return action status in json to display on a message bar
            if (casemembercontact.ErrorMessage.IsNotNullOrEmpty())
            {
                return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, casemembercontact) }));
            }
            else
            {
                return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, casemembercontact) }));
            }
        }
예제 #28
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            object objCurrentActionName = string.Empty;

            this.RouteData.Values.TryGetValue("action", out objCurrentActionName);
            string currentActionName = objCurrentActionName.ToString(true).ToLower();

            ViewBag.HasAccessToAssignmentModule     = false;
            ViewBag.HasAccessToIndividualModule     = false;
            ViewBag.HasAccessToInitialContactModule = false;
            ViewBag.HasAccessToCaseAuditLogModule   = true;

            int caseId = 0;

            currentActionName = currentActionName.ToLower();
            if (!currentActionName.Contains("ajax") && !currentActionName.Contains("icon") && !currentActionName.Contains("logo") && !currentActionName.Contains("photo") && !currentActionName.Contains("uploadfile") && !currentActionName.Contains("removefile"))
            {
                if (filterContext.ActionParameters != null && filterContext.ActionParameters.Count > 0)
                {
                    if (filterContext.ActionParameters.ContainsKey("caseid"))
                    {
                        caseId = filterContext.ActionParameters["caseid"].ToInteger(true);
                    }
                }
                if (caseId == 0)
                {
                    caseId = Request.QueryString["caseid"].ToInteger(true);
                }
                ViewBag.CaseID = caseId;
                if (Request.QueryString["casememberid"].IsNotNullOrEmpty())
                {
                    ViewBag.CaseMemberID = Request.QueryString["casememberid"].ToInteger(true);
                }
                else
                {
                    ViewBag.CaseMemberID = 0;
                }
                if (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) != -1)
                {
                    WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                    RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = "" });
                }
                if (!currentActionName.Contains("ajax"))
                {
                    if (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1)
                    {
                        Case varCase = caseRepository.Find(caseId);
                        if (varCase != null)
                        {
                            ViewBag.HasAccessToAssignmentModule     = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseWorker, Constants.Actions.Index, true);
                            ViewBag.HasAccessToIndividualModule     = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseMember, Constants.Actions.Index, true);
                            ViewBag.HasAccessToInitialContactModule = workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, CurrentLoggedInWorker.ID, varCase.ProgramID, varCase.RegionID, varCase.SubProgramID, varCase.JamatkhanaID, Constants.Areas.CaseManagement, Constants.Controllers.CaseProgressNote, Constants.Actions.InitialContact, true);
                        }
                    }
                    else
                    {
                        ViewBag.HasAccessToAssignmentModule     = true;
                        ViewBag.HasAccessToIndividualModule     = true;
                        ViewBag.HasAccessToInitialContactModule = true;
                    }
                }
            }
            base.OnActionExecuting(filterContext);
        }
예제 #29
0
        public ActionResult Edit(CaseWorker caseworker)
        {
            caseworker.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
            try
            {
                //validate data
                if (ModelState.IsValid)
                {
                    var primaryWorkerID = GetPrimaryWorkerOfTheCase(caseworker.CaseID);
                    if (caseworker.CreatedByWorkerID != CurrentLoggedInWorker.ID && primaryWorkerID != CurrentLoggedInWorker.ID && CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1 && (CurrentLoggedInWorkerRoleIDs.IndexOf(SiteConfigurationReader.RegionalManagerRoleID) == -1))
                    {
                        WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action";
                        //return Json(new { success = true, url = Url.Action(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }) });
                        return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty }));
                    }
                    caseworkerRepository.InsertOrUpdate(caseworker);
                    caseworkerRepository.Save();
                    string selectedCaseMember = Request.Form["SelectedCaseMember"].ToString(true);
                    selectedCaseMember = selectedCaseMember.Replace("false", string.Empty);
                    string[] arraySelectedCaseMember             = selectedCaseMember.ToStringArray(',', true);
                    List <CaseWorkerMemberAssignment> assignment = caseworkermemberassignmentRepository.FindAllByCaseWorkerID(caseworker.ID);
                    if (arraySelectedCaseMember != null && arraySelectedCaseMember.Length > 0)
                    {
                        foreach (string caseMemberID in arraySelectedCaseMember)
                        {
                            if (assignment.Where(item => item.CaseMemberID == caseMemberID.ToInteger(true)).Count() == 0)
                            {
                                CaseWorkerMemberAssignment newCaseWorkerMemberAssignment = new CaseWorkerMemberAssignment()
                                {
                                    CaseMemberID          = caseMemberID.ToInteger(true),
                                    CaseWorkerID          = caseworker.ID,
                                    LastUpdateDate        = DateTime.Now,
                                    LastUpdatedByWorkerID = caseworker.LastUpdatedByWorkerID
                                };
                                caseworkermemberassignmentRepository.InsertOrUpdate(newCaseWorkerMemberAssignment);
                                caseworkermemberassignmentRepository.Save();
                            }
                        }
                    }

                    foreach (CaseWorkerMemberAssignment existingMember in assignment)
                    {
                        if (arraySelectedCaseMember == null || !arraySelectedCaseMember.Contains(existingMember.CaseMemberID.ToString(true)))
                        {
                            caseworkermemberassignmentRepository.Delete(existingMember);
                            caseworkermemberassignmentRepository.Save();
                        }
                    }
                    //if (caseworker.CaseWorkerNote.ContactMethodID > 0)
                    //{
                    //    caseworker.CaseWorkerNote.LastUpdatedByWorkerID = CurrentLoggedInWorker.ID;
                    //    caseworker.CaseWorkerNote.CaseID = caseworker.CaseID;
                    //    //caseMember.CaseWorkerNote.CaseStatusID = varCase.CaseStatusID;
                    //    //caseMember.CaseWorkerNote.ProgramID = varCase.ProgramID;
                    //    caseworker.CaseWorkerNote.IsFamily = true;
                    //    caseworker.CaseWorkerNote.IsFamilyMember = false;
                    //    caseworker.CaseWorkerNote.WorkerNoteActivityTypeID = (int)WorkerNoteActivityType.CaseWorker;
                    //    //varCase.CaseWorkerNote.NoteDate = Convert.ToDateTime(varCase.ContactDate);
                    //    caseWorkerNoteRepository.InsertOrUpdate(caseworker.CaseWorkerNote);
                    //    caseWorkerNoteRepository.Save();
                    //}
                    //return RedirectToAction(Constants.Views.Index, new { caseId = caseId });
                    return(RedirectToAction(Constants.Actions.Index, Constants.Controllers.CaseSummary, new { caseID = caseworker.CaseID }));
                }
                else
                {
                    foreach (var modelStateValue in ViewData.ModelState.Values)
                    {
                        foreach (var error in modelStateValue.Errors)
                        {
                            caseworker.ErrorMessage = error.ErrorMessage;
                            break;
                        }
                        if (caseworker.ErrorMessage.IsNotNullOrEmpty())
                        {
                            break;
                        }
                    }
                }
            }
            catch (CustomException ex)
            {
                caseworker.ErrorMessage = ex.UserDefinedMessage;
            }
            catch (Exception ex)
            {
                ExceptionManager.Manage(ex);
                caseworker.ErrorMessage = Constants.Messages.UnhandelledError;
            }
            ViewBag.PossibleCreatedByWorkers     = workerRepository.All;
            ViewBag.PossibleLastUpdatedByWorkers = workerRepository.All;
            ViewBag.PossibleWorkers = workerRepository.All;
            //return view with error message if the operation is failed
            return(View(caseworker));
        }
예제 #30
0
        //public string FindWorkerNameByCaseWorkerID(int caseWorkerID)
        //{
        //    return context.CaseWorker.Join(context.Worker, left => left.WorkerID, right => right.ID, (left, right) => new { left, right }).Where(item => item.left.ID == caseWorkerID).Select(item =>item.right.FirstName +" "+item.right.LastName).FirstOrDefault();

        //}

//        public DataSourceResult Search(WorkerSearchViewModel searchParameters, DataSourceRequest paramDSRequest)
//        {
//            bool IsCurrentUserNotAdminRole = (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1);
//            string hasEditPermission = (workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.WorkerManagement, Constants.Controllers.Worker, Constants.Actions.Edit, true)).ToDisplayStyle();
//            string hasDeletePermission = (workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.WorkerManagement, Constants.Controllers.Worker, Constants.Actions.Delete, true)).ToDisplayStyle();

//            DataSourceRequest dsRequest = paramDSRequest;
//            if (dsRequest == null)
//            {
//                dsRequest = new DataSourceRequest();
//            }
//            if (dsRequest.Filters == null || (dsRequest.Filters != null && dsRequest.Filters.Count == 0))
//            {
//                if (dsRequest.Filters == null)
//                {
//                    dsRequest.Filters = new List<IFilterDescriptor>();
//                }
//            }
//            if (dsRequest.Sorts == null || (dsRequest.Sorts != null && dsRequest.Sorts.Count == 0))
//            {
//                if (dsRequest.Sorts == null)
//                {
//                    dsRequest.Sorts = new List<SortDescriptor>();
//                }
//                SortDescriptor defaultSortExpression = new SortDescriptor("LastUpdateDate", System.ComponentModel.ListSortDirection.Descending);

//                dsRequest.Sorts.Add(defaultSortExpression);
//            }
//            if (dsRequest.PageSize == 0)
//            {
//                dsRequest.PageSize = Constants.CommonConstants.DefaultPageSize;
//            }
//            StringBuilder sqlQuery = new StringBuilder(@"SELECT DISTINCT
//                            W.ID,W.EmailAddress,W.IsActive, [W].[FirstName] + ' ' + [W].[LastName] [Name],
//                            '" + hasDeletePermission + @"' [HasPermissionToDelete],
//                            '" + hasEditPermission + @"' [HasPermissionToEdit]
//                            FROM Worker AS [W]
//                            LEFT JOIN WorkerInRoleNew WIR on W.ID = WIR.WorkerID
//                            LEFT JOIN WorkerRolePermissionNew WRP on WIR.WorkerRoleID = WRP.WorkerRoleID
//                            LEFT JOIN Permission AS P ON WRP.PermissionID = P.ID
//                            LEFT JOIN PermissionRegion AS PR ON P.ID = PR.PermissionID
//                            LEFT JOIN PermissionSubProgram AS PSP ON PR.ID = PSP.PermissionRegionID
//                            LEFT JOIN PermissionJamatkhana AS PJK ON PR.ID = PJK.PermissionRegionID
//                            WHERE [W].[ID] > 0 ");
//            if (IsCurrentUserNotAdminRole)
//            {
//                sqlQuery.Append(" AND [W].[ID] <> " + CurrentLoggedInWorker.ID + " ");
//            }
//            if (searchParameters.RegionID > 0)
//            {
//                searchParameters.RegionID = searchParameters.RegionID;
//                sqlQuery.Append(" AND [PR].[RegionID] =" + searchParameters.RegionID + "");
//            }
//            //else if (IsCurrentLoggedInWorkerRegionalAdministrator) //<JL:Comment:06/11/2017>
//            else if (IsCurrentUserNotAdminRole) //<JL:Add:06/11/2017>
//            {
//                StringBuilder regionquery = new StringBuilder();
//                regionquery.Append("SELECT DISTINCT PR.RegionID ");
//                regionquery.Append("FROM Worker AS [W] ");
//                regionquery.Append("LEFT JOIN WorkerInRoleNew WIR on W.ID = WIR.WorkerID ");
//                regionquery.Append("LEFT JOIN WorkerRolePermissionNew WRP on WIR.WorkerRoleID = WRP.WorkerRoleID ");
//                regionquery.Append("LEFT JOIN Permission AS P ON WRP.PermissionID = P.ID ");
//                regionquery.Append("LEFT JOIN PermissionRegion AS PR ON P.ID = PR.PermissionID ");
//                //regionquery.Append("WHERE [W].ID = " + CurrentLoggedInWorker.ID + " AND WIR.WorkerRoleID = " + SiteConfigurationReader.RegionalAdministratorRoleID); //<JL:Comment:06/11/2017>
//                regionquery.Append("WHERE [W].ID = " + CurrentLoggedInWorker.ID); //<JL:Add:06/11/2017>
//                searchParameters.RegionID = searchParameters.RegionID;
//                //sqlQuery.Append(" AND [PR].[RegionID] = (SELECT RegionID FROM WorkerInRoleNew WIR WHERE WorkerRoleID = " + SiteConfigurationReader.RegionalAdministratorRoleID + " AND WorkerID = " + CurrentLoggedInWorker.ID + ")");
//                sqlQuery.Append(" AND [PR].[RegionID] IN (" + regionquery.ToString() + ")");
//                sqlQuery.Append(" AND [W].[ID] !=1");
//            }
//            if (searchParameters.FirstName.IsNotNullOrEmpty())
//            {
//                searchParameters.FirstName = searchParameters.FirstName.Trim();
//                sqlQuery.Append(" AND [W].[FirstName] LIKE '%" + searchParameters.FirstName + "%'");
//            }

//            if (searchParameters.LastName.IsNotNullOrEmpty())
//            {
//                searchParameters.LastName = searchParameters.LastName.Trim();
//                sqlQuery.Append(" AND [W].[LastName] LIKE '%" + searchParameters.LastName + "%'");
//            }

//            if (searchParameters.RoleID > 0)
//            {
//                sqlQuery.Append(" AND [W].[ID] IN (SELECT [WorkerID] FROM WorkerInRoleNew WHERE WorkerRoleID = " + searchParameters.RoleID + ")");
//            }
//            if (searchParameters.ProgramID > 0)
//            {
//                sqlQuery.Append(" AND [PR].[ProgramID] =" + searchParameters.ProgramID + "");
//            }
//            else if (IsCurrentUserNotAdminRole) //<JL:Add:06/11/2017>
//            {
//                StringBuilder programquery = new StringBuilder();
//                programquery.Append("SELECT DISTINCT PR.ProgramID ");
//                programquery.Append("FROM Worker AS [W] ");
//                programquery.Append("INNER JOIN WorkerInRoleNew WIR on W.ID = WIR.WorkerID ");
//                programquery.Append("INNER JOIN WorkerRolePermissionNew WRP on WIR.WorkerRoleID = WRP.WorkerRoleID ");
//                programquery.Append("INNER JOIN Permission AS P ON WRP.PermissionID = P.ID ");
//                programquery.Append("INNER JOIN PermissionRegion AS PR ON P.ID = PR.PermissionID ");
//                programquery.Append("WHERE [W].ID = " + CurrentLoggedInWorker.ID);
//                searchParameters.ProgramID = searchParameters.ProgramID;

//                sqlQuery.Append(" AND [PR].[ProgramID] IN (" + programquery.ToString() + ")");
//                sqlQuery.Append(" AND [W].[ID] !=1");
//            }
//            if (IsCurrentUserNotAdminRole) //<JL:Add:06/11/2017>
//            {
//                StringBuilder subprogramquery = new StringBuilder();
//                subprogramquery.Append("SELECT DISTINCT PSP.SubProgramID ");
//                subprogramquery.Append("FROM Worker AS [W] ");
//                subprogramquery.Append("INNER JOIN WorkerInRoleNew WIR on W.ID = WIR.WorkerID ");
//                subprogramquery.Append("INNER JOIN WorkerRolePermissionNew WRP on WIR.WorkerRoleID = WRP.WorkerRoleID ");
//                subprogramquery.Append("INNER JOIN Permission AS P ON WRP.PermissionID = P.ID ");
//                subprogramquery.Append("INNER JOIN PermissionRegion AS PR ON P.ID = PR.PermissionID ");
//                subprogramquery.Append("INNER JOIN PermissionSubProgram AS PSP ON PR.ID = PSP.PermissionRegionID ");
//                subprogramquery.Append("WHERE [W].ID = " + CurrentLoggedInWorker.ID);

//                sqlQuery.Append(" AND [PSP].[SubProgramID] IN (" + subprogramquery.ToString() + ")");
//                sqlQuery.Append(" AND [W].[ID] !=1");

//                StringBuilder jkquery = new StringBuilder();
//                jkquery.Append("SELECT DISTINCT PJK.JamatkhanaID ");
//                jkquery.Append("FROM Worker AS [W] ");
//                jkquery.Append("INNER JOIN WorkerInRoleNew WIR on W.ID = WIR.WorkerID ");
//                jkquery.Append("INNER JOIN WorkerRolePermissionNew WRP on WIR.WorkerRoleID = WRP.WorkerRoleID ");
//                jkquery.Append("INNER JOIN Permission AS P ON WRP.PermissionID = P.ID ");
//                jkquery.Append("INNER JOIN PermissionRegion AS PR ON P.ID = PR.PermissionID ");
//                jkquery.Append("LEFT JOIN PermissionJamatkhana AS PJK ON PR.ID = PJK.PermissionRegionID ");
//                jkquery.Append("WHERE [W].ID = " + CurrentLoggedInWorker.ID);

//                sqlQuery.Append(" AND [PJK].[JamatkhanaID] IN (" + jkquery.ToString() + ")");
//            }

//            DataSourceResult dataSourceResult = context.Database.SqlQuery<WorkerListViewModel>(sqlQuery.ToString()).AsEnumerable().GroupBy(m=>m.ID).Select(m=>m.First()).ToDataSourceResult(dsRequest);

//            DataSourceRequest dsRequestTotalCountQuery = new DataSourceRequest();
//            dsRequestTotalCountQuery.Filters = dsRequest.Filters;
//            dataSourceResult.Total = context.Database.SqlQuery<WorkerListViewModel>(sqlQuery.ToString()).AsEnumerable().ToDataSourceResult(dsRequestTotalCountQuery).Data.AsQueryable().Count();
//            return dataSourceResult;
//        }

        public DataSourceResult Search(WorkerSearchViewModel searchParameters, DataSourceRequest paramDSRequest)
        {
            bool   IsCurrentUserNotAdminRole = (CurrentLoggedInWorkerRoleIDs.IndexOf(1) == -1);
            string hasEditPermission         = (workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.WorkerManagement, Constants.Controllers.Worker, Constants.Actions.Edit, true)).ToDisplayStyle();
            string hasDeletePermission       = (workerroleactionpermissionnewRepository.HasPermission(CurrentLoggedInWorkerRoleIDs, Constants.Areas.WorkerManagement, Constants.Controllers.Worker, Constants.Actions.Delete, true)).ToDisplayStyle();

            DataSourceRequest dsRequest = paramDSRequest;

            if (dsRequest == null)
            {
                dsRequest = new DataSourceRequest();
            }
            if (dsRequest.Filters == null || (dsRequest.Filters != null && dsRequest.Filters.Count == 0))
            {
                if (dsRequest.Filters == null)
                {
                    dsRequest.Filters = new List <IFilterDescriptor>();
                }
            }
            if (dsRequest.Sorts == null || (dsRequest.Sorts != null && dsRequest.Sorts.Count == 0))
            {
                if (dsRequest.Sorts == null)
                {
                    dsRequest.Sorts = new List <SortDescriptor>();
                }
                SortDescriptor defaultSortExpression = new SortDescriptor("LastUpdateDate", System.ComponentModel.ListSortDirection.Descending);

                dsRequest.Sorts.Add(defaultSortExpression);
            }
            if (dsRequest.PageSize == 0)
            {
                dsRequest.PageSize = Constants.CommonConstants.DefaultPageSize;
            }
            StringBuilder sqlQuery;

            sqlQuery = new StringBuilder(@"SELECT DISTINCT 
                            W.ID,W.EmailAddress,W.IsActive, [W].[FirstName] + ' ' + [W].[LastName] [Name],
                            '" + hasDeletePermission + @"' [HasPermissionToDelete],
                            '" + hasEditPermission + @"' [HasPermissionToEdit]
                            FROM Worker AS [W] ");

            if (IsCurrentUserNotAdminRole)
            {
                sqlQuery.Append(" INNER JOIN WorkerInRoleNew WIR on W.ID = WIR.WorkerID");
                sqlQuery.Append(" INNER JOIN WorkerRolePermissionNew WRP on WIR.WorkerRoleID = WRP.WorkerRoleID");

                if (searchParameters.RegionID > 0 || searchParameters.ProgramID > 0)
                {
                    sqlQuery.Append(" INNER JOIN PermissionRegion AS PR ON WRP.PermissionID = PR.PermissionID");
                    if (searchParameters.RegionID > 0)
                    {
                        sqlQuery.Append(" AND [PR].[RegionID] =" + searchParameters.RegionID + "");
                    }
                    if (searchParameters.ProgramID > 0)
                    {
                        sqlQuery.Append(" AND [PR].[ProgramID] =" + searchParameters.ProgramID + "");
                    }
                }

                sqlQuery.Append(" INNER JOIN (");
                sqlQuery.Append(" SELECT WRP.PermissionID");
                sqlQuery.Append(" FROM WorkerInRoleNew AS WIR ");
                sqlQuery.Append(" INNER JOIN WorkerRolePermissionNew WRP ON WIR.WorkerRoleID = WRP.WorkerRoleID");
                sqlQuery.Append(" WHERE [WIR].WorkerID = " + CurrentLoggedInWorker.ID + " ");
                sqlQuery.Append(" ) AS CW ON [WRP].[PermissionID] = CW.PermissionID");
            }
            else
            {
                sqlQuery.Append(" LEFT JOIN WorkerInRoleNew WIR on W.ID = WIR.WorkerID");
                sqlQuery.Append(" LEFT JOIN WorkerRolePermissionNew WRP on WIR.WorkerRoleID = WRP.WorkerRoleID");

                if (searchParameters.RegionID > 0 || searchParameters.ProgramID > 0)
                {
                    sqlQuery.Append(" LEFT JOIN PermissionRegion AS PR ON WRP.PermissionID = PR.PermissionID");
                    if (searchParameters.RegionID > 0)
                    {
                        sqlQuery.Append(" AND [PR].[RegionID] =" + searchParameters.RegionID + "");
                    }
                    if (searchParameters.ProgramID > 0)
                    {
                        sqlQuery.Append(" AND [PR].[ProgramID] =" + searchParameters.ProgramID + "");
                    }
                }
            }

            sqlQuery.Append(" WHERE [W].[ID] > 0 ");

            if (IsCurrentUserNotAdminRole)
            {
                sqlQuery.Append(" AND [W].[ID] NOT IN (" + CurrentLoggedInWorker.ID + ",1) ");
            }

            if (searchParameters.FirstName.IsNotNullOrEmpty())
            {
                searchParameters.FirstName = searchParameters.FirstName.Trim();
                sqlQuery.Append(" AND [W].[FirstName] LIKE '%" + searchParameters.FirstName + "%'");
            }

            if (searchParameters.LastName.IsNotNullOrEmpty())
            {
                searchParameters.LastName = searchParameters.LastName.Trim();
                sqlQuery.Append(" AND [W].[LastName] LIKE '%" + searchParameters.LastName + "%'");
            }

            if (searchParameters.RoleID > 0)
            {
                sqlQuery.Append(" AND [W].[ID] IN (SELECT [WorkerID] FROM WorkerInRoleNew WHERE WorkerRoleID = " + searchParameters.RoleID + ")");
            }

            DataSourceResult dataSourceResult = context.Database.SqlQuery <WorkerListViewModel>(sqlQuery.ToString()).AsEnumerable().GroupBy(m => m.ID).Select(m => m.First()).ToDataSourceResult(dsRequest);

            DataSourceRequest dsRequestTotalCountQuery = new DataSourceRequest();

            dsRequestTotalCountQuery.Filters = dsRequest.Filters;
            dataSourceResult.Total           = context.Database.SqlQuery <WorkerListViewModel>(sqlQuery.ToString()).AsEnumerable().ToDataSourceResult(dsRequestTotalCountQuery).Data.AsQueryable().Count();
            return(dataSourceResult);
        }