public async Task <IActionResult> PostLongTermGoal([FromBody] LongTermGoalDTO dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var ltg = LongTermGoalDTO.UpdateDbObjectWithDTO(new LongTermGoal(), dto); ltg.Columns = new List <Column>(); ltg.Columns.Add(new Column { Name = "Todo" }); ltg.Columns.Add(new Column { Name = "Doing" }); ltg.Columns.Add(new Column { Name = "Done" }); _context.LongTermGoals.Add(ltg); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLongTermGoal", new { id = ltg.Id }, LongTermGoalDTO.DbObjectToDto(ltg))); }
public async Task <IActionResult> GetLongTermGoal([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var longTermGoal = await _context.LongTermGoals.SingleOrDefaultAsync(m => m.Id == id); if (longTermGoal == null) { return(NotFound()); } var result = LongTermGoalDTO.DbObjectToDto(longTermGoal); return(Ok(result)); }