public async Task <IActionResult> AddArticle( [FromQuery(Name = "type")] string typeStr, [FromQuery(Name = "title")] string title, [FromQuery(Name = "note")] string note, [FromQuery(Name = "publicationId")] int publicationId ) { if (!Enum.TryParse <ArticleType> (typeStr, true, out var type)) { type = ArticleType.UNKNOWN; } if (typeStr == null || title == null || publicationId == 0 || type == ArticleType.UNKNOWN) { return(new CustomErrorResource( HttpStatusCode.BadRequest, "One or more mandatory fields are missing or invalid")); } var item = new Article(0, type, title, note, publicationId, DateTime.Now); _context.AddAuditCustomField("AuditProcessAction", ProcessAction.AddedDirectly.ToString()); await _context.Articles.AddAsync(item); await _context.Publications.FindAsync(item.PublicationId); await _context.SaveChangesAsync(); var result = await _context.Articles.FindAsync(item.Id); return(new CreatedResult($"article/{result.Id}", result)); }