/// <summary> /// Allows a client to broadcast a notification to all members of the team who are currently joined, IF: /// 1. they are an view administrator /// </summary> /// <param name="teamId"></param> /// <param name="incomingData"></param> /// <param name="ct"></param> /// <returns></returns> public async Task <ViewModels.Notification> PostToTeam(Guid teamId, ViewModels.Notification incomingData, CancellationToken ct) { var wasSuccess = true; var canPost = true; var messageTime = DateTime.Now.ToUniversalTime(); var requestedTeam = _context.Teams.Find(teamId); NotificationEntity notificationEntity; if ((await _authorizationService.AuthorizeAsync(_user, null, new ViewAdminRequirement(requestedTeam.ViewId))).Succeeded) { notificationEntity = _mapper.Map <NotificationEntity>(incomingData); notificationEntity.ToId = teamId; notificationEntity.ToType = NotificationType.Team; notificationEntity.BroadcastTime = messageTime; notificationEntity.FromId = _user.GetId(); notificationEntity.FromType = NotificationType.User; notificationEntity.FromName = _user.Claims.Single(x => x.Type == "name").Value; notificationEntity.ToName = _context.Teams.Find(teamId).Name; _context.Notifications.Add(notificationEntity); await _context.SaveChangesAsync(ct); } else { notificationEntity = new NotificationEntity { }; wasSuccess = false; canPost = false; } var returnNotification = _mapper.Map <ViewModels.Notification>(notificationEntity); returnNotification.WasSuccess = wasSuccess; returnNotification.CanPost = canPost; returnNotification.IconUrl = GetIconUrl(notificationEntity.Priority, notificationEntity.FromName); return(returnNotification); }
public async Task Check() { var notifs = await api.User.GetNotificationsAsync(); //var sorted = (from n in notifs orderby n.CreateTime descending, n.Read ascending select n); Notifications.Clear(); foreach (var notif in notifs) { var vm = new ViewModels.Notification(notif); Notifications.Add(vm); } int unread = Notifications.Count(x => x.Read == false); SendUpdate(unread, Notifications.Count); }