public ActionResult Index()
        {
            var pagingRequest = GetSinglePagingRequest();
            var applications  = Core.GetApplications(pagingRequest);

            if (applications.Items == null || applications.Items.Count == 0)
            {
                ErrorNotification(Resources.Application.No_Applications);
                return(Redirect(Url.AddApplication()));
            }

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

            var users = Core.GetUsers();

            foreach (var application in applicationsViewModel.Applications)
            {
                var user = users.Items.FirstOrDefault(u => u.Id == application.DefaultUserId);

                //if the default user has been deleted, update it here to the current user
                if (user == null)
                {
                    var app = Core.Session.Raven.Load <Application>(Application.GetId(application.Id));
                    app.DefaultUserId = Core.AppContext.CurrentUser.Id;
                    user = Core.AppContext.CurrentUser;
                }

                application.RuleMatchFactory = _matchRuleFactoryFactory.Create(application.RuleMatchFactory).Name;
                application.DefaultUser      = "******".FormatWith(user.FirstName, user.LastName);
            }

            return(View(applicationsViewModel));
        }
Example #2
0
        public ActionResult Index(IssueErrorsPostModel postModel)
        {
            //this is a bit of a hack but the paging URL is generated based on the page URL so if we get
            //an ajax call just assume it's error page
            if (Request.IsAjaxRequest())
            {
                return(Errors(new ErrorCriteriaPostModel
                {
                    Id = postModel.Id,
                }));
            }

            var viewModel = GetViewModel(postModel, GetSinglePagingRequest());

            if (viewModel == null)
            {
                Response.StatusCode = 404;
                return(View("NotFound", new IssueNotFoundViewModel {
                    Id = postModel.Id.GetFriendlyId()
                }));
            }

            if ((postModel.AppId == null || Application.GetId(postModel.AppId) != viewModel.Details.ApplicationId) ||
                (postModel.OrgId == null || Organisation.GetId(postModel.OrgId) != viewModel.Details.OrganisationId)
                )
            {
                var routeValues = Request.RequestContext.RouteData.Values;

                routeValues["appid"] = IdHelper.GetFriendlyId(viewModel.Details.ApplicationId);
                routeValues["orgid"] = IdHelper.GetFriendlyId(viewModel.Details.OrganisationId);

                return(RedirectToRoute(routeValues));
            }

            return(View(viewModel));
        }