Example #1
0
        public async Task <bool> AcceptMeeting(int meetingId, int userId, int schoolId, int currentUserId)
        {
            var meeting = await database.UserRepository.Get <Meeting>(meetingId);

            if (meeting.Accepted || currentUserId == meeting.ArrangedBy)
            {
                return(false);
            }

            var school = await database.SchoolRepository.Get <School>(schoolId);

            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);
            }

            meeting.Accept();

            if (!await database.Complete())
            {
                return(false);
            }

            if (currentUserId == school.OwnerId)
            {
                await notificationSystem.PushNotification(userId, StaticExpressions.MeetingAcceptedByOwner(school.Name));
            }
            else
            {
                await notificationSystem.PushNotification(school.OwnerId, StaticExpressions.MeetingAccepted);
            }

            return(true);
        }