public void RejectJoinGroupRequest(string id, string userId)
        {
            JoinGroupRequestNotification notification = this.Context.Notifications.OfType <JoinGroupRequestNotification>()
                                                        .Include(n => n.Requester)
                                                        .Include(n => n.Group)
                                                        .SingleOrDefault(n => n.Id == id);

            Group group     = notification?.Group;
            User  requester = notification?.Requester;
            User  sender    = this.Context.Users.Find(userId);

            if (group?.Players != null)
            {
                PlayerRejectedGroupNotification playerRejectedGroupNotification = new PlayerRejectedGroupNotification()
                {
                    Id     = Guid.NewGuid().ToString(),
                    Group  = group,
                    Sender = sender
                };

                requester.Notifications.Add(playerRejectedGroupNotification);

                this.Context.Notifications.Remove(notification);
            }
            this.Context.SaveChanges();
        }
Esempio n. 2
0
        public void JoinGroupRequest(string groupId, string userId)
        {
            Group group = Context.Groups.Find(groupId);
            User  user  = Context.Users.Find(userId);
            IEnumerable <User> admins = Context.Groups.Include(g => g.Admins)
                                        .SingleOrDefault(g => g.Id == groupId)?.Admins;

            if (admins != null)
            {
                JoinGroupRequestNotification notification = new JoinGroupRequestNotification
                {
                    Id        = Guid.NewGuid().ToString(),
                    Group     = group,
                    Requester = user
                };

                foreach (var admin in admins)
                {
                    admin.Notifications.Add(notification);
                }

                Context.SaveChanges();
            }
        }