示例#1
0
        public async Task <ActionResult> Post([FromBody] CircleEventUpdateDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId) || !await _repo.IsOwner((int)model.AppUserId, model.CircleId))
            {
                return(Unauthorized());
            }

            var newEvent = this._mapper.Map <CircleEvent>(model);

            _repo.Add(newEvent);
            CircleEvent oldestEvent = null;

            if (await _repo.GetCircleEventCount(model.CircleId) >= CIRCLE_EVENT_MAX)
            {
                oldestEvent = await _repo.GetOldestCircleEvent(model.CircleId);

                _repo.Delete(oldestEvent);
            }
            await _repo.SaveAll();

            if (oldestEvent != null)
            {
                await this.deleteAttachedPhotos(oldestEvent.Photos);
            }

            return(CreatedAtRoute("GetCircleEvent", new { id = newEvent.Id }, _mapper.Map <CircleEventForReturnDto>(await _repo.Get <CircleEvent>(newEvent.Id))));
        }
示例#2
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)));
        }
        public async Task <ActionResult> SendCircleRequest([FromBody] CircleRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId))
            {
                return(Unauthorized());
            }
            if (await _repo.IsMember((int)model.AppUserId, model.CircleId))
            {
                return(BadRequest("既にメンバーになっています"));
            }
            var circleFromRepo = await _repo.Get <Circle>(model.CircleId);

            if (circleFromRepo == null)
            {
                return(NotFound("サークルレコードが見つかりません: " + model.CircleId));
            }
            if (await _repo.RequestSent((int)model.AppUserId, model.CircleId))
            {
                return(BadRequest("既にリクエストしています"));
            }

            if (circleFromRepo.ApprovalRequired)
            {
                _repo.Add(model);
                await _notificationRepo.AddNotification(NotificationEnum.NewCircleMemberRequest, model.AppUserId, model);

                await _repo.SaveAll();

                return(CreatedAtRoute("GetCircleRequest", new { userId = model.AppUserId, circleId = model.CircleId }, null));
            }
            _repo.Add(new CircleMember()
            {
                AppUserId      = (int)model.AppUserId,
                CircleId       = model.CircleId,
                Role           = CircleRoleEnum.MEMBER,
                DateJoined     = DateTime.Now,
                DateLastActive = DateTime.Now
            });
            await _repo.SaveAll();

            return(CreatedAtRoute("GetCircleMember", new { userId = model.AppUserId, circleId = model.CircleId }, null));
        }