Exemple #1
0
        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)));
        }
Exemple #2
0
        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());
        }