コード例 #1
0
        public async Task <IActionResult> PostRiskreport([FromBody] Riskreport riskreport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Riskreport.Add(riskreport);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (RiskreportExists(riskreport.YearActive))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetRiskreport", new { id = riskreport.YearActive }, riskreport));
        }
コード例 #2
0
        public async Task <IActionResult> PutRiskreport([FromRoute] int id, [FromBody] Riskreport riskreport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != riskreport.YearActive)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }