示例#1
0
        /*
         * The response is 204 (No Content). According to the HTTP specification,
         * a PUT request requires the client to send the entire updated entity, not just the changes.
         */
        public async Task <IActionResult> PutRobot(int id, Robot robot)
        {
            if (id != robot.IdRobot)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#2
0
        public async Task <T> AddAsync(T entity)
        {
            _context.Set <T>().Add(entity);
            await _context.SaveChangesAsync();

            return(entity);
        }
示例#3
0
        public async Task <ActionResult <RobotModel> > PostRobotModel()
        {
            RobotModel robot = CreateDefaultRobot();

            _context.Robots.Add(robot);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("PostRobotModel", new { id = robot.Id }, robot));
        }