예제 #1
0
        /// <summary>
        /// Registers Pagination returned by the service tier.  Use when there are multiple paged tables and you need to
        /// specify an id.
        /// </summary>
        public bool RegisterPagingStatus(string pagingId, PagingStatus pagination, PageRequestWithSort pagingRequest, string itemNamePlural, out ActionResult result)
        {
            string queryStringParameter = PagingConstants.QueryStringParameters.PageNumber;

            if (pagingId != PagingConstants.DefaultPagingId)
            {
                queryStringParameter += pagingId;
            }

            int correctPageNumber;

            if (IsPaginationInvalid(pagingRequest.PageNumber, pagination.TotalPages, out correctPageNumber))
            {
                var parameters = new KeyValuePair <string, string>(queryStringParameter, correctPageNumber.ToString());
                result = new RedirectResult(HttpContext.Request.Url.ChangeQueryString(parameters));
                return(false);
            }
            var viewModel = PagingViewModelGenerator.Generate(pagingId, pagination, pagingRequest);

            viewModel.ItemNamePlural          = itemNamePlural;
            ViewData["pagination" + pagingId] = viewModel;

            result = null;
            return(true);
        }
예제 #2
0
        public Page <Group> GetGroups(PageRequestWithSort paging = null)
        {
            var groups = _getGroupsQuery.Invoke(new GetGroupsRequest
            {
                OrganisationId = AppContext.CurrentUser.OrganisationId,
                Paging         = new PageRequestWithSort(1, Configuration.MaxPageSize)
            }).Groups;

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

            return(groups.AdjustSetForPaging(paging));
        }
예제 #3
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));
        }
예제 #4
0
        public Page <User> GetUsers(PageRequestWithSort paging = null, string groupId = null)
        {
            var users = _getUsersQuery.Invoke(new GetUsersRequest
            {
                OrganisationId = AppContext.CurrentUser.OrganisationId,
                Paging         = new PageRequestWithSort(1, Configuration.MaxPageSize)
            }).Users;

            if (groupId.IsNotNullOrEmpty())
            {
                return(users.Filter(u => u.GroupIds.Contains(Group.GetId(groupId)), paging));
            }

            if (paging != null)
            {
                return(users.AdjustSetForPaging(paging));
            }

            return(users);
        }
예제 #5
0
        public static Page <TEntity> GetPage <TEntity, TIndex, TOrdProp>(this IDocumentSession session, PageRequestWithSort pageRequestWithSort, Expression <Func <TEntity, bool> > whereClause = null, Expression <Func <TEntity, TOrdProp> > orderByClause = null, bool orderDescending = false)
            where TIndex : AbstractIndexCreationTask, new()
        {
            RavenQueryStatistics stats;

            var entities = session.Query <TEntity, TIndex>();

            if (whereClause != null)
            {
                entities = entities.Where(whereClause);
            }

            //TODO: check this works ok
            entities = entities.Statistics(out stats);

            if (orderByClause != null)
            {
                entities = orderDescending ? entities.OrderByDescending(orderByClause) : entities.OrderBy(orderByClause);
            }

            var retrievedEntities = entities.Skip((pageRequestWithSort.PageNumber - 1) * pageRequestWithSort.PageSize).Take(pageRequestWithSort.PageSize).ToList();

            return(new Page <TEntity>(retrievedEntities, new PagingStatus(pageRequestWithSort.PageSize, pageRequestWithSort.PageNumber, stats.TotalResults)));
        }
예제 #6
0
        private ErrorCriteriaViewModel GetErrorsViewModel(ErrorCriteriaPostModel postModel, PageRequestWithSort paging, List <string> extraDataKeys)
        {
            var request = new GetApplicationErrorsRequest
            {
                OrganisationId = Core.AppContext.CurrentUser.OrganisationId,
                IssueId        = postModel.Id,
                Paging         = paging,
            };

            if (postModel.DateRange.IsNotNullOrEmpty())
            {
                string[] dates = postModel.DateRange.Split('|');

                DateTime startDate;
                DateTime endDate;

                if (DateTime.TryParse(dates[0], out startDate) && DateTime.TryParse(dates[1], out endDate))
                {
                    request.StartDate = startDate;
                    request.EndDate   = endDate.AddDays(1).AddMinutes(-1);
                }
            }

            var errors = _getApplicationErrorsQuery.Invoke(request).Errors;

            var model = new ErrorCriteriaViewModel
            {
                Action     = "errors",
                Controller = "issue",
                DateRange  = postModel.DateRange,
                Paging     = _pagingViewModelGenerator.Generate(PagingConstants.DefaultPagingId, errors.PagingStatus, paging),
                Errors     = errors.Items.Select(e => new ErrorInstanceViewModel
                {
                    Error      = e,
                    HideIssues = true,
                    PropertiesEligibleForRules = extraDataKeys,
                    //IsGetMethod = e.ContextData.ContainsKey("Request.HttpMethod") && e.ContextData["Request.HttpMethod"].ToLowerInvariant() == "get"
                }).ToList(),
                HideIssues     = true,
                Id             = postModel.Id,
                Sort           = paging.Sort,
                SortDescending = paging.SortDescending,
            };

            model.Paging.Tab = IssueTab.Details.ToString();
            return(model);
        }
예제 #7
0
        private IssueViewModel GetViewModel(IssueErrorsPostModel postModel, PageRequestWithSort paging, bool useSystemUser = false)
        {
            var issue = _getIssueQuery.Invoke(new GetIssueRequest
            {
                IssueId     = postModel.Id,
                CurrentUser = useSystemUser ? Errordite.Core.Domain.Organisation.User.System() : Core.AppContext.CurrentUser
            }).Issue;

            if (issue == null)
            {
                return(null);
            }

            var users        = Core.GetUsers();
            var applications = Core.GetApplications();
            var assignedUser = users.Items.FirstOrDefault(u => u.Id == issue.UserId);

            //if the assigned user has been deleted, update it to the current user
            if (assignedUser == null)
            {
                var updateIssue = Core.Session.Raven.Load <Issue>(issue.Id);
                updateIssue.UserId = Core.AppContext.CurrentUser.Id;
                assignedUser       = Core.AppContext.CurrentUser;
            }

            int ii = 0;

            var extraDataKeys = _getExtraDataKeysForIssueQuery.Invoke(new GetExtraDataKeysForIssueRequest
            {
                IssueId = issue.Id,
            }).Keys ?? new List <string>();

            var ruleViewModels = issue.Rules.OfType <PropertyMatchRule>().Select(r => new RuleViewModel
            {
                ErrorProperty  = r.ErrorProperty,
                StringOperator = r.StringOperator,
                Value          = r.Value,
                Index          = ii++,
                Properties     = _configuration.GetRuleProperties(r.ErrorProperty)
                                 .Union(extraDataKeys.Select(k => new SelectListItem
                {
                    Selected = r.ErrorProperty == k,
                    Text     = k,
                    Value    = k
                })),
            }).ToList();

            var updateViewModel = new UpdateIssueViewModel
            {
                ApplicationId           = issue.ApplicationId,
                Rules                   = ruleViewModels,
                Name                    = issue.Name,
                AdjustmentName          = GetAdjustmentRejectsName(issue.Name),
                IssueId                 = issue.Id,
                Users                   = users.Items.ToSelectList(u => u.Id, u => "{0} {1}".FormatWith(u.FirstName, u.LastName), sortListBy: SortSelectListBy.Text, selected: u => u.Id == issue.UserId),
                Statuses                = issue.Status.ToSelectedList(IssueResources.ResourceManager, false, issue.Status == IssueStatus.Unacknowledged ? IssueStatus.Acknowledged.ToString() : issue.Status.ToString()),
                UserId                  = issue.UserId,
                Status                  = issue.Status == IssueStatus.Unacknowledged ? IssueStatus.Acknowledged : issue.Status,
                NotifyFrequency         = issue.NotifyFrequency,
                Reference               = issue.Reference,
                NotificationFrequencies = FrequencyHours,
                Comment                 = null
            };

            var viewModel = new IssueViewModel
            {
                Details = new IssueDetailsViewModel
                {
                    ApplicationId    = issue.ApplicationId,
                    OrganisationId   = issue.OrganisationId,
                    ErrorCount       = issue.ErrorCount,
                    LastErrorUtc     = issue.LastErrorUtc,
                    FirstErrorUtc    = issue.CreatedOnUtc,
                    UserName         = assignedUser == null ? string.Empty : assignedUser.FullName,
                    ApplicationName  = applications.Items.First(a => a.Id == issue.ApplicationId).Name,
                    ErrorLimitStatus = IssueResources.ResourceManager.GetString("ErrorLimitStatus_{0}".FormatWith(issue.LimitStatus)),
                    TestIssue        = issue.TestIssue,
                    IssueId          = issue.Id,
                    Status           = issue.Status,
                    NotifyFrequency  = issue.NotifyFrequency,
                    Reference        = issue.Reference
                },
                Errors    = GetErrorsViewModel(postModel, paging, extraDataKeys),
                Update    = updateViewModel,
                Tab       = postModel.Tab,
                PublicUrl = "{0}/issue/public?token={1}".FormatWith(
                    _configuration.SiteBaseUrl,
                    _encryptor.Encrypt("{0}|{1}|{2}".FormatWith(
                                           Core.AppContext.CurrentUser.ActiveOrganisation.FriendlyId,
                                           issue.FriendlyId,
                                           Core.AppContext.CurrentUser.ActiveOrganisation.ApiKeySalt)).Base64Encode())
            };

            //dont let users set an issue to unacknowledged
            if (issue.Status != IssueStatus.Unacknowledged)
            {
                var statuses = viewModel.Update.Statuses.ToList();
                statuses.Remove(viewModel.Update.Statuses.First(s => s.Value == IssueStatus.Unacknowledged.ToString()));
                viewModel.Update.Statuses = statuses;
            }

            return(viewModel);
        }
예제 #8
0
 public bool RegisterPagingStatus(PagingStatus pagination, PageRequestWithSort pagingRequest, string itemNamePlural, out ActionResult result)
 {
     return(RegisterPagingStatus(PagingConstants.DefaultPagingId, pagination, pagingRequest, itemNamePlural, out result));
 }
예제 #9
0
 public bool RegisterPagingStatus(string pagingId, PagingStatus pagingStatus, PageRequestWithSort pagingRequest, out ActionResult overrideActionResult)
 {
     return(RegisterPagingStatus(pagingId, pagingStatus, pagingRequest, null, out overrideActionResult));
 }
예제 #10
0
 protected Page <TEntity> GetMasterPage <TEntity, TIndex, TOrdProp>(PageRequestWithSort paging, Expression <Func <TEntity, bool> > whereClause = null, Expression <Func <TEntity, TOrdProp> > orderByClause = null, bool orderDescending = false)
     where TIndex : AbstractIndexCreationTask, new()
 {
     return(Session.MasterRaven.GetPage <TEntity, TIndex, TOrdProp>(paging, whereClause, orderByClause, orderDescending));
 }
예제 #11
0
        public static Page <T> Filter <T>(this Page <T> original, Func <T, bool> filter, PageRequestWithSort paging)
        {
            var items = original.Items.Where(filter);

            return(new Page <T>(items.Skip((paging.PageNumber - 1) * paging.PageSize).Take(paging.PageSize).ToList(), new PagingStatus(original.PagingStatus.PageSize, original.PagingStatus.PageNumber, items.Count())));
        }
예제 #12
0
 public static Page <T> AdjustSetForPaging <T>(this Page <T> original, PageRequestWithSort paging)
 {
     return(new Page <T>(original.Items.Skip((paging.PageNumber - 1) * paging.PageSize).Take(paging.PageSize).ToList(), new PagingStatus(paging.PageSize, paging.PageNumber, original.PagingStatus.TotalItems)));
 }