public async Task <int> GetNextOrderNumberAsync(string contentItemId) { var index = await _session.QueryIndex <ContainedPartIndex>(x => x.ListContentItemId == contentItemId) .OrderByDescending(x => x.Order) .FirstOrDefaultAsync(); if (index != null) { return(index.Order + 1); } else { return(0); } }
private async Task RecordAuditTrailEventAsync(string name, IContent content) { if (name != ContentAuditTrailEventConfiguration.Restored && _restoring.Contains(content.ContentItem.ContentItemId)) { return; } var siteSettings = await _siteService.GetSiteSettingsAsync(); var settings = siteSettings.As <ContentAuditTrailSettings>(); if (!settings.AllowedContentTypes.Contains(content.ContentItem.ContentType)) { return; } var versionNumber = await _session .QueryIndex <ContentItemIndex>(index => index.ContentItemId == content.ContentItem.ContentItemId) .CountAsync(); await _auditTrailManager.RecordEventAsync( new AuditTrailContext <AuditTrailContentEvent> ( name, ContentAuditTrailEventConfiguration.Content, content.ContentItem.ContentItemId, _httpContextAccessor.HttpContext.User?.FindFirstValue(ClaimTypes.NameIdentifier), _httpContextAccessor.HttpContext.User?.Identity?.Name, new AuditTrailContentEvent { ContentItem = content.ContentItem, VersionNumber = versionNumber } )); }
public override async Task <IDisplayResult> UpdateAsync(AutoroutePart model, IUpdateModel updater, UpdatePartEditorContext context) { var viewModel = new AutoroutePartViewModel(); await updater.TryUpdateModelAsync(viewModel, Prefix, t => t.Path, t => t.UpdatePath, t => t.RouteContainedItems, t => t.Absolute, t => t.Disabled); var settings = context.TypePartDefinition.GetSettings <AutoroutePartSettings>(); model.Disabled = viewModel.Disabled; model.Absolute = viewModel.Absolute; model.RouteContainedItems = viewModel.RouteContainedItems; // When disabled these values are not updated. if (!model.Disabled) { if (settings.AllowCustomPath) { model.Path = viewModel.Path; } if (settings.AllowUpdatePath && viewModel.UpdatePath) { // Make it empty to force a regeneration model.Path = ""; } var httpContext = _httpContextAccessor.HttpContext; if (httpContext != null && await _authorizationService.AuthorizeAsync(httpContext.User, Permissions.SetHomepage)) { await updater.TryUpdateModelAsync(model, Prefix, t => t.SetHomepage); } updater.ModelState.BindValidationResults(Prefix, model.ValidatePathFieldValue(S)); // This can only validate the path if the Autoroute is not managing content item routes or the path is absolute. if (!String.IsNullOrEmpty(model.Path) && (!settings.ManageContainedItemRoutes || (settings.ManageContainedItemRoutes && model.Absolute))) { var possibleConflicts = await _session.QueryIndex <AutoroutePartIndex>(o => o.Path == model.Path).ListAsync(); if (possibleConflicts.Any()) { var hasConflict = false; if (possibleConflicts.Any(x => x.ContentItemId != model.ContentItem.ContentItemId) || possibleConflicts.Any(x => !string.IsNullOrEmpty(x.ContainedContentItemId) && x.ContainedContentItemId != model.ContentItem.ContentItemId)) { hasConflict = true; } if (hasConflict) { updater.ModelState.AddModelError(Prefix, nameof(model.Path), S["Your permalink is already in use."]); } } } } return(Edit(model, context)); }
private async Task ValidateAsync(AutoroutePart autoroute, IUpdateModel updater) { if (autoroute.Path?.IndexOfAny(InvalidCharactersForPath) > -1 || autoroute.Path?.IndexOf(' ') > -1) { var invalidCharactersForMessage = string.Join(", ", InvalidCharactersForPath.Select(c => $"\"{c}\"")); updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), T["Please do not use any of the following characters in your permalink: {0}. No spaces are allowed (please use dashes or underscores instead).", invalidCharactersForMessage]); } if (autoroute.Path?.Length > MaxPathLength) { updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), T["Your permalink is too long. The permalink can only be up to {0} characters.", MaxPathLength]); } if (autoroute.Path != null && (await _session.QueryIndex <AutoroutePartIndex>(o => o.Path == autoroute.Path && o.ContentItemId != autoroute.ContentItem.ContentItemId).CountAsync()) > 0) { updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), T["Your permalink is already in use."]); } }
private async Task ValidateAsync(AutoroutePart autoroute, IUpdateModel updater, AutoroutePartSettings settings) { if (autoroute.Path == "/") { updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), S["Your permalink can't be set to the homepage, please use the homepage option instead."]); } if (autoroute.Path?.IndexOfAny(InvalidCharactersForPath) > -1 || autoroute.Path?.IndexOf(' ') > -1 || autoroute.Path?.IndexOf("//") > -1) { var invalidCharactersForMessage = string.Join(", ", InvalidCharactersForPath.Select(c => $"\"{c}\"")); updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), S["Please do not use any of the following characters in your permalink: {0}. No spaces, or consecutive slashes, are allowed (please use dashes or underscores instead).", invalidCharactersForMessage]); } if (autoroute.Path?.Length > MaxPathLength) { updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), S["Your permalink is too long. The permalink can only be up to {0} characters.", MaxPathLength]); } // This can only validate the path if the Autoroute is not managing content item routes or the path is absolute. if (!String.IsNullOrEmpty(autoroute.Path) && (!settings.ManageContainedItemRoutes || (settings.ManageContainedItemRoutes && autoroute.Absolute))) { var possibleConflicts = await _session.QueryIndex <AutoroutePartIndex>(o => o.Path == autoroute.Path).ListAsync(); if (possibleConflicts.Any()) { var hasConflict = false; if (possibleConflicts.Any(x => x.ContentItemId != autoroute.ContentItem.ContentItemId) || possibleConflicts.Any(x => !string.IsNullOrEmpty(x.ContainedContentItemId) && x.ContainedContentItemId != autoroute.ContentItem.ContentItemId)) { hasConflict = true; } if (hasConflict) { updater.ModelState.AddModelError(Prefix, nameof(autoroute.Path), S["Your permalink is already in use."]); } } } }
private bool IsPathUnique(string path, AutoroutePart context) { return(_session.QueryIndex <AutoroutePartIndex>(o => o.ContentItemId != context.ContentItem.ContentItemId && o.Path == path).CountAsync().GetAwaiter().GetResult() == 0); }
private async Task <bool> IsPathUniqueAsync(string path, AutoroutePart context) { return((await _session.QueryIndex <AutoroutePartIndex>(o => o.ContentItemId != context.ContentItem.ContentItemId && o.Path == path).CountAsync()) == 0); }
private async Task PrepareGroupChatNotifications(CommentRecordViewModel comment, string userId) { //get all current group cliend connection id, and send the message to them. var groupsMember = new[] { new { GroupId = 1, MemberId = 2, GroupName = "dddd" } }; var groupMembersQuery = _session.QueryIndex <ContentPickerFieldIndex>(x => x.SelectedContentItemId == comment.ContentItemId); var groupMemberIdResults = (await groupMembersQuery.ListAsync()).Select(x => x.ContentItemId); // var groupsMember = _context.GroupMember.Where(g => g.GroupId == comment.GroupId && g.MemberId != currentUserId) // .Join(_context.Group, gm => gm.GroupId, g => g.Id, (gm, g) => new // { // gm.GroupId, // gm.MemberId, // GroupName = g.Name // }); // get all the connected participant notification number. // get all the connected participant notification number. var connectedMemberNotificationNum = NotificationHub.Connections .Where(uId => uId.UserId != userId); // .GroupJoin(_unitOfWork.Notification // .Find(o => o.GroupId == comment.GroupId && o.IsSeen == false), uId => uId, n => n.ToUserId, // (UserId, NotificationNum) => new KeyValuePair<string, int>(UserId, NotificationNum.Count() + 1)); // return (await _session.QueryIndex<AutoroutePartIndex>(o => o.ContentItemId != context.ContentItem.ContentItemId && o.Path == path).CountAsync()) ; //prepare the current post info /*var currentComment = new CommentRecordViewModel() * { * Content = comment.Content, * Created = comment.Created, * CreatedByAdmin = false, * CreatedByCurrentUser = false, * Creator = comment.Creator, * FileMimeType = comment.FileMimeType, * FileURL = comment.FileURL, * Fullname = comment.Fullname, * Id = comment.Id, * IsNew = true, * Modified = comment.Modified, * Parent = comment.Parent, * UpvoteCount = comment.UpvoteCount, * UserHasUpvoted = false, * Pings = comment.Pings, * CommentGroupType = comment.CommentGroupType, * FileName = comment.FileName, * GroupId = comment.GroupId, * // ProfilePictureUrl = comment.ProfilePictureUrl, * Root = comment.Root, * UserVoted = comment.UserVoted, * CreatorName = User.Identity.Name, * // GroupName = GetGommentGroupName(comment) * };*/ /*foreach (var member in groupsMember) * { * //add notifications to other member * // if (member.MemberId != null) * // { * var notification = new Notification * { * Content = comment.Content, * CreatedUtc = DateTime.Now, * GroupId = comment.GroupId, * IsSeen = false, * FromUserId = userId, * NotificationType = NotificationType.NewChatMessage, * Title = string.Format(" sent a message {0}", string.IsNullOrEmpty(member.GroupName) ? "" : string.Format(" in {0} chat session ", member.GroupName)), //need to improve in next version * CorrelationId = comment.Id.ToString(), * Event = "Comment", * ToUserId = member.MemberId.ToString() * }; * * if (!string.IsNullOrEmpty(comment.FileURL)) * { * notification.Title = string.Format(" sent an attachment {0}", string.IsNullOrEmpty(member.GroupName) ? "" : string.Format(" in {0} chat session ", member.GroupName)); //need to improve in next version * } * * await _notificationRepository.InsertAsync(notification); * // _context.Notification.Add(notification); * * // } * }*/ //todo //send notifications to current connected comment group member /*foreach (var conn in connectedMemberNotificationNum) * { * if (conn.ConnectionID != null) * { * await _realTimeNotifier.HubContext().Clients.Client(conn.ConnectionID).SendAsync("RefreshChatNotificationNum", conn.NotificationNum, currentComment); * // await _hubContext.Clients.Client(conn.ConnectionID).SendAsync("ReceiveMessage", currentComment, conn.NotificationNum); * } * }*/ }
public Task <int> GetTeamMemberCount(string teamContentItemId) { return(_session.QueryIndex <HackathonUsersIndex>(x => x.TeamContentItemId == teamContentItemId).CountAsync()); }