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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns a list of new notifications that were not created based on a user following another user
        /// Goes through the list of newly created notifications and checks if the followeeid + otherid combination is there
        /// If not, will make a new notification to be returned
        /// </summary>
        /// <param name="followeeeid"></param>
        /// <param name="otherid"></param>
        /// <param name="curNotif"></param>
        /// <returns></returns>
        private async Task <List <Repository.Models.Notification> > FolloweeNotifications(string otherid, string type, List <Repository.Models.FollowingUser> followees, List <Repository.Models.Notification> curNotif, string creatorid)
        {
            List <Repository.Models.Notification>         newNotifications = new List <Repository.Models.Notification>();
            List <Task <Repository.Models.Notification> > tasks            = new List <Task <Repository.Models.Notification> >();

            foreach (Repository.Models.FollowingUser followee in followees)
            {
                if (!curNotif.Exists(x => x.UserId == followee.FolloweeUserId))
                {
                    tasks.Add(Task.Run(() => Mapper.ModelNotifToRepoNotif(followee.FolloweeUserId, otherid, type, creatorid)));
                }
            }
            var results = await Task.WhenAll(tasks);

            foreach (var item in results)
            {
                newNotifications.Add(item);
            }
            return(newNotifications);
        }