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)); }
public async Task <IActionResult> PutLongTermGoal([FromRoute] int id, [FromBody] LongTermGoalDTO dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dto.Id) { return(BadRequest()); } var ltg = await _context.LongTermGoals.SingleOrDefaultAsync(x => x.Id == dto.Id); ltg = LongTermGoalDTO.UpdateDbObjectWithDTO(ltg, dto); _context.Entry(ltg).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LongTermGoalExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IEnumerable <LongTermGoalDTO> GetMostRecent() { var ltgs = _context.LongTermGoals.Where(x => !x.Archived).OrderByDescending(x => x.LastModified).Take(10); return(LongTermGoalDTO.DbSetToDtoList(ltgs)); }
public IEnumerable <LongTermGoalDTO> GetManyByProjectId([FromRoute] int id) { var ltgs = _context.LongTermGoals.Where(x => x.ProjectId == id && !x.Archived); return(LongTermGoalDTO.DbSetToDtoList(ltgs)); }
public IEnumerable <LongTermGoalDTO> GetLongTermGoals() { var ltgs = _context.LongTermGoals; return(LongTermGoalDTO.DbSetToDtoList(ltgs)); }