Ejemplo n.º 1
0
        public async Task <IActionResult> PostWorkout([FromBody] Workout workout)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (workout.TimeInSeconds >= 5400)
            {
                throw new Exception("Sorry !!! We do't facilitate our users to jogg more than an hour. For WorkOut ID: " + workout.Id);
            }
            _context.Workout.Add(workout);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetWorkout", new { id = workout.Id }, workout));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> addNewHardware([FromBody] AddHardware hardware)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _workoutDataContext.Hardwares.Add(hardware);
            await _workoutDataContext.SaveChangesAsync();

            return(CreatedAtAction("getHardware", new { hardwareID = hardware.HardwareID }, hardware));
        }