/// <summary> /// Displays notifications. /// </summary> /// <param name="app">The Notifications app.</param> /// <param name="query">Query object for paging.</param> public override ActionResult Get(Notifications app, Query query) { app.Result = NotificationService.Search(new NotificationQuery(query) { OrderBy = "Id DESC", SearchRead = null, Top = PageSizes.First() }); if (Request.IsAjaxRequest()) { return(PartialView("_Notifications", app.Result)); } return(View(app)); }
public ActionResult Messenger(int?id, QueryOptions opts) { // limit page size to 25 opts.Top = Math.Min(opts.Top ?? MAX_PAGE_SIZE, MAX_PAGE_SIZE); var model = new Messenger { ConversationId = id }; if (model.ConversationId != null) { // get selected conversation model.Conversation = ConversationService.Get(model.ConversationId.Value); if (model.Conversation == null) { ThrowResponseException(HttpStatusCode.NotFound, $"Conversation with id {model.ConversationId.Value} not found"); } } else { // get most recent conversation model.Conversation = ConversationService.Search(new ConversationQuery { OrderBy = "PinnedAt DESC, LastMessageAt DESC", Top = 1 }).FirstOrDefault(); } if (model.Conversation != null) { if (model.ConversationId != null) { // mark conversation as read (if needed) if (model.Conversation.ReadAt == null) { model.Conversation = ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow); } else if (model.Conversation.ReadAt < model.Conversation.LastMessage?.CreatedAt) { // NOTE: do not assign the read conversation to model.Conversation since that will prevent rendering of the "New messages" separator ConversationService.SetRead(model.Conversation.Id, DateTime.UtcNow); } } // get first page of messages (and reverse them for easier rendering in correct order) model.Messages = ConversationService.GetMessages(model.Conversation.Id, new QueryOptions { Top = MAX_PAGE_SIZE }); model.Messages.Reverse(); } // Meetings model.ZoomEnabled = ConfigurationService.ZoomMeetings; model.TeamsEnabled = ConfigurationService.TeamsMeetings; // NOTE: we load conversations last so that selected conversation does not appear unread in the list var query = new ConversationQuery(opts); query.UserId = User.Id; query.OrderBy = "PinnedAt DESC, LastMessageAt DESC"; model.Conversations = ConversationService.Search(query); // make sure selected conversation is visible in conversations list while (model.Conversation != null && !model.Conversations.Any(x => x.Id == model.Conversation.Id)) { query.Top += PageSizes.First(); model.Conversations = ConversationService.Search(query); } return(View(nameof(Messenger), model)); }
protected override void Validate() { var fields = GetAllFields().ToArray(); var names = new HashSet <string>(fields.Select(f => f.Name).Distinct()); var aliases = new HashSet <string>(fields.Select(f => f.Alias)); ValidateVersion(names, aliases); ValidateFilter(names, aliases); ValidateOrder(names, aliases); foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField))) { if (GetField(field.SortField) == null) { Error($"Can't find sort field {field.SortField} defined in field {field.Alias}."); } } // Paging Madness if (Page > 0) { if (PageSizes.Any()) { if (PageSizes.All(ps => ps.Size != PageSize)) { var first = PageSizes.First().Size; Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}."); PageSize = first; } } else { if (PageSize > 0) { PageSizes.Add(new PageSize { Size = PageSize }); } else { PageSizes.Add(new PageSize { Size = 25 }); PageSizes.Add(new PageSize { Size = 50 }); PageSizes.Add(new PageSize { Size = 100 }); if (PageSize != 25 && PageSize != 50 && PageSize != 100) { PageSize = 25; } } } } else { if (PageSize > 0) { PageSize = 0; } } }
protected override void Validate() { // if validation has been defined, check to see if corresponding valid and message fields are present and create them if not var calculatedKeys = new HashSet <string>(CalculatedFields.Select(f => f.Alias ?? f.Name).Distinct(), StringComparer.OrdinalIgnoreCase); if (Fields.Any(f => f.Validators.Any())) { foreach (var field in Fields.Where(f => f.Validators.Any())) { if (!calculatedKeys.Contains(field.ValidField)) { CalculatedFields.Add(new Field { Name = field.ValidField, Alias = field.ValidField, Input = false, Type = "bool", Default = "true", IsCalculated = true }); } if (!calculatedKeys.Contains(field.MessageField)) { CalculatedFields.Add(new Field { Name = field.MessageField, Alias = field.MessageField, Length = "255", Default = "", IsCalculated = true, Input = false }); } } // create an entity-wide valid field if necessary if (ValidField == string.Empty) { var valid = Alias + "Valid"; if (!CalculatedFields.Any(f => f.Name.Equals(valid))) { var add = new Field { Name = valid, Alias = valid, Type = "bool", ValidField = valid, Input = false, IsCalculated = true }; add.Validators.Add(new Operation { Method = "all", Operator = "equals", Value = "true", Parameters = GetAllFields().Where(f => f.ValidField != string.Empty).Select(f => f.ValidField).Distinct().Select(n => new Parameter { Field = n }).ToList() }); CalculatedFields.Add(add); ValidField = valid; } } } var fields = GetAllFields().ToArray(); var names = new HashSet <string>(fields.Select(f => f.Name).Distinct()); var aliases = new HashSet <string>(fields.Select(f => f.Alias)); ValidateVersion(names, aliases); ValidateFilter(names, aliases); ValidateOrder(names, aliases); foreach (var field in GetAllOutputFields().Where(f => f.Sortable == "true" && !string.IsNullOrEmpty(f.SortField))) { if (GetField(field.SortField) == null) { Error($"Can't find sort field {field.SortField} defined in field {field.Alias}."); } } // Paging Madness if (Page > 0) { if (PageSizes.Any()) { if (PageSizes.All(ps => ps.Size != PageSize)) { var first = PageSizes.First().Size; Warn($"The entity {Name} has an invalid PageSize of {PageSize}. Set to {first}."); PageSize = first; } } else { if (PageSize > 0) { PageSizes.Add(new PageSize { Size = PageSize }); } else { PageSizes.Add(new PageSize { Size = 25 }); PageSizes.Add(new PageSize { Size = 50 }); PageSizes.Add(new PageSize { Size = 100 }); if (PageSize != 25 && PageSize != 50 && PageSize != 100) { PageSize = 25; } } } } else { if (PageSize > 0) { PageSize = 0; } } }