public async Task <ActionResult> Post([FromBody] UserCommentUpdateDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var circleTopic = await _repo.GetCircleTopic(model.OwnerRecordId);

            if (circleTopic == null)
            {
                return(NotFound());
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId) || !await _repo.IsMember((int)model.AppUserId, circleTopic.CircleId))
            {
                return(Unauthorized());
            }

            // model.CircleId = circleTopic.CircleId;
            var newTopic = this._mapper.Map <CircleTopicComment>(model);

            newTopic.CircleId = circleTopic.CircleId;
            _repo.Add(newTopic);
            await _repo.SaveAll();

            return(CreatedAtRoute("GetCircleTopicComment", new { id = model.Id }, _mapper.Map <CircleTopicCommentForReturnDto>(newTopic)));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Post([FromBody] CircleEventCommentReply model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var circleEventComment = await _repo.GetCircleEventComment(model.CommentId);

            if (circleEventComment == null)
            {
                return(NotFound());
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId) || !await _repo.IsMember((int)model.AppUserId, circleEventComment.CircleId))
            {
                return(Unauthorized());
            }

            model.CircleId = circleEventComment.CircleId;
            // var newTopic = this._mapper.Map<CircleEvent>(model);
            _repo.Add(model);
            await _repo.SaveAll();

            if (circleEventComment.AppUserId == model.AppUserId) //Comment owner
            {
                await _notificationRepo.AddNotification(NotificationEnum.NewCircleEventReplyByOwner, (int)model.AppUserId, model);
            }
            else
            {
                await _notificationRepo.AddNotification(NotificationEnum.NewCircleEventReplyByMember, (int)model.AppUserId, model);
            }
            await _repo.SaveAll();

            return(CreatedAtRoute("GetCircleEventCommentReply", new { id = model.Id }, _mapper.Map <CommentForReturnDto>(model)));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Post([FromBody] CircleUpdateDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId))
            {
                return(Unauthorized());
            }

            var newCircle = this._mapper.Map <Circle>(model);
            var ownerUser = await _appUserRepo.GetAppUser(model.AppUserId);

            if (ownerUser == null)
            {
                _logger.LogError("User not found: " + model.AppUserId);
                return(NotFound("ユーザーが見つかりません"));
            }

            newCircle.CircleMemberList = new List <CircleMember>()
            {
                new CircleMember()
                {
                    AppUserId = model.AppUserId,
                    Role      = CircleRoleEnum.OWNER,
                    CircleId  = newCircle.Id
                }
            };

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

            return(CreatedAtRoute("GetCircle", new { id = newCircle.Id }, _mapper.Map <CircleForReturnDto>(newCircle)));
        }
Exemplo n.º 4
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))));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> Post([FromBody] CircleTopicUpdateDto model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (!await this.MatchAppUserWithToken(model.AppUserId) || !await _repo.IsMember(model.AppUserId, model.CircleId))
            {
                return(Unauthorized());
            }

            var newTopic = this._mapper.Map <CircleTopic>(model);

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

            await _notificationRepo.AddNotification(NotificationEnum.NewCircleTopicCreated, model.AppUserId, newTopic);

            await _repo.SaveAll();

            return(CreatedAtRoute("GetCircleTopic", new { id = newTopic.Id }, _mapper.Map <CircleTopicForReturnDto>(await _repo.GetCircleTopic(newTopic.Id))));
        }
Exemplo n.º 6
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)));
        }
Exemplo n.º 7
0
        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));
        }