public void UpdateFollow(Follow followToUpdate, FollowRequestData RequestData)
 {
     // can only change the stats.
     followToUpdate.FollowState = RequestData.State;
     _context.Follows.Update(followToUpdate);
     _context.SaveChanges();
 }
Beispiel #2
0
        public IActionResult CreateFollow([FromBody] FollowRequestData RequestData)
        {
            if (!_service.IsAuthorizedRider(RequestData))
            {
                return(Unauthorized());
            }

            if (!_service.RiderExists(RequestData.FollowerId))
            {
                return(NotFound());
            }
            if (!_service.RiderExists(RequestData.FollowingId))
            {
                return(NotFound());
            }

            if (_service.FollowExists(RequestData))
            {
                return(Ok(_service.GetFollow(RequestData)));
            }

            if (ModelState.IsValid)
            {
                var follow = _service.AddFollow(RequestData);
                return(Ok(follow));
            }
            return(Unauthorized());
        }
Beispiel #3
0
        public IActionResult GetAllFollowers(FollowRequestData RequestData)
        {
            if (!_service.IsAuthorized(RequestData))
            {
                return(Unauthorized());
            }

            return(Ok(_context.Follows.ToList()));
        }
        public Follow GetFollow(FollowRequestData RequestData)
        {
            Follow follow = _context.Follows.SingleOrDefault <Follow>(f => f.FollowingID == RequestData.FollowingId && f.FollowerID == RequestData.FollowerId);

            if (follow != null)
            {
                return(follow);
            }
            return(null);
        }
Beispiel #5
0
        public IActionResult GetFollowById(FollowRequestData RequestData)
        {
            if (!_service.IsAuthorized(RequestData))
            {
                return(Unauthorized());
            }

            var follows = _context.Follows.Where(f => f.FollowID == RequestData.FollowId).SingleOrDefault();

            return(Ok(follows));
        }
Beispiel #6
0
        public IActionResult GetFollow(FollowRequestData RequestData)
        {
            if (!_service.IsAuthorized(RequestData))
            {
                return(Unauthorized());
            }

            var follows = _service.GetFollow(RequestData);

            return(Ok(follows));
        }
Beispiel #7
0
        public IActionResult GetMyFollowing(FollowRequestData RequestData)
        {
            if (!_service.IsAuthorized(RequestData))
            {
                return(Unauthorized());
            }

            var follows = _context.Follows.Where(f => f.FollowerID == RequestData.FollowerId).ToList();

            return(Ok(follows));
        }
 public bool IsAuthorized(FollowRequestData RequestData)
 {
     if ((RequestData.RequestingId == RequestData.FollowerId) ||
         (RequestData.RequestingId == RequestData.FollowingId))
     {
         return(IsAuthorizedRider(RequestData));
     }
     else
     {
         return(IsAuthorizedAdmin(RequestData));
     }
 }
        public Follow AddFollow(FollowRequestData RequestData)
        {
            Follow f = new Follow();

            f.FollowingID = RequestData.FollowingId;
            f.FollowerID  = RequestData.FollowerId;
            f.FollowState = FollowStateType.FollowRequested;

            // Set up  the actual follow data
            //f.FollowerRider = _riderService.GetRiderByID(f.FollowerID);
            //f.FollowingRider = _riderService.GetRiderByID(f.FollowingID);
            _context.Add(f);
            _context.SaveChanges();
            return(f);
        }
Beispiel #10
0
        public async Task <IActionResult> DeleteFollowById([FromBody] FollowRequestData RequestData)
        {
            if (!_service.IsAuthorized(RequestData))
            {
                return(Unauthorized());
            }

            var follow = await _context.Follows.SingleOrDefaultAsync(
                f => f.FollowID == RequestData.FollowId);

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

            // Do the delete...
            _context.Follows.Remove(follow);
            await _context.SaveChangesAsync();

            return(Ok());
        }
        public bool IsAuthorizedRider(FollowRequestData RequestData)
        {
            return(_riderService.IsAuthorizedRider(RequestData.RequestingId, RequestData.Authorization));

            /*
             * bool result = false;
             * if (RiderExists(RequestData.RequestingId))
             * {
             *  if (Auth.IsValidToken(RequestData.Authorization))
             *  {
             *      Rider foundRider = _context.Riders.SingleOrDefault(m => m.ID == RequestData.RequestingId);
             *      if (foundRider != null)
             *      {
             *          string userAuth = Auth.GenerateJWT(foundRider);
             *          if ((RequestData.Authorization == userAuth))
             *              result = true;
             *      }
             *  }
             * }
             * return result;
             */
        }
Beispiel #12
0
        public IActionResult DeleteMyFollowings([FromBody] FollowRequestData RequestData)
        {
            if (!_service.IsAuthorizedRider(RequestData))
            {
                return(Unauthorized());
            }

            // verify there is at least one signup!
            var follow = _context.Follows.SingleOrDefault(
                f => f.FollowerID == RequestData.FollowerId);

            if (follow != null)
            {
                // here we do a range delete on the RiderID...
                _context.Follows.RemoveRange(
                    _context.Follows.Where(
                        f => f.FollowerID == RequestData.FollowerId
                        )
                    );
                _context.SaveChangesAsync();
            }
            return(Ok());
        }
Beispiel #13
0
        public IActionResult EditFollow([FromBody] FollowRequestData RequestData)
        {
            if (!_service.IsAuthorized(RequestData))
            {
                return(Unauthorized());
            }

            var followToUpdate = _context.Follows.SingleOrDefault(f => f.FollowID == RequestData.FollowId);

            if (followToUpdate != null)
            {
                try
                {
                    _service.UpdateFollow(followToUpdate, RequestData);
                    return(Ok());
                }

                catch (DbUpdateException /* ex */)
                {
                    return(NotFound());
                }
            }
            return(NotFound());
        }
 public bool FollowExists(FollowRequestData RequestData)
 {
     return(_context.Follows.Any(e => e.FollowerID == RequestData.FollowerId && e.FollowingID == RequestData.FollowingId));
 }