public async Task <IActionResult> Create(Guid id, TopicForUpdate topicforUpdate) { var entity = await repository.Get(id); entity = new Topic { Title = topicforUpdate.Title, Description = topicforUpdate.Description, }; await repository.Save(); return(Ok()); }
public async Task <bool> UpdateTopicAsync(int id, TopicForUpdate topicForUpdate) { var topic = await GetTopicByIdAsync(id); if (topic == null) { return(false); } try { topic.Name = topicForUpdate.Name; await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { return(false); } }
public async Task <IActionResult> UpdateTopic(int id, [FromBody] TopicForUpdate input) { if (ModelState.IsValid) { var result = await _topicRepository.UpdateTopicAsync(id, input); if (result) { return(Ok(new { message = "success", StatusCode = 200 })); } return(BadRequest(new { message = "fail" })); } return(BadRequest(ModelState)); }