public AdminModel Update(string login, AdminModel user) { var userFromBd = GetAdmin(login); var type = userFromBd.GetType(); foreach (var propertyInfo in type.GetProperties()) { var newUserProperty = propertyInfo.GetValue(user); if (newUserProperty != null) { propertyInfo.SetValue(userFromBd, newUserProperty); } } var filter = Builders <AdminModel> .Filter.Eq(u => u.Login, login); Admins.ReplaceOne(filter, userFromBd); return(userFromBd); }
public string Save(AdminModel admin) { Admins.InsertOne(admin); return(admin.Id); }