コード例 #1
0
        // PUT: /Knowledges/5
        /// <summary>
        /// Support for updating Knowledges
        /// </summary>
        public async Task <IActionResult> Put([FromODataUri] int key, [FromBody] Knowledge update)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (key != update.Id)
            {
                return(BadRequest());
            }

            _context.Entry(update).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Knowledge.Any(p => p.Id == key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(update));
        }
コード例 #2
0
        public async Task <IActionResult> Put([FromODataUri] string userid, [FromBody] Quizuser update)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (String.CompareOrdinal(userid, update.Userid) != 0)
            {
                return(BadRequest());
            }

            _context.Entry(update).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.Quizuser.Any(p => String.CompareOrdinal(p.Userid, userid) == 0))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(update));
        }