public async Task <ActionResult> Delete(int id)
        {
            var circleTopicCommentFromRepo = await _repo.GetCircleTopicComment(id);

            if (circleTopicCommentFromRepo == null)
            {
                return(NotFound());
            }
            if (!await MatchAppUserWithToken((int)circleTopicCommentFromRepo.AppUserId))
            {
                return(Unauthorized());
            }

            _repo.Delete(circleTopicCommentFromRepo);
            await _repo.SaveAll();

            if (circleTopicCommentFromRepo.PhotoId != null)
            {
                _repo.Delete(circleTopicCommentFromRepo.Photo);
                var task = this._imageFileStorageManager.DeleteImageFileAsync(circleTopicCommentFromRepo.Photo);
            }

            await _repo.SaveAll();

            return(Ok());
        }
Exemplo n.º 2
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.º 3
0
        public async Task <ActionResult> ApproveCircleRequest([FromBody] CircleRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var loggedInUser = await GetLoggedInUserAsync();

            if (loggedInUser == null)
            {
                return(Unauthorized());
            }
            if (!await _repo.IsOwner(loggedInUser.Id, model.CircleId))
            {
                return(Unauthorized());
            }
            var circleRequestFromRepo = await _repo.GetCircleRequest((int)model.AppUserId, model.CircleId);

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

            _repo.Delete(circleRequestFromRepo);
            //If already member, just remove request and create nothing
            if (await _repo.IsMember(model.AppUserId, model.CircleId))
            {
                await _repo.SaveAll();

                return(Ok());
            }

            var newCircleMember = new CircleMember()
            {
                AppUserId      = (int)model.AppUserId,
                Circle         = circleRequestFromRepo.Circle,
                CircleId       = model.CircleId,
                Role           = CircleRoleEnum.MEMBER,
                DateJoined     = DateTime.Now,
                DateLastActive = DateTime.Now
            };

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

            await _notificationRepo.AddNotification(NotificationEnum.CircleRequestAccepted, model.AppUserId, newCircleMember);

            await _repo.SaveAll();

            return(CreatedAtRoute("GetCircleMember", new { userId = model.AppUserId, circleId = model.CircleId }, _mapper.Map <CircleMemberForReturnDto>(await _repo.GetCircleMember(model.AppUserId, model.CircleId))));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Delete(int id)
        {
            var circleFromRepo = await _repo.GetCircle(id);

            if (circleFromRepo == null)
            {
                return(NotFound());
            }
            var loggedInUser = await GetLoggedInUserAsync();

            if (!await _repo.CheckUpdatePermission(loggedInUser.Id, id))
            {
                return(Unauthorized());
            }

            //TODO: Delete All Photos of relating records (and relating records itself as well)

            _repo.Delete(circleFromRepo);
            await _repo.SaveAll();

            var errors = this._imageFileStorageManager.DeleteAttachedPhotos(circleFromRepo.Photos);

            foreach (var error in errors)
            {
                this._logger.LogError(error);
            }
            await _repo.SaveAll();

            return(Ok());
        }
        public Task <Unit> Handle(CircleDeleteCommand request, CancellationToken cancellationToken)
        {
            using var transaction = new TransactionScope();

            var circle = _circleRepository.Find(new CircleId(request.UserId));

            if (circle != null)
            {
                _circleRepository.Delete(circle);
            }

            transaction.Complete();

            return(Task.FromResult(Unit.Value));
        }
Exemplo n.º 6
0
        public void Delete(CircleDeleteCommand command)
        {
            using (var transaction = new TransactionScope())
            {
                var id     = new CircleId(command.Id);
                var circle = circleRepository.Find(id);
                if (circle == null)
                {
                    return;
                }

                circleRepository.Delete(circle);

                transaction.Complete();
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult> Delete(int id)
        {
            var circleEventCommentReplyFromRepo = await _repo.GetCircleEventCommentReply(id);

            if (circleEventCommentReplyFromRepo == null)
            {
                return(NotFound());
            }
            if (!await MatchAppUserWithToken((int)circleEventCommentReplyFromRepo.AppUserId))
            {
                return(Unauthorized());
            }

            _repo.Delete(circleEventCommentReplyFromRepo);
            await _repo.SaveAll();

            return(Ok());
        }
Exemplo n.º 8
0
        public CircleDeleteOutputData Handle(CircleDeleteInputData inputData)
        {
            using var transaction = new TransactionScope();

            var id     = new CircleId(inputData.Id);
            var circle = circleRepository.Find(id);

            if (circle == null)
            {
                return(new CircleDeleteOutputData());
            }

            circleRepository.Delete(circle);

            transaction.Complete();

            return(new CircleDeleteOutputData());
        }
Exemplo n.º 9
0
        public async Task <ActionResult> Delete(int appUserId, int eventId)
        {
            if (!await this.MatchAppUserWithToken(appUserId))
            {
                return(Unauthorized());
            }

            var participationFromRepo = await _repo.GetCircleEventParticipation(appUserId, eventId);

            if (participationFromRepo == null)
            {
                return(NotFound());
            }
            _repo.Delete(participationFromRepo);
            await _repo.SaveAll();

            return(Ok());
        }