public async Task <IActionResult> UpdateArticleContent(long id, [FromBody] ContentArticleCreate request) { var article_content = await _context.Contents .FirstOrDefaultAsync(c => c.Id == id); if (article_content == null) { return(NotFound("Article Content wasn't found")); } article_content.title = request.title; article_content.subtitle = request.subtitle; article_content.coverImage = request.coverImage; article_content.categoryID = request.categoryID; article_content.article = request.article; article_content.created = request.created; //demo_content.DemonstrationContentID = request.DemonstrationContentID; _context.Contents.Update(article_content); await _context.SaveChangesAsync(); return(Ok(await _context.Contents.ProjectTo <ArticleContentResponse>(_mapper.ConfigurationProvider) .FirstOrDefaultAsync(x => x.Id == article_content.Id))); }
public async Task <IActionResult> CreateContentArticle([FromBody] ContentArticleCreate request) { var res = await _context.Contents.AddAsync(_mapper.Map <Content>(request)); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(CreateContentArticle), await _context.Contents.ProjectTo <ContentGetAllResponse>(_mapper.ConfigurationProvider) .FirstOrDefaultAsync(x => x.Id == res.Entity.Id))); }
public async Task <ActionResult> CreateArticleContent([FromBody] ContentArticleCreate request) { try { var res = await _context.Contents.AddAsync(_mapper.Map <Content>(request)); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(CreateArticleContent), await _context.Contents.ProjectTo <ArticleContentResponse>(_mapper.ConfigurationProvider) .FirstOrDefaultAsync(x => x.Id == res.Entity.Id))); }catch (Exception exception) { return(BadRequest($"Error: {exception.Message}")); } }