//private bool SaveClaim(IdentityClaim IdentityUserClaim) //{ // try // { // DbContext.Claims.Add(IdentityUserClaim); // DbContext.SaveChanges(); // return true; // } // catch (Exception) // { // return false; // } //} #endregion #region MongoDb private bool SaveClaim(IdentityClaim identityClaim) { try { if (identityClaim == null) return false; if (!IsUniqueClaim(identityClaim)) return false; var saveResult = DbContext.ClainsCollection.Save(identityClaim); return saveResult.Ok; } catch (Exception) { return false; } }
private bool IsUniqueClaim(IdentityClaim identityClaim) { var query = Query.And(Query.EQ("name", identityClaim.Name), Query.Not(Query.EQ("_id", identityClaim.Id))); var hasRegister = DbContext.ClainsCollection.FindOneAs<IdentityClaim>(query); return hasRegister == null; }
public ActionResult CreateClaim(IdentityClaim identityUserClaim) { try { var saveResult = false; if (ModelState.IsValid) saveResult = SaveClaim(identityUserClaim); if (!saveResult) return View(); return RedirectToAction("Index"); } catch { return View(); } }