Пример #1
0
        public async Task <IActionResult> ToggleIsPinnedOption(TPrimaryKey threadId)
        {
            var threadDto = await _threadService.GetAsync(threadId);

            var isCurrentUserCategoryModerator = await _categoryToModeratorService
                                                 .IsUserCategoryModeratorAsync(threadDto.CategoryId, User);

            if (isCurrentUserCategoryModerator)
            {
                threadDto.IsPinned = !threadDto.IsPinned;
                await _threadService.EditAsync(threadDto, GetCurrentUserId());

                var categoryDto = await _categoryService.GetAsync(threadDto.CategoryId);

                return(RedirectToAction("Details", "Threads", new { categoryAlias = categoryDto.Alias, threadId = threadDto.Id }));
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden, $"Access denied");
            }
        }
Пример #2
0
        public async Task <IActionResult> Edit(string categoryAlias, TPrimaryKey threadId, ThreadEditViewModel threadEditViewModel)
        {
            var threadDto = await _threadService.GetAsync(threadId);

            _mapper.Map(threadEditViewModel, threadDto);
            var isCurrentUserCategoryModerator = await _categoryToModeratorService
                                                 .IsUserCategoryModeratorAsync(threadDto.CategoryId, User);

            if (isCurrentUserCategoryModerator)
            {
                await _threadService.EditAsync(threadDto);

                return(RedirectToAction("Details", "Threads", new { categoryAlias = categoryAlias, threadId = threadDto.Id }));
            }
            else
            {
                throw new HttpResponseException(HttpStatusCode.Forbidden, $"Access denied");
            }
        }