private void Set(string key, string value) { try { Option option = _db.Options.Where(o => o.Id == key).FirstOrDefault(); if (option == null) { option = new Option() { Id = key, Value = value }; _db.Options.Add(option); } else { option.Value = value; } _db.SaveChanges(); _cache.Remove(key); } catch (DbUpdateException ex) { if (ex.InnerException is SqlException innerException && innerException.Number == 2627) { throw new Exception("There is already an option with that key in the database.", ex); }
public virtual async Task UpdateProfileAsync(UserProfile user) { ApplicationUser userToUpdate = await _db.Users.FirstOrDefaultAsync(u => u.Id == user.Id); foreach (PropertyInfo property in typeof(IUserProfile).GetProperties()) { property.SetValue(userToUpdate, property.GetValue(user)); } foreach (PropertyInfo property in typeof(IName).GetProperties()) { property.SetValue(userToUpdate, property.GetValue(user)); } foreach (PropertyInfo property in typeof(IJsonMetadata).GetProperties()) { property.SetValue(userToUpdate, property.GetValue(user)); } _db.Update(userToUpdate); _db.SaveChanges(); }