c# - Get method specifically to handle a 0 value -


in web api controller method have.

public ihttpactionresult getmember(int id)     {         member member = db.members.find(id);         if (member == null)         {             return notfound();         }           return ok(member);     } 

basically checking here if there no current member id = 0, returning notfound ... , ui receiving.

the scenario 0 value api should provide new item defaults.any examples on how achieve this?

i came not able work right.

public ihttpactionresult getmember(int id)     {         member member = db.members.find(id);         if (id > 0)         {             var members = db.members.find();             member = members.firstordefault((m) => m.memberid == id);             //return notfound();              if (member == null)             {                 return notfound();             }             else             {                db.members.add(member);                 db.savechanges();              }             return ok(member);         }     } 

i not sure if understand goal, might if understand correctly:

public ihttpactionresult getmember(int id) {     member member = db.members.find(id);     if (member == null)     {         if (id != 0)         {             member = new member();         }         else         {             return notfound();         }     }     return ok(member); } 

is want?


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -