public IActionResult LendcardsTo([FromBody] LendContract lendContract) { try { var uId = Utility.UserInfo.Id(HttpContext.User); var userEmail = Utility.UserInfo.Email(HttpContext.User); var reciverExists = _userSource.UserExists(lendContract.Lender); if (!reciverExists) { return(StatusCode(401)); } var markAsLent = _collectionSource.MarkCardAsLent(uId, lendContract.Lendee, lendContract.CardsAndAmounts); var uIdOfRevicer = lendContract.Lendee; var reciveCard = _collectionSource.AddCardAsLent(uId, lendContract.Lendee, lendContract.CardsAndAmounts); if (markAsLent && reciveCard) { return(StatusCode(200)); } return(StatusCode(500)); } catch (Exception) { return(StatusCode(500)); } }
public void AcceptLoanRequest([FromBody] string messageId) { var userId = HttpContext.User.Id(); var message = _messageSource.GetMessageById(userId, messageId); if (message.Type != "Loan") { return; } var loanRequest = message as LoanRequestMessage; _collectionSource.MarkCardAsLent(loanRequest.RecipientId, loanRequest.SenderId, loanRequest.RequestedCardsAndAmounts); _collectionSource.AddCardAsLent(loanRequest.RecipientId, loanRequest.SenderId, loanRequest.RequestedCardsAndAmounts); _messageSource.DeleteMessage(userId, messageId); }