public async Task <IActionResult> PostComment([FromBody] Comment comment) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _context.Comment.AddAsync(comment); await _context.SaveChangesAsync(); return(StatusCode(201)); }
public async Task <IActionResult> PostLikes([FromBody] Like like) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var wait = await checkIfLiked(like.UserId, like.CommentId); if (wait == true) { return(BadRequest("Already in the database")); } else { _context.Like.Add(like); await _context.SaveChangesAsync(); return(Ok(like)); } }
public async Task <IActionResult> PostUser([FromBody] User user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _check.UsernameExist(user.Username)) { if (await _check.EmailExist(user.Email)) { return(BadRequest("Username and Email is already taken")); } return(BadRequest("Username already exists")); } else if (await _check.EmailExist(user.Email)) { if (await _check.UsernameExist(user.Username)) { return(BadRequest("Username and Email is already taken")); } return(BadRequest("Email already exists")); } var hashedPassword = _auth.HashPassword(user.Password); var newUser = new User { Username = user.Username.ToLower(), FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, Password = hashedPassword }; await _context.User.AddAsync(newUser); await _context.SaveChangesAsync(); var newPostedUser = await _context.User.FirstOrDefaultAsync(x => x.Username == user.Username); return(Ok(newPostedUser)); }
public async Task <IActionResult> Post([FromBody] Follow follow) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = follow.UserId; var followId = follow.FollowedUserId; if (await _check.UserFollowed(userId, followId)) { return(BadRequest("Already Followed")); } await _context.Follow.AddAsync(follow); await _context.SaveChangesAsync(); return(Ok(follow)); }