public async Task DeleteAsync(Student student)
 {
     _context.Remove(student);
     //Not included in cascade to avoid cycles
     _context.Remove(student.User);
     await SaveAsync();
 }
        public async Task DeleteAsync(Project project)
        {
            Group group = _context.Groups.Where(g => g.ProposedProject.Id == project.Id).First();

            group.ProposedProject = null;
            _context.Remove(project);
            await SaveAsync();
        }
        public async Task RejectAsync(Entreaty entreaty)
        {
            Group        group      = entreaty.Group;
            Student      student    = entreaty.Student;
            Student      groupAdmin = group.Students.Where(s => s.GroupAdmin == true).FirstOrDefault();
            EntreatyType type       = entreaty.EntreatyType;

            _context.Remove(entreaty);
            await SaveAsync();

            NotificationContext notificationContext = new NotificationContext()
            {
                NotificationType = NotificationType.ENTREATY,
                Time             = DateTime.UtcNow
            };

            foreach (Student s in group.Students)
            {
                notificationContext.NotificationsSent.Add(new Notification()
                {
                    NotificationContext = notificationContext,
                    Read     = false,
                    Receiver = await _context.Users.FindAsync(s.Id)
                });
            }
            if (type == EntreatyType.REQUEST)
            {
                notificationContext.CreatedBy = _context.Users.Find(groupAdmin.Id);
                notificationContext.Data      = string.Format("{0} has rejected request", group.Name);
                notificationContext.NotificationsSent.Add(new Notification()
                {
                    NotificationContext = notificationContext,
                    Read     = false,
                    Receiver = student.User
                });
            }
            else
            {
                notificationContext.CreatedBy = _context.Users.Find(student.Id);
                notificationContext.Data      = string.Format("{0} {1} has rejected invite", student.FirstName, student.LastName);
            }
            _context.Add(notificationContext);
            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");
                }
            }
        }
示例#4
0
        public async Task DeleteAsync(Group group, int userId)
        {
            List <Student> students = group.Students.ToList();

            _context.Remove(group);
            await SaveAsync();

            NotificationContext notificationContext = new NotificationContext()
            {
                CreatedBy        = await _context.Users.FindAsync(userId),
                Data             = string.Format("Your group has been deleted"),
                NotificationType = NotificationType.SYSTEM,
                Time             = DateTime.UtcNow
            };

            await SendNotificationsToRangeOfStudentsAsync(notificationContext, students);
        }
示例#5
0
 public async Task DeleteAsync(Notification notification)
 {
     _context.Remove(notification);
     await SaveAsync();
 }