示例#1
0
 public IActionResult Post(User model)
 {
     if (ModelState.IsValid)
     {
         if (!_srv.CheckUserExists(model.Name))
         {
             User user = new User()
             {
                 Name     = model.Name,
                 Password = model.Password
             };
             if (_srv.PostUser(user))
             {
                 return(Ok());
             }
             return(BadRequest("Posting user failed!"));
         }
         return(BadRequest($"User with name \"{model.Name}\" already exists!"));
     }
     return(BadRequest("User model is invalid!"));
 }