public async Task<List<string>> Delete(int claimId) { List<string> errors = new List<string>(); int deletedCount = 0; try { using (DataLayer.EFDbContext.AuthorizationContext authContext = new DataLayer.EFDbContext.AuthorizationContext()) { DataLayer.Entities.User.Claims claim = await authContext.Claims.FindAsync(claimId); authContext.Claims.Remove(claim); deletedCount = await authContext.SaveChangesAsync(); if (deletedCount <= 0) { errors.Add("Error deleting Claim, ClaimID: " + claimId.ToString()); } } } catch (DbEntityValidationException ex) { errors.Add(ex.ToString()); } return errors; }
public async Task<List<string>> RevokeAllTokens(string userName) { List<string> errors = new List<string>(); if (string.IsNullOrEmpty(userName)) { errors.Add("No user specified."); return errors; } try { using (DataLayer.EFDbContext.AuthorizationContext authContext = new DataLayer.EFDbContext.AuthorizationContext()) { var tokens = authContext.AuthorizationTokens.Where(at => at.userName == userName); foreach (var token in tokens) { token.isActive = false; } await authContext.SaveChangesAsync(); } } catch (DbEntityValidationException ex) { errors.Add(ex.ToString()); } return errors; }
public async Task<ngk.DataLayer.Entities.User.Claims> Insert(DataLayer.Entities.User.Claims claim) { using (DataLayer.EFDbContext.AuthorizationContext authContext = new DataLayer.EFDbContext.AuthorizationContext()) { authContext.Claims.Add(claim); await authContext.SaveChangesAsync(); } if (claim.claimId != 0) { return claim; } return null; }
public async Task<List<string>> UpdateUser(string originalEmail, string updatedEmail, string firstName, string lastName) { List<string> errors = new List<string>(); try { using (DataLayer.EFDbContext.AuthorizationContext authContext = new DataLayer.EFDbContext.AuthorizationContext()) { var updateUser = authContext.Users.First(u => u.Email == originalEmail); updateUser.Email = updatedEmail; updateUser.UserName = updatedEmail; // for now, username is email address... updateUser.firstName = firstName; updateUser.lastName = lastName; await authContext.SaveChangesAsync(); } } catch (DbEntityValidationException ex) { errors.Add(ex.ToString()); } return errors; }