Esempio n. 1
0
        public IHttpActionResult GetNotifications(FollowRestaurantDto followRestaurantDto)
        {
            if (context.FollowRestaurants.Any(f => f.RestaurantId == followRestaurantDto.RestaurantId && f.UnfollowDate == null))
            {
                Unfollow(followRestaurantDto);
            }

            else
            {
                var owners = context.RestaurantOwnerships
                             .Where(ro => ro.RestaurantId == followRestaurantDto.RestaurantId)
                             .Select(ro => ro.ApplicationUser);

                var userId           = User.Identity.GetUserId();
                var followRestaurant = new FollowRestaurant(userId, followRestaurantDto.RestaurantId, DateTime.Now);
                var notification     = Notification.RestaurantFollowed(followRestaurant);


                foreach (var owner in owners)
                {
                    context.Notifications.Add(notification);
                    owner.Notify(notification);
                    foreach (var userNotification in owner.UserNotifications)
                    {
                        context.UserNotifications.Add(userNotification);
                    }
                }


                context.SaveChanges();
            }
            return(Ok());
        }
Esempio n. 2
0
        private Notification(NotificationType type, FollowRestaurant followRestaurant)
        {
            if (followRestaurant == null)
            {
                throw new ArgumentNullException("followRestaurant");
            }

            Type             = type;
            FollowRestaurant = followRestaurant;
            DateTime         = DateTime.Now;
        }
Esempio n. 3
0
 public void AddRestaurantFollowing(FollowRestaurant followRestaurant)
 {
     _context.FollowRestaurants.Add(followRestaurant);
 }
Esempio n. 4
0
        public static Notification RestaurantFollowed(FollowRestaurant followRestaurant)
        {
            var notification = new Notification(NotificationType.BusinsessFollowed, followRestaurant);

            return(notification);
        }