Beispiel #1
0
        // GET: Topics/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var topic = await topicService.GetTopicByIdAsync(id);

            await topicService.DeleteAsync(topic);

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

            return(View(topic));
        }
Beispiel #2
0
        public async Task <IActionResult> DeleteTopic([Required] string id)
        {
            var topic = await _topicService.GetByIdAsync(id);

            ValidateUser(topic.UserId);

            await _topicService.DeleteAsync(id);

            return(Ok());
        }
        /// <summary>
        /// Asks the service to asynchronously delete the topic uniquely identified through Id.
        /// </summary>
        /// <param name="id">
        /// The topics unique identifier.
        /// </param>
        /// <returns>
        /// HTTP Status Code 204 - No Content if topic was successfully deleted, or did not exist,
        ///     HTTP Status Code 500 - Internal Server Error if the other codes don't apply. Contains exception on DEBUG.
        /// </returns>
        public async Task <IHttpActionResult> Delete(int id)
        {
            var result = await _topicService.DeleteAsync(id);

            if (result.ActionStatus.Status == ActionStatusEnum.Success)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }

            return(HandleErrorActionResult(result));
        }
        public async Task <IActionResult> DeleteAsync(int courseId, int id)
        {
            var result = await _topicService.DeleteAsync(courseId, id);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var topicResource = _mapper.Map <Topic, TopicResource>(result.Resource);

            return(Ok(topicResource));
        }
Beispiel #5
0
        public async Task <ActionResult> DeleteTopic(Guid forumId, Guid topicId)
        {
            var site = await _contextService.CurrentSiteAsync();

            var user = await _contextService.CurrentUserAsync();

            var command = new DeleteTopic
            {
                Id      = topicId,
                ForumId = forumId,
                SiteId  = site.Id,
                UserId  = user.Id
            };

            var topicUserId = await _dbContext.Posts
                              .Where(x =>
                                     x.Id == command.Id &&
                                     x.TopicId == null &&
                                     x.ForumId == command.ForumId &&
                                     x.Forum.Category.SiteId == command.SiteId &&
                                     x.Status != PostStatusType.Deleted)
                              .Select(x => x.CreatedBy)
                              .FirstOrDefaultAsync();

            var permissions = await _permissionModelBuilder.BuildPermissionModelsByForumId(site.Id, forumId);

            var canDelete   = _securityService.HasPermission(PermissionType.Delete, permissions);
            var canModerate = _securityService.HasPermission(PermissionType.Moderate, permissions);
            var authorized  = (canDelete && topicUserId == user.Id || canModerate) && !user.IsSuspended;

            if (!authorized)
            {
                _logger.LogWarning("Unauthorized access to delete topic", new
                {
                    SiteId  = site.Id,
                    ForumId = forumId,
                    TopicId = topicId,
                    User    = User.Identity.Name
                });

                return(Unauthorized());
            }

            await _topicService.DeleteAsync(command);

            return(Ok());
        }
Beispiel #6
0
        public async Task DeleteAsync(string id)
        {
            PlanArea planArea = await _planAreaReadRepository.GetByIdAsync(id);

            if (planArea == null)
            {
                throw new DomainServicesException("Plan Area not found.");
            }

            foreach (AreaTopic areaTopic in _topicService.GetBy(planArea))
            {
                await _topicService.DeleteAsync(areaTopic.Id);
            }

            await _planAreaWriteRepository.DeleteAsync(planArea);
            await _planAreaWriteRepository.SaveChangesAsync();
        }
        public async Task DeleteAsync(string id)
        {
            PlanArea planArea = await _planAreaObjectService.GetByIdAsync <PlanArea>(id);

            if (planArea == null)
            {
                throw new DomainServicesException("Plan Area not found.");
            }

            foreach (AreaTopic areaTopic in _topicService.GetBy(planArea))
            {
                await _topicService.DeleteAsync(areaTopic.Id);
            }



            await _planAreaObjectService.DeleteAsync(planArea);
        }
Beispiel #8
0
        public async Task <IResponseWrapper> Handle(DeleteTopicCommand request, CancellationToken cancellationToken)
        {
            await _topicService.DeleteAsync(request.Topic.Id, cancellationToken);

            return(Response.Ok());
        }