asp.net core mvc - Visual Studio Scaffolded controller actions -


when using "add scaffold" create new "api controller actions, using entity framework" on asp .net core 1.1 web api, generates following:

    // get: api/users     [httpget]     public ienumerable<user> getusers()     {         try         {             return _context.users;         }          catch (exception ex)         {             _logger.logerror(loggingevents.general_exception, ex, ex.message);         }     }      // get: api/users/5     [httpget("{id}")]     public async task<iactionresult> getuser([fromroute] int? id)     {         if (!modelstate.isvalid)         {             return badrequest(modelstate);         }          var user = await _context.users.singleordefaultasync(m => m.userid == id);          if (user == null)         {             return notfound();         }          return ok(user);     }      // put: api/users/5     [httpput("{id}")]     public async task<iactionresult> putuser([fromroute] int? id, [frombody] user user)     {         if (!modelstate.isvalid)         {             return badrequest(modelstate);         }          if (id != user.userid)         {             return badrequest();         }          _context.entry(user).state = entitystate.modified;          try         {             await _context.savechangesasync();         }         catch (dbupdateconcurrencyexception)         {             if (!userexists(id))             {                 return notfound();             }             else             {                 throw;             }         }          return nocontent();     }      // post: api/users     [httppost]     public async task<iactionresult> postuser([frombody] user user)     {         if (!modelstate.isvalid)         {             return badrequest(modelstate);         }          _context.users.add(user);         await _context.savechangesasync();          return createdataction("getuser", new { id = user.userid }, user);     }      // delete: api/users/5     [httpdelete("{id}")]     public async task<iactionresult> deleteuser([fromroute] int? id)     {         if (!modelstate.isvalid)         {             return badrequest(modelstate);         }          var user = await _context.users.singleordefaultasync(m => m.userid == id);         if (user == null)         {             return notfound();         }          _context.users.remove(user);         await _context.savechangesasync();          return ok(user);     }      private bool userexists(int? id)     {         return _context.users.any(e => e.userid == id);     } 

the first thing popped me when looked @ code visual studio generated, methods return task, , async, exception of first one: public ienumerable getusers()

is there reason this? mean, if there error? should able return 500 internal server error, instead of null? , why isn't running asynchronously?

thanks


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -