public async Task <CommentsOverviewModel> Edit(CommentEditModel model) { var comment = await _commentsService.GetAsync(model.Id); if (!_commentsService.CanEdit(comment, await _intranetMemberService.GetCurrentMemberIdAsync())) { return(await _commentsHelper.OverViewAsync(model.Id)); } var editDto = MapToEditDto(model, model.Id); var command = new EditCommentCommand(model.EntityId, model.EntityType, editDto); _commandPublisher.Publish(command); await OnCommentEditedAsync(model.Id, model.EntityType); switch (model.EntityType) { case IntranetEntityTypeEnum type when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events): var activityCommentsInfo = GetActivityComments(model.EntityId); return(await _commentsHelper.OverViewAsync(activityCommentsInfo.Id, activityCommentsInfo.Comments, activityCommentsInfo.IsReadOnly)); default: return(await _commentsHelper.OverViewAsync(comment.ActivityId)); } }
public async Task <IHttpActionResult> AddLike([FromUri] Guid entityId, [FromUri] IntranetEntityTypeEnum entityType) { if (!await CanAddRemoveLikeAsync(entityId, entityType)) { return(StatusCode(HttpStatusCode.Forbidden)); } var command = new AddLikeCommand(entityId, entityType, await _intranetMemberService.GetCurrentMemberIdAsync()); _commandPublisher.Publish(command); switch (entityType) { case IntranetEntityTypeEnum.Comment: return(Ok(await _likesService.GetLikeModelsAsync(entityId))); case IntranetEntityTypeEnum.ContentPage: return(Ok(await _likesService.GetLikeModelsAsync(entityId))); case IntranetEntityTypeEnum type when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events): var activityLikeInfo = GetActivityLikes(entityId); return(Ok(activityLikeInfo.Likes)); default: throw new IndexOutOfRangeException(); } }
private async Task <NewsBase> MapToNewsAsync(NewsCreateModel createModel) { var news = createModel.Map <NewsBase>(); news.MediaIds = news.MediaIds.Concat(_mediaHelper.CreateMedia(createModel, MediaFolderTypeEnum.NewsContent)); news.PublishDate = createModel.PublishDate.ToUniversalTime().WithCorrectedDaylightSavingTime(createModel.PublishDate); news.UnpublishDate = createModel.UnpublishDate?.ToUniversalTime().WithCorrectedDaylightSavingTime(createModel.UnpublishDate.Value); news.EndPinDate = createModel.EndPinDate?.ToUniversalTime().WithCorrectedDaylightSavingTime(createModel.EndPinDate.Value); news.CreatorId = await _intranetMemberService.GetCurrentMemberIdAsync(); if (await IsPinAllowedAsync()) { news.IsPinned = createModel.IsPinned; } return(news); }
public async Task <IEnumerable <GroupDocumentViewModel> > List(Guid groupId) { var groupDocumentsList = await _groupDocumentsService.GetByGroupAsync(groupId); var mediaIdsList = groupDocumentsList.Select(s => s.MediaId).ToList(); var medias = _mediaService.GetByIds(mediaIdsList); var group = await _groupService.GetAsync(groupId); var groupMembers = await _groupMemberService.GetGroupMemberByGroupAsync(groupId); var currentMemberId = await _intranetMemberService.GetCurrentMemberIdAsync(); var documentTasks = medias.Select(async s => { IntranetMember creator; if (TryParseIntranetCreatorId(s, out var intranetCreatorId)) { creator = await _intranetMemberService.GetAsync(intranetCreatorId); } else { creator = await _intranetMemberService.GetByUserIdAsync(s.CreatorId); } var document = groupDocumentsList.First(f => f.MediaId == s.Id); var model = new GroupDocumentViewModel { CanDelete = CanDelete(currentMemberId, group, groupMembers, s), Id = document.Id, CreateDate = s.CreateDate.ToString("dd.MM.yyyy"), Name = s.Name, Type = s is FileModel file ? file.UmbracoExtension : ((ImageModel)s).UmbracoExtension, Creator = creator.ToViewModel(), FileUrl = s.Url }; return(model); }).ToArray(); var documents = await Task.WhenAll(documentTasks); var docs = documents.OrderBy(x => x.Name); return(docs); }
public async Task <NotificationViewModel[]> Get(int page = 1) { var skip = (page - 1) * ItemsPerPage; var notifications = (await _uiNotifierService.GetManyAsync( await _intranetMemberService.GetCurrentMemberIdAsync())) .Skip(skip) .Take(ItemsPerPage) .ToArray(); var notNotifiedNotifications = notifications.Where(el => !el.IsNotified).ToArray(); if (notNotifiedNotifications.Any()) { await _uiNotifierService.NotifyAsync(notNotifiedNotifications); } return(await Task.WhenAll(notifications.Select(async n => await MapNotificationToViewModelAsync(n)))); }
public async Task <IHttpActionResult> Create(GroupCreateModel createModel) { if (!_groupService.CanCreate()) { return(StatusCode(HttpStatusCode.Forbidden)); } var currentMemberId = await _memberService.GetCurrentMemberIdAsync(); var groupId = await _groupMemberService.CreateAsync(createModel, new GroupMemberSubscriptionModel { IsAdmin = true, MemberId = currentMemberId, }); return(Ok(_groupLinkProvider.GetGroupRoomLink(groupId))); }
private async Task ResolveMentionsAsync(string text, SocialBase social) { var mentionIds = _mentionService.GetMentions(text).ToList(); if (mentionIds.Any()) { var links = await _activityLinkService.GetLinksAsync(social.Id); const int maxTitleLength = 100; _mentionService.ProcessMention(new MentionModel() { MentionedSourceId = social.Id, CreatorId = await _memberService.GetCurrentMemberIdAsync(), MentionedUserIds = mentionIds, Title = social.Description.StripMentionHtml().TrimByWordEnd(maxTitleLength), Url = links.Details, ActivityType = IntranetActivityTypeEnum.Social }); } }
public async Task <Guid> CreateAsync(GroupCreateModel model, GroupMemberSubscriptionModel creator) { var group = model.Map <GroupModel>(); group.CreatorId = await _memberService.GetCurrentMemberIdAsync(); group.GroupTypeId = GroupTypeEnum.Open.ToInt(); var createdMedias = _mediaHelper.CreateMedia(model, MediaFolderTypeEnum.GroupsContent).ToList(); group.ImageId = createdMedias.Any() ? (int?)createdMedias.First() : null; var groupId = await _groupService.CreateAsync(group); await AddAsync(groupId, creator); await _groupMediaService.GroupTitleChangedAsync(groupId, @group.Title); return(groupId); }
public async Task <GroupViewModel> GetGroupViewModelAsync(Guid groupId) { var group = await _groupService.GetAsync(groupId); var currentMemberId = await _memberService.GetCurrentMemberIdAsync(); var groupModel = group.Map <GroupViewModel>(); groupModel.IsMember = await _groupMemberService.IsGroupMemberAsync(group.Id, currentMemberId); groupModel.IsCreator = group.CreatorId == currentMemberId; groupModel.MembersCount = await _groupMemberService.GetMembersCountAsync(group.Id); groupModel.Creator = (await _memberService.GetAsync(group.CreatorId)).ToViewModel(); groupModel.GroupUrl = _groupLinkProvider.GetGroupRoomLink(group.Id); if (groupModel.HasImage) { groupModel.GroupImageUrl = _imageHelper.GetImageWithPreset(_mediaModelService.Get(group.ImageId.Value).Url, UmbracoAliases.ImagePresets.GroupImageThumbnail); } return(groupModel); }
public virtual async Task <IEnumerable <CommentViewModel> > GetCommentViewsAsync(IEnumerable <CommentModel> comments) { var commentsList = comments.OrderBy(c => c.CreatedDate).ToArray(); var currentMemberId = await _intranetMemberService.GetCurrentMemberIdAsync(); var creators = (await _intranetMemberService.GetAllAsync()).ToArray(); var replies = commentsList.Where(_commentsService.IsReply); return(commentsList .Where(c => !_commentsService.IsReply(c)) .Select(comment => { var model = GetCommentView(comment, currentMemberId, creators.SingleOrDefault(c => c.Id == comment.UserId)); var commentReplies = replies.Where(reply => reply.ParentId == model.Id); model.Replies = commentReplies .Select(reply => GetCommentView(reply, currentMemberId, creators.SingleOrDefault(c => c.Id == reply.UserId))); return model; })); }
public async Task <bool> CanUploadAsync(Guid groupId) { return(await _groupMemberService.IsGroupMemberAsync(groupId, await _intranetMemberService.GetCurrentMemberIdAsync())); }