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")); }
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); }
public int AddGenre(AddGenreModel addTheme) { Genre genre = new Genre() { Name = addTheme.Name }; _repository.Add(genre); return(genre.Id); }
public int AddGame(AddGameModel addGame) { SomeGame game = new SomeGame() { Name = addGame.Name, GenreId = addGame.GenreId }; _repository.Add(game); return(game.Id); }
public ActionResult Add(Forum forum) { try { _forumRepository.Add(forum); _forumRepository.SaveChanges(); return(new AcceptedResult()); } catch (Exception) { return(BadRequest()); } }
public int Register(UserRegisterModel user) { User Adduser = new User() { Login = user.Login, Password = user.Password }; _repository.Add(Adduser); return(Adduser.Id); }
public async Task <IActionResult> Create(Forum forum) { try { await _repository.Add(forum); return(RedirectToAction(nameof(Index))); } catch { return(StatusCode(500)); } }
public bool CreateForum(Forum forum) { bool flag = false; try { _forumRepository.Add(forum); _unitOfWork.Commit(); flag = true; } catch { } return(flag); }