public async Task <bool> CancelMeeting(int meetingId, int userId, int schoolId, int currentUserId, bool isRejected = false) { var meeting = await database.UserRepository.Get <Meeting>(meetingId); var school = await database.SchoolRepository.Get <School>(schoolId); if (isRejected && currentUserId == meeting.ArrangedBy) { return(false); } if (currentUserId != meeting.UserId && currentUserId != userId && currentUserId != school.OwnerId) { return(false); } if (!school.Meetings.Any(m => m.Id == meetingId && m.UserId == userId && m.SchoolId == schoolId)) { return(false); } if (meeting.Accepted && isRejected) { return(false); } database.UserRepository.Remove(meeting); if (!await database.Complete()) { return(false); } if (currentUserId == school.OwnerId) { if (!isRejected) { await notificationSystem.PushNotification(userId, StaticExpressions.MeetingCancelledByOwner(school.Name)); } else { await notificationSystem.PushNotification(userId, StaticExpressions.MeetingRejectedByOwner(school.Name)); } } else { if (!isRejected) { await notificationSystem.PushNotification(school.OwnerId, StaticExpressions.MeetingCancelled); } else { await notificationSystem.PushNotification(school.OwnerId, StaticExpressions.MeetingRejected); } } return(true); }