public void Can_save_and_load_genericAttribute() { var genericAttribute = new GenericAttribute { EntityId = 1, KeyGroup = "KeyGroup 1", Key = "Key 1", Value = "Value 1", StoreId = 2 }; var fromDb = SaveAndLoadEntity(genericAttribute); fromDb.ShouldNotBeNull(); fromDb.EntityId.ShouldEqual(1); fromDb.KeyGroup.ShouldEqual("KeyGroup 1"); fromDb.Key.ShouldEqual("Key 1"); fromDb.Value.ShouldEqual("Value 1"); fromDb.StoreId.ShouldEqual(2); }
public bool CreateKeys(int customerId) { if (customerId != 0) { var hmac = new HmacAuthentication(); var userData = WebApiCaching.UserData(); string key1, key2; for (int i = 0; i < 9999; ++i) { if (hmac.CreateKeys(out key1, out key2) && !userData.Exists(x => x.PublicKey.IsCaseInsensitiveEqual(key1))) { var apiUser = new WebApiUserCacheData() { CustomerId = customerId, PublicKey = key1, SecretKey = key2, Enabled = true }; RemoveKeys(customerId); var attribute = new GenericAttribute() { EntityId = customerId, KeyGroup = "Customer", Key = WebApiUserCacheData.Key, Value = apiUser.ToString() }; _genericAttributeService.InsertAttribute(attribute); WebApiCaching.Remove(WebApiUserCacheData.Key); return true; } } } return false; }
public ActionResult GenericAttributeAdd(GenericAttributeModel model, GridCommand command) { if (!_services.Permissions.Authorize(StandardPermissionProvider.AccessAdminPanel)) return AccessDeniedView(); model.Key = model.Key.TrimSafe(); model.Value = model.Value.TrimSafe(); if (!ModelState.IsValid) { // display the first model error var modelStateErrorMessages = this.ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); return Content(modelStateErrorMessages.FirstOrDefault()); } var storeId = _services.StoreContext.CurrentStore.Id; var attr = _genericAttributeService.GetAttribute<string>(model.EntityName, model.EntityId, model.Key, storeId); if (attr == null) { var ga = new GenericAttribute { StoreId = storeId, KeyGroup = model.EntityName, EntityId = model.EntityId, Key = model.Key, Value = model.Value }; _genericAttributeService.InsertAttribute(ga); } else { return Content(string.Format(_localizationService.GetResource("Admin.Common.GenericAttributes.NameAlreadyExists"), model.Key)); } return GenericAttributesSelect(model.EntityName, model.EntityId, command); }