Exemplo 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());
        }
Exemplo n.º 2
0
        private IHttpActionResult Unfollow(FollowRestaurantDto followRestaurantDto)
        {
            //context.FollowRestaurants.FirstOrDefault(f => f.RestaurantId == followRestaurantDto.RestaurantId && f.UnfollowDate == null)
            //    .SetDateTimeUnfollow(DateTime.Now);


            //context.SaveChanges();

            return(Ok());
        }
Exemplo n.º 3
0
        public IHttpActionResult Follow(FollowRestaurantDto followRestaurantDto)
        {
            var userId = User.Identity.GetUserId();

            if (context.FollowRestaurants.Any(f => f.RestaurantId == followRestaurantDto.RestaurantId && f.UnfollowDate == null))
            {
                Unfollow(followRestaurantDto);
            }

            //else
            //{
            //    var followRestaurant = new FollowRestaurant(userId, followRestaurantDto.RestaurantId, DateTime.Now);

            //    context.FollowRestaurants.Add(followRestaurant);

            //    context.SaveChanges();



            //}

            return(Ok());
        }