コード例 #1
0
        public async Task <IActionResult> PutWorkOut([FromRoute] int id, [FromBody] WorkOut workOut)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != workOut.Id)
            {
                return(BadRequest());
            }

            _context.Entry(workOut).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkOutExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> Patch([FromODataUri] int id, [FromBody] WorkOut workOut)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != workOut.Id)
            {
                return(BadRequest());
            }

            var check = _context.WorkOutList.Where(item => item.Id == workOut.Id).First();

            if (!check.Complete && workOut.Complete)
            {
                check.MarkComplete();
            }

            check.Description = workOut.Description;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkOutExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }