Пример #1
0
        public ActionResult CreateForumFromAnime(int animeId, [FromBody] CreateForumDTO forum)
        {
            _logger.LogInformation(MyLogEvents.InsertItem, "Adding anime Ratings");

            if (!_unitOfWork.Forums.AnimeExists(animeId))
            {
                _logger.LogInformation(MyLogEvents.GetItemNotFound, "anime does not exis");

                return(NotFound(new ResponseDTO <string> {
                    Code = ResponseCodes.NotFound, responseMessage = "anime does not exist", returnObject = null
                }));
            }

            var forumEntity = _mapper.Map <Forum>(forum);

            forumEntity.AnimeId = animeId;

            _unitOfWork.Forums.Add(forumEntity);

            _unitOfWork.Complete();

            var forumToReturn = _mapper.Map <ForumDTO>(forumEntity);

            return(CreatedAtRoute("GetForumForAnime", new { animeId }, new ResponseDTO <ForumDTO>()
            {
                Code = ResponseCodes.Success, responseMessage = "list of animes forums successfully returned", returnObject = forumToReturn
            }));
        }
Пример #2
0
        public async Task <IActionResult> CreateForum(CreateForumDTO createForumDTO)
        {
            var newForum = new Forum
            {
                Title       = createForumDTO.Title,
                Slug        = createForumDTO.Title.GenerateSlug(),
                Description = createForumDTO.Description ?? string.Empty
            };

            _Repo.Add(newForum);
            await _Repo.SaveChangesAsync();

            return(await GetForums());
        }