public async Task <IActionResult> Create(TopicCreateDto model, string forumId) { if (!ModelState.IsValid) { return(View(model)); } var authorId = User.Claims.FirstOrDefault(c => c.Type == "Id").Value; var topic = new Topic { Id = Guid.NewGuid().ToString("N"), Title = model.Title, Description = model.Description, AuthorId = authorId, ForumId = forumId }; try { await topicRepository.CreateAsync(topic); return(RedirectToAction("Show", "Forum", new { id = forumId })); } catch (Exception e) { ViewBag.Error = e.Message; return(View(model)); } }
public async Task <CreateTopicOperationResponse> Execute(CreateTopicOperationRequest request) { var topic = new Domain.Entity.LearningCalendar.Topic { ParentTopicId = request.ParentTopic, Subject = request.Subject, Description = request.Description, }; try { await _topicRepository.CreateAsync(topic); } catch (DbUpdateException) { throw new TopicAlreadyExistsException(request.Subject); } return(new CreateTopicOperationResponse { Id = topic.Id }); }