Exemplo n.º 1
0
        public async Task <ActionResult> CancelCircleEventParticipation([FromBody] CircleEventParticipation model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId))
            {
                return(Unauthorized());
            }
            var eventParticipationFromRepo = await _repo.GetCircleEventParticipation((int)model.AppUserId, model.CircleEventId);

            if (eventParticipationFromRepo == null)
            {
                return(NotFound());
            }

            eventParticipationFromRepo.Status = CircleEventParticipationStatus.Canceled;
            var firstWaitingParticipant = await _repo.GetCircleEventFirstWaitingParticipation(model.CircleEventId);

            if (firstWaitingParticipant != null)
            {
                firstWaitingParticipant.Status = CircleEventParticipationStatus.Confirmed;
                await _notificationRepo.AddNotification(NotificationEnum.EventParticipationRequestAccepted, (int)model.AppUserId, firstWaitingParticipant);
            }

            await _repo.SaveAll();

            return(Ok());
        }