示例#1
0
        public async Task <IActionResult> PutKey(string id, Key key)
        {
            if (id != key.key)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#2
0
        public async Task <Key> GetAvailableKeyAsync(int skipRowsCount)
        {
            var key = await _context.Keys.Where(key => key.State == KeyState.New).OrderBy(key => key.Id).Skip(skipRowsCount).FirstOrDefaultAsync();

            key.State = KeyState.Reserved;

            _context.Keys.Update(key);
            await _context.SaveChangesAsync();

            return(key);
        }