public async Task CreateInviteAsync(Entreaty invite, int userId)
        {
            invite.EntreatyType = EntreatyType.INVITE;
            NotificationContext notificationContext = new NotificationContext()
            {
                CreatedBy        = await _context.Users.FindAsync(userId),
                Data             = string.Format("{0} has sent an invite", invite.Group.Name),
                NotificationType = NotificationType.ENTREATY,
                Time             = DateTime.UtcNow
            };

            foreach (Student s in invite.Group.Students)
            {
                notificationContext.NotificationsSent.Add(new Notification()
                {
                    NotificationContext = notificationContext,
                    Read     = false,
                    Receiver = await _context.Users.FindAsync(s.Id)
                });
            }
            notificationContext.NotificationsSent.Add(new Notification()
            {
                NotificationContext = notificationContext,
                Read     = false,
                Receiver = await _context.Users.FindAsync(invite.Student.Id)
            });
            invite.NotificationContext = notificationContext;
            await _context.AddAsync(invite);

            await SaveAsync();

            foreach (Notification n in notificationContext.NotificationsSent)
            {
                if (_hubContext.Clients.Group(n.ReceiverId.ToString()) != null)
                {
                    await _hubContext.Clients.Group(n.ReceiverId.ToString()).SendAsync("ReceiveNotification");
                }
            }
        }
        public async Task CreateAsync(Student student)
        {
            await _context.AddAsync(student);

            await SaveAsync();
        }
示例#3
0
        public async Task CreateAsync(Notification notification)
        {
            await _context.AddAsync(notification);

            await SaveAsync();
        }
示例#4
0
        public async Task CreateAsync(Group group)
        {
            await _context.AddAsync(group);

            await SaveAsync();
        }
        public async Task CreateAsync(Project project)
        {
            await _context.AddAsync(project);

            await SaveAsync();
        }