Beispiel #1
0
        public Page <Application> GetApplications(PageRequestWithSort paging = null)
        {
            var applications = _getApplicationsQuery.Invoke(new GetApplicationsRequest
            {
                OrganisationId = AppContext.CurrentUser.OrganisationId,
                Paging         = new PageRequestWithSort(1, Configuration.MaxPageSize)
            }).Applications;

            if (paging == null)
            {
                return(applications);
            }

            return(applications.AdjustSetForPaging(paging));
        }
        public ActivateOrganisationResponse Invoke(ActivateOrganisationRequest request)
        {
            var organisation = Session.MasterRaven
                               .Include <Organisation>(o => o.RavenInstanceId)
                               .Load <Organisation>(request.OrganisationId);

            if (organisation == null)
            {
                return(new ActivateOrganisationResponse(request.OrganisationId, true));
            }

            organisation.RavenInstance = MasterLoad <RavenInstance>(organisation.RavenInstanceId);

            if (organisation.Status != OrganisationStatus.Suspended)
            {
                return(new ActivateOrganisationResponse(organisation.Id, true)
                {
                    Status = ActivateOrganisationStatus.AccountAlreadyActivate
                });
            }

            organisation.Status         = OrganisationStatus.Active;
            organisation.SuspendedOnUtc = null;

            using (Session.SwitchOrg(organisation))
            {
                //disable all applications
                var applications = _getApplicationsQuery.Invoke(new GetApplicationsRequest
                {
                    OrganisationId = organisation.Id,
                    Paging         = new PageRequestWithSort(1, _configuration.MaxPageSize)
                }).Applications;

                foreach (var application in applications.Items)
                {
                    application.IsActive = true;
                    Session.AddCommitAction(new FlushApplicationCacheCommitAction(_configuration, organisation, application.Id));
                }
            }

            Session.AddCommitAction(new FlushOrganisationCacheCommitAction(_configuration, organisation));

            return(new ActivateOrganisationResponse(organisation.Id)
            {
                Status = ActivateOrganisationStatus.Ok
            });
        }
Beispiel #3
0
        public ActionResult Applications(string organisationId)
        {
            using (SwitchOrgScope(organisationId))
            {
                var pagingRequest = GetSinglePagingRequest();

                var applications = _getApplicationsQuery.Invoke(new GetApplicationsRequest
                {
                    OrganisationId = organisationId,
                    Paging         = pagingRequest
                }).Applications;

                if (applications.Items == null || applications.Items.Count == 0)
                {
                    return(View(new ApplicationsViewModel()));
                }

                var applicationsViewModel = new ApplicationsViewModel
                {
                    Applications = applications.Items.Select(Mapper.Map <Application, ApplicationViewModel>).ToList(),
                    Paging       =
                        _pagingViewModelGenerator.Generate(PagingConstants.DefaultPagingId,
                                                           applications.PagingStatus, pagingRequest),
                    SystemView = true
                };

                var users = _getUsersQuery.Invoke(new GetUsersRequest
                {
                    OrganisationId = organisationId,
                    Paging         = new PageRequestWithSort(1, Core.Configuration.MaxPageSize)
                }).Users;

                foreach (var application in applicationsViewModel.Applications)
                {
                    var user = users.Items.FirstOrDefault(u => u.Id == application.DefaultUserId);
                    application.RuleMatchFactory = _matchRuleFactoryFactory.Create(application.RuleMatchFactory).Name;
                    application.DefaultUser      = user == null
                                                  ? "Unknown"
                                                  : "{0} {1}".FormatWith(user.FirstName, user.LastName);
                }
                return(View(applicationsViewModel));
            }
        }
        public SuspendOrganisationResponse Invoke(SuspendOrganisationRequest request)
        {
            var organisation = Session.MasterRaven
                               .Include <Organisation>(o => o.RavenInstanceId)
                               .Load <Organisation>(request.OrganisationId);

            if (organisation == null)
            {
                return(new SuspendOrganisationResponse(request.OrganisationId, true));
            }

            organisation.RavenInstance = MasterLoad <RavenInstance>(organisation.RavenInstanceId);

            if (organisation.Status == OrganisationStatus.Suspended)
            {
                return(new SuspendOrganisationResponse(organisation.Id, true)
                {
                    Status = SuspendOrganisationStatus.AccountAlreadySuspended
                });
            }

            using (Session.SwitchOrg(organisation))
            {
                organisation.Status           = OrganisationStatus.Suspended;
                organisation.SuspendedReason  = request.Reason;
                organisation.SuspendedMessage = request.Message;
                organisation.SuspendedOnUtc   = DateTime.UtcNow;

                var applications = _getApplicationsQuery.Invoke(new GetApplicationsRequest
                {
                    OrganisationId = organisation.Id,
                    Paging         = new PageRequestWithSort(1, _configuration.MaxPageSize)
                }).Applications;

                foreach (var application in applications.Items)
                {
                    application.IsActive = false;
                    Session.AddCommitAction(new FlushApplicationCacheCommitAction(_configuration, organisation, application.Id));
                }

                Session.AddCommitAction(new FlushOrganisationCacheCommitAction(_configuration, organisation));

                var primaryUser = Session.Raven.Load <User>(organisation.PrimaryUserId);

                if (primaryUser != null)
                {
                    Session.AddCommitAction(new SendMessageCommitAction(
                                                new AccountSuspendedEmailInfo
                    {
                        OrganisationName = organisation.Name,
                        UserName         = primaryUser.FirstName,
                        SuspendedReason  = request.Reason.GetDescription()
                    },
                                                _configuration.GetNotificationsQueueAddress(organisation.RavenInstanceId)));
                }
            }

            return(new SuspendOrganisationResponse(organisation.Id)
            {
                Status = SuspendOrganisationStatus.Ok
            });
        }