public IActionResult RejectFriendRequeust([FromBody] RequestResponseViewModel requestResponseViewModel) { try { var friendship = _friendshipRepo.AcceptRequest(requestResponseViewModel.Notification.CreatedBy, requestResponseViewModel.LoggedInUserId); if (friendship != null) { //Update the friendship status to 3: Rejected! friendship.FriendshipStatusId = 3; _friendshipRepository.Update(friendship); //Update the acknowledgement status of the notification requestResponseViewModel.Notification.NotificationAcknowledged = true; _notificationRespository.Update(requestResponseViewModel.Notification); return(Ok(true)); } else { return(BadRequest()); } } catch (Exception e) { return(BadRequest()); } }
public IActionResult AcceptFriendRequeust([FromBody] RequestResponseViewModel requestResponseViewModel) { try { //get the friendship object from the friendship table var friendship = _friendshipRepo.AcceptRequest(requestResponseViewModel.Notification.CreatedBy, requestResponseViewModel.LoggedInUserId); if (friendship != null) { //If friendship object exists, change the status to 2: Accepted! friendship.FriendshipStatusId = 2; _friendshipRepository.Update(friendship); //Update the acknowledgement status of the original notification requestResponseViewModel.Notification.NotificationAcknowledged = true; _notificationRespository.Update(requestResponseViewModel.Notification); //Create a new notification for friend requested accepted event //get the UserName of the request accepter and create a notification var requestAcceptor = _userRepo.Find(u => u.Id == requestResponseViewModel.LoggedInUserId).SingleOrDefault(); var notification = new Notification { NotificationTypeId = (int)NotificationTypeConstants.FriendRequestAccepted, NotificationDetails = $"{requestAcceptor.FirstName + ' ' + requestAcceptor.LastName} accepted your request", NotificationAcknowledged = false, CreatedBy = requestResponseViewModel.LoggedInUserId, CreatedDateTime = DateTime.UtcNow }; _notificationRespository.Add(notification); _notificationRespository.SaveChanges(); //get the notification id and save it in the UserNotificationRefTable int NotificationId = notification.NotificationId; var userNotificationRef = new UserNotificationRef { NotificationId = NotificationId, RecipientUserId = requestResponseViewModel.Notification.CreatedBy }; _userNotificationRef.Add(userNotificationRef); _userNotificationRef.SaveChanges(); return(Ok()); } else { return(BadRequest()); } } catch (Exception e) { return(BadRequest()); } }