Пример #1
0
 public HttpResponseMessage PostAuth(Auth au)
 {
     if (ModelState.IsValid)
     {
         var result = QueryableDependencies.UpdateAuth(au);
         return Request.CreateResponse(HttpStatusCode.OK, result);
     }
     else
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
 }
Пример #2
0
 public static string UpdateAuth(Auth au)
 {
     var collection = BadgeApiDB.GetCollection<Auth>("Auth");
     var query = Query.EQ("UserName", au.UserName);
     var result = collection.FindOne(query);
     if (result != null)
     {
         var update = Update<Auth>.Set(e => e.Password, au.Password);
         update.Set(e => e.Roles , au.Roles);
         collection.Update(query, update);
         return result.ToJson();
     }
     else
     {
         var newauth = BadgeApiDB.GetCollection("Auth");
         newauth.Insert(au);
         return au.ToJson();
     }
 }