示例#1
0
        public async Task <IActionResult> PutCoinsInMachine([FromRoute] int id, [FromBody] CoinsInMachine coinsInMachine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            _context.Entry(coinsInMachine).State      = EntityState.Modified;
            _context.Entry(coinsInMachine.Coin).State = EntityState.Modified;

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

            return(NoContent());
        }
示例#2
0
        public async Task <IActionResult> PostCoinsInMachine([FromBody] CoinsInMachine coinsInMachine)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CoinsInMachine.Add(coinsInMachine);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCoinsInMachine", new { id = coinsInMachine.Id }, coinsInMachine));
        }