public IHttpActionResult Follow(FollowDto dto) { var userId = User.Identity.GetUserId(); var follow = new Follow { FollowedId = dto.Followed, FollowerId = userId }; if (_context.Follows.Any(f => f.FollowedId == dto.Followed && f.FollowerId == userId)) { return(BadRequest("Already Following")); } _context.Follows.Add(follow); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult Follow(FollowDto dto) { var userId = User.Identity.GetUserId(); if (_context.Follows.Any(f => f.FollowerId == userId && f.FollowingId == dto.ArtistId)) { return(BadRequest("You are already following this artist!")); } var follow = new Follow { FollowerId = userId, FollowingId = dto.ArtistId }; _context.Follows.Add(follow); _context.SaveChanges(); return(Ok()); }
public IHttpActionResult Follow(FollowDto followDto) { var userId = User.Identity.GetUserId(); if (_context.Follows.Any(f => f.UserId == userId && f.ArtistId == followDto.ArtistId)) { return(BadRequest("User already follows follow.")); } var follow = new Follow { UserId = userId, ArtistId = followDto.ArtistId }; _context.Follows.Add(follow); _context.SaveChanges(); return(Ok()); }
// POST: api/Follow public IHttpActionResult Post(FollowDto FollowDto) { try { string FolloweeId = FollowDto.FolloweeId; string userID = User.Identity.GetUserId(); bool exist = _context.Followings .Any(c => c.FolloweeId == FolloweeId && c.FollowerId == userID); if (exist) { return(BadRequest("this Attendance Already Exists.")); } var followee = _context.Users .FirstOrDefault(c => c.Id == FolloweeId); if (followee == null) { return(Content(System.Net.HttpStatusCode.NotFound, $"The Artist with id {FolloweeId} is not found.")); } var follow = new Following() { FollowerId = userID, FolloweeId = FolloweeId }; _context.Followings.Add(follow); _context.SaveChanges(); } catch (System.Exception e) { return(StatusCode(System.Net.HttpStatusCode.InternalServerError)); } return(Ok("Added Successfully.")); }
public IHttpActionResult follow(FollowDto dto) { var userId = User.Identity.GetUserId(); var exists = _context.Followers.Any(u => u.FollowerId == userId && u.FolloweeId == dto.FolloweeId); if (exists) { return(BadRequest("The attendance already exists.")); } var follow = new Follow { FollowerId = userId, FolloweeId = dto.FolloweeId }; _context.Followers.Add(follow); _context.SaveChanges(); return(Ok()); }