Esempio n. 1
0
        public async Task <IActionResult> ReplyForumPoste(ForumPostForReplyDto dto)
        {
            // Trouver l'utilisateur actuel
            var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            // Préparation du model
            var item = new ForumPost
            {
                ForumTopicId = dto.ForumTopicId,
                UserId       = userId,
                Date         = DateTime.Now,
                Content      = dto.Content
            };

            _repo.Add(item);

            if (!await _repo.SaveAll())
            {
                return(BadRequest("Impossible de répondre à ce poste"));
            }

            var itemTopic = await _repo.GetForumTopic(dto.ForumTopicId);

            itemTopic.Date = item.Date;
            _repo.Update(itemTopic);

            if (!await _repo.SaveAll())
            {
                return(BadRequest("Impossible de modifier la date du sujet"));
            }

            return(Ok());
        }
        public async Task <IActionResult> NewForumTopicAndForumPost(ForumPostForNewForumTopicDto dto)
        {
            // Test if ForumTopic.Name is unique
            if (await _repo.ForumTopicExist(dto.NameTopic))
            {
                return(BadRequest($"Impossible de créer le sujet, le même nom de sujet « {dto.NameTopic} » existe déjà"));
            }

            // Prepare ForumTopic
            var itemForumTopic = new ForumTopic
            {
                Date             = DateTime.Now,
                ForumCategorieId = dto.ForumCategorieId,
                Name             = dto.NameTopic,
                View             = 0
            };

            _repo.Add(itemForumTopic);

            if (!await _repo.SaveAll())
            {
                return(BadRequest("Impossible de créer le sujet"));
            }

            // Find current user
            var userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            // Prepare ForumPost
            var item = new ForumPost
            {
                ForumTopicId = itemForumTopic.Id,
                UserId       = userId,
                Date         = DateTime.Now,
                Content      = dto.Content
            };

            _repo.Add(item);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Impossible de créer le sujet"));
        }
Esempio n. 3
0
        public void Add(Forum item)
        {
            item.UrlName         = UrlHelpers.ConvertToUrl(item.Title);
            item.CreatedDateTime = DateTime.UtcNow;
            item.CreatedBy       = 1;
            var entity = _mapper.Map <Domain.Forums.ForumEntity>(item);

            _forumRepository.Add(entity);
        }
Esempio n. 4
0
        public int AddGenre(AddGenreModel addTheme)
        {
            Genre genre = new Genre()
            {
                Name = addTheme.Name
            };

            _repository.Add(genre);

            return(genre.Id);
        }
Esempio n. 5
0
        public int AddGame(AddGameModel addGame)
        {
            SomeGame game = new SomeGame()
            {
                Name    = addGame.Name,
                GenreId = addGame.GenreId
            };

            _repository.Add(game);

            return(game.Id);
        }
Esempio n. 6
0
 public ActionResult Add(Forum forum)
 {
     try
     {
         _forumRepository.Add(forum);
         _forumRepository.SaveChanges();
         return(new AcceptedResult());
     } catch (Exception)
     {
         return(BadRequest());
     }
 }
Esempio n. 7
0
        public int Register(UserRegisterModel user)
        {
            User Adduser = new User()
            {
                Login    = user.Login,
                Password = user.Password
            };

            _repository.Add(Adduser);

            return(Adduser.Id);
        }
Esempio n. 8
0
        public async Task <IActionResult> Create(Forum forum)
        {
            try
            {
                await _repository.Add(forum);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Esempio n. 9
0
        public bool CreateForum(Forum forum)
        {
            bool flag = false;

            try
            {
                _forumRepository.Add(forum);
                _unitOfWork.Commit();
                flag = true;
            }
            catch { }

            return(flag);
        }