public async Task <PublicationViewModel> CreateNew(Guid userId, PublicationCreateDto publication) { if (publication.ReplyPublicationId.HasValue && !await PublicationRepository.Exists(publication.ReplyPublicationId.Value)) { throw new DataNotFoundException($"Target publication {publication.ReplyPublicationId} does not exist."); } return(await PublicationRepository.CreateNew(userId, publication)); }
public async Task <IActionResult> CreateNew([FromBody] PublicationCreateDto dto) { try { var user = await HttpContext.GetUser(); var result = await PublicationService.CreateNew(user.Id, dto); return(Created($"/api/Publication/{result.Id}", result)); } catch (Exception ex) { Logger.LogWarning(ex, "An error occured: " + ex.Message ?? "undefined"); return(ExceptionHandlerService.Handle(ex, Request)); } }
public async Task<PublicationViewModel> CreateNew(Guid userId, PublicationCreateDto publication) { var result = await DbContext.Publications.AddAsync(new Publication { SubmissionType = publication.SubmissionType, TextContent = publication.TextContent, MediaId = publication.MediaId, ReplyPublicationId = publication.ReplyPublicationId, CreationDate = DateTime.UtcNow, UserId = userId }); await DbContext.SaveChangesAsync(); return PublicationViewModel.FromPublication(result.Entity); }