Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="mail"></param>
        public void SendAll(MailJobModel mail)
        {
            var userDb = new ApplicationDbContext();
            var Db     = new TimeTableDbContext();

            ICollection <ApplicationUser> userList;

            userList = userDb.Users.Where(u =>
                                          u.MemberState == MemberState.Student ||
                                          (u.MemberState == MemberState.Staff && u.LikeEMails)).ToList();

            var sender = userDb.Users.SingleOrDefault(x => x.Id.Equals(mail.SenderId));

            // jetzt reduzieren, um nicht FK Mitglieder!
            var deleteList = new List <ApplicationUser>();

            var subService = new SemesterSubscriptionService(Db);

            foreach (var user in userList)
            {
                if (user.MemberState == MemberState.Student)
                {
                    var isInSem = subService.IsSubscribed(user.Id, mail.SemesterId, mail.OrgId);
                    if (!isInSem)
                    {
                        deleteList.Add(user);
                    }
                }
                else
                {
                    var isInFK = Db.Members.Any(x =>
                                                x.Organiser.Id == mail.OrgId &&
                                                string.IsNullOrEmpty(x.UserId) && x.UserId.Equals(user.Id));
                    if (!isInFK)
                    {
                        deleteList.Add(user);
                    }
                }
            }

            foreach (var user in deleteList)
            {
                userList.Remove(user);
            }

            SendMail(userList, sender, mail);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="allSubscriptions"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public List <OccurrenceSubscription> GetSubscriptionsForGroup(ICollection <OccurrenceSubscription> allSubscriptions, OccurrenceGroup group)
        {
            var semSubService = new SemesterSubscriptionService();

            var subList = new List <OccurrenceSubscription>();

            foreach (var subscription in allSubscriptions)
            {
                var user = UserManager.FindById(subscription.UserId);
                if (user != null)
                {
                    bool isInGroup = semSubService.IsSubscribed(user.Id, group.SemesterGroups, group.Occurrence.UseExactFit);

                    if (isInGroup)
                    {
                        subList.Add(subscription);
                    }
                }
            }

            return(subList);
        }