示例#1
0
        public async Task <IActionResult> PutWorkout(int id, Workout workout)
        {
            if (id != workout.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        //TODO: Re-evaluate. I don't think this method is needed.

        /*
         * public virtual void Save()
         * {
         *  try
         *  {
         *      _context.SaveChanges();
         *  }
         *  catch (Exception ex)
         *  {
         *      //TODO: Log
         *      //TODO: Handle different exception types
         *      throw;
         *  }
         * }
         *
         * //TODO: Re-evaluate. I don't think this method is needed.
         * public virtual Task SaveAsync()
         * {
         *  try
         *  {
         *      return _context.SaveChangesAsync();
         *  }
         *  catch (Exception ex)
         *  {
         *      //TODO: Log
         *      //TODO: Handle different exception types
         *      throw;
         *  }
         * }
         */

        public void SetValues(TEntity target, TEntity source)
        {
            _context.Entry <TEntity>(target).CurrentValues.SetValues(source);
        }