public async Task <IHttpActionResult> MakeUnitPlan2(
            OrganizationReference organization,
            int year,
            ReportingTerm reportingTerm,
            ReportingFrequency reportingFrequency)
        {
            try
            {
                if (!_userContext.CurrentUserIsSystemUser())
                {
                    return(Unauthorized());
                }

                if (organization == null)
                {
                    throw new ArgumentNullException(nameof(organization));
                }

                if (!_userContext.CurrentUserCanAccess(organization.Id))
                {
                    return(Unauthorized());
                }

                var cmd = new CreateUnitPlanCommand(organization, year, reportingTerm, reportingFrequency);
                await _endpointInstance().SendWithSignalRMetaData(cmd, Request);

                return(this.Accepted());
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(InternalServerError());
            }
        }
        public async Task <IHttpActionResult> DeleteOrganizationUser(int organizationUserId)
        {
            try
            {
                if (!_userContext.CurrentUserIsSystemUser())
                {
                    return(Unauthorized());
                }

                if (!_userContext.CurrentUserIsSystemAdmin())
                {
                    return(Unauthorized());
                }

                if (!_userContext.CurrentUserCanAccess(organizationUserId))
                {
                    return(Unauthorized());
                }

                var cmd = new DeleteOrganizationUserCommand(organizationUserId);
                await _endpointInstance().SendWithSignalRMetaData(cmd, Request);

                return(this.Accepted());
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                return(InternalServerError());
            }
        }
        public IHttpActionResult GetSearchResult([FromUri] AllReportSearchTerms searchTerms)
        {
            if (!_userContext.CurrentUserIsSystemUser())
            {
                return(Unauthorized());
            }

            if (searchTerms == null)
            {
                searchTerms = new AllReportSearchTerms();
            }

            if (searchTerms.Organization.HasValue && !_userContext.CurrentUserCanAccess(searchTerms.Organization.Value))
            {
                return(Unauthorized());
            }

            if (searchTerms.Parent.HasValue && !_userContext.CurrentUserCanAccess(searchTerms.Parent.Value))
            {
                return(Unauthorized());
            }

            return(_queryService.Search(searchTerms).ToJson(this));
        }