Beispiel #1
0
        public async Task CreateNotifications(ModelNotification modelNotifications, string type)
        {
            List <Repository.Models.Notification>         newNotifications = new List <Repository.Models.Notification>();
            List <Task <Repository.Models.Notification> > tasks            = new List <Task <Repository.Models.Notification> >();
            List <Repository.Models.FollowingUser>        allFollowees     = await _repo.GetUserFollowees(modelNotifications.Usernameid);

            foreach (string userid in modelNotifications.Followers)
            {
                if (userid != modelNotifications.Usernameid)
                {
                    tasks.Add(Task.Run(() => Mapper.ModelNotifToRepoNotif(userid, modelNotifications.OtherId, type, null)));
                }
            }
            var results = await Task.WhenAll(tasks);

            foreach (var item in results)
            {
                newNotifications.Add(item);
            }
            List <Task> repoTasks = new List <Task>();

            foreach (var notification in newNotifications)
            {
                await _repo.AddNotification(notification);
            }

            List <Repository.Models.Notification> otherNotifications = await Task.Run(() => FolloweeNotifications(modelNotifications.OtherId, type, allFollowees, newNotifications, modelNotifications.Usernameid));

            foreach (var notification in otherNotifications)
            {
                await _repo.AddNotification(notification);
            }
        }