Ejemplo n.º 1
0
        public async Task <ActionResult> ApproveCircleEventParticipation([FromBody] CircleEventParticipation model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var circleEventFromRepo = await _repo.Get <CircleEvent>(model.CircleEventId);

            if (circleEventFromRepo == null)
            {
                return(NotFound("イベントが見つかりません"));
            }
            if (!await this.MatchAppUserWithToken(circleEventFromRepo.AppUserId))
            {
                return(Unauthorized());
            }
            var circleEventParticipationFromRepo = await _repo.GetCircleEventParticipation((int)model.AppUserId, model.CircleEventId);

            if (circleEventParticipationFromRepo == null)
            {
                return(NotFound("参加リクエストが見つかりません"));
            }

            circleEventParticipationFromRepo.Status = CircleEventParticipationStatus.Confirmed;
            await _notificationRepo.AddNotification(NotificationEnum.EventParticipationRequestAccepted, (int)circleEventFromRepo.AppUserId, model);

            await _repo.SaveAll();

            return(Ok());
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Post([FromBody] CircleEventParticipation model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId))
            {
                return(Unauthorized());
            }
            var circleEventFromRepo = await _repo.Get <CircleEvent>(model.CircleEventId);

            if (circleEventFromRepo == null)
            {
                return(NotFound("イベントが見つかりません: " + model.CircleEventId));
            }
            var existingRequest = await _repo.GetCircleEventParticipation((int)model.AppUserId, model.CircleEventId);

            if (existingRequest != null)
            {
                return(BadRequest("既にリクエストしています"));
            }

            if (circleEventFromRepo.ApprovalRequired || await _repo.IsEventFull(circleEventFromRepo.Id))
            {
                await _notificationRepo.AddNotification(NotificationEnum.NewCircleEventParticipationRequest, (int)circleEventFromRepo.AppUserId, circleEventFromRepo);
            }
            else
            {
                model.Status = CircleEventParticipationStatus.Confirmed;
            }

            _repo.Add(model);
            await _repo.SaveAll();

            return(CreatedAtRoute("GetCircleEventParticipation", new { userId = model.AppUserId, eventId = model.CircleEventId }, _mapper.Map <CircleEventParticipationForReturnDto>(model)));
        }
        private async Task <HttpResponseMessage> approveEventParticipation(string eventOwnerName, CircleEventParticipation participation)
        {
            await LoginByUser(eventOwnerName);

            var contents = BuildStringContent(participation);

            return(await _client.PutAsync("/api/circleeventparticipation/approve", contents));
        }
Ejemplo n.º 5
0
        private async Task EventParticipationRequestAcceptedNotification(int appUserId, CircleEventParticipation eventParticipation)
        {
            var participationFromRepo = await _context.CircleEventParticipations.Include(cep => cep.CircleEvent).FirstOrDefaultAsync(cep => cep.AppUserId == eventParticipation.AppUserId && cep.CircleEventId == eventParticipation.CircleEventId);

            if (participationFromRepo == null)
            {
                return;
            }
            Dictionary <string, int> recordIds = new Dictionary <string, int>()
            {
                { "Circle", participationFromRepo.CircleEvent.CircleId },
            };

            await AddNotificationIfNotExist(new Notification()
            {
                AppUserId         = (int)participationFromRepo.AppUserId,
                NotificationType  = NotificationEnum.EventParticipationRequestAccepted,
                RecordType        = "CircleEvent",
                RecordId          = participationFromRepo.CircleEventId,
                RelatingRecordIds = JObject.FromObject(recordIds),
                TargetRecordTitle = participationFromRepo.CircleEvent.Title
            });
        }