public async Task <IActionResult> GetTenders()
        {
            var friends = await FacebookApi.GetUserFriends(null);

            var tenders = await DbContext.Profiles.Where(p => p.IsTender && friends.Contains(p.FacebookId)).ToArrayAsync();

            return(Ok(tenders.Select(p => p.ToProfileDto())));
        }
        public async Task <IActionResult> GetFriends()
        {
            string facebookId = null;
            var    friends    = await FacebookApi.GetUserFriends(null);

            var profiles = await DbContext.Profiles.Where(p => friends.Contains(p.FacebookId)).ToArrayAsync();

            return(Ok(profiles.Select(p => p.ToProfileDto())));
        }
        public async Task <IActionResult> GetFriend(Guid id)
        {
            var friend = await DbContext.Profiles.FindAsync(id);

            if (friend == null)
            {
                return(NotFound());
            }

            var friends = await FacebookApi.GetUserFriends(null);

            if (!friends.Contains(friend.FacebookId))
            {
                return(Forbid());
            }

            return(Ok(friend.ToProfileDto()));
        }
Example #4
0
        public async Task <IActionResult> GetTenders(int id)
        {
            if (await DbContext.Bars.FindAsync(id) == null)
            {
                return(NotFound());
            }

            // Start time is right now
            var start = DateTime.UtcNow;
            // If it's between 12am and 2am, add 2 hours to the date, otherwise 26 (1 day + 2 hours)
            var end     = start.Date + TimeSpan.FromHours(start.TimeOfDay.Hours < 2 ? 2 : 26);
            var friends = await FacebookApi.GetUserFriends(User.Claims.Single(c => c.Type == "token").Value);

            var shifts = await DbContext.Shifts.Where(s =>
                                                      s.Bar.Id == id &&
                                                      s.Start <end &&
                                                               s.End> start &&
                                                      friends.Contains(s.Profile.FacebookId))
                         .ToArrayAsync();

            return(Ok(shifts.Select(s => s.ToDto())));
        }