public bool SendFriendRequest(FriendRequestInputModel model) { try { this.friendRequestData.SendFriendRequest(model); return(true); } catch (Exception) { return(false); } }
public void SendFriendRequest(FriendRequestInputModel model) { using (SqlConnection conn = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand("tdb_frr_ins", conn); cmd.CommandType = CommandType.StoredProcedure; conn.Open(); cmd.Parameters.AddWithValue("@snd_id", model.SenderId); cmd.Parameters.AddWithValue("@rsv_id", model.ReceiverId); cmd.Parameters.AddWithValue("@status", model.Status); cmd.ExecuteNonQuery(); conn.Close(); }; }
public IHttpActionResult SendFriendRequest(int recieverId) { if (!this.CheckIfUserExist(recieverId)) { return(this.BadRequest($"User with id {recieverId} does not exist.")); } int userId = this.GetUserId(); if (userId == recieverId) { return(this.BadRequest("You can`t sennd friend request to yourself.")); } FriendRequestInputModel model = new FriendRequestInputModel { SenderId = userId, ReceiverId = recieverId, Status = "Pending" }; bool doesRequestExist = this.ChechIfRequestExist(userId, STATUS_PENDING, model.ReceiverId); bool doesOpositeRequestExist = this.ChechIfRequestExist(model.ReceiverId, STATUS_PENDING, userId); if (doesRequestExist) { return(this.BadRequest($"You already send friend request to user with id {model.ReceiverId}. Wait for response.")); } if (doesOpositeRequestExist) { return(this.BadRequest($"You already have friend request from user with id {model.ReceiverId}. You have to respond.")); } try { this.friendRequestSevice.SendFriendRequest(model); return(this.Ok("Request sent successfully")); } catch (Exception ex) { return(this.BadRequest(ex.Message)); } }
public async Task <ActionResult <ApiResultViewModel <FriendRequest> > > SendFriendRequest([FromRoute] long accountId, [FromBody] FriendRequestInputModel inputModel, CancellationToken cancellationToken) { if (accountId != AccountId) { return(Forbidden()); } if (inputModel.FriendAccountId == accountId) { return(BadRequest("invalid_friendAccountId", "you cannot friend yourself")); } var friendAccount = await _accountManager.GetAsync(inputModel.FriendAccountId, cancellationToken); if (friendAccount == null || friendAccount.IsArchived) { return(BadRequest("invalid_friendAcccountId", "friend account not found.")); } var friendRequest = await _friendRequestManager.GetExistingRequest(accountId, inputModel.FriendAccountId, cancellationToken); if (friendRequest != null) { return(BadRequest("already_exists", "Friend request already sent.")); } if (await _accountFriendManager.IsFriendAsync(accountId, inputModel.FriendAccountId, cancellationToken)) { return(BadRequest("already_friends", "Requested player is already in your friend list.")); } friendRequest = new FriendRequest { FromAccountId = accountId, ToAccountId = inputModel.FriendAccountId, RequestDateTime = DateTime.UtcNow, StatusId = FriendRequestStatus.Pending }; var account = await _accountManager.GetAsync(accountId, cancellationToken); friendRequest = await _friendRequestManager.SaveAsync(friendRequest, cancellationToken); await _notificationManager.SaveAsync( new Core.Entities.Notification { AccountId = friendRequest.ToAccountId, Body = $"friend request sent by {account.Email}", NotificationTypeId = NotificationTypeIds.General, Title = "Friend Request" }, cancellationToken); return(CreatedData(friendRequest)); }