public IHttpActionResult SetPictureAs(EntitySetImageModel model) { var uploadType = model.UploadType; var pictureId = model.PictureId; /*Due to caching, generic attributes don't update the data somehow from apicontrollers*/ //TODO: Find a workaround to this issue //for now we have created an extension method to bypass cache for retrieve. eventually this works for now string key = ""; switch (uploadType) { case "cover": key = AdditionalCustomerAttributeNames.CoverImageId; break; case "avatar": key = SystemCustomerAttributeNames.AvatarPictureId; break; } //get the attribute with our extension method var attribute = _genericAttributeService.GetAttributeByKey(_workContext.CurrentCustomer, key); if (attribute == null) { _genericAttributeService.SaveAttribute(_workContext.CurrentCustomer, key, pictureId); } else { attribute.Value = pictureId.ToString(); _genericAttributeService.UpdateAttribute(attribute); } return(Json(new { Success = true })); }
private void UpdateProductGenericAttributes(Product entityToUpdate, List <ProductGenericAttributeDto> dtoGenericAttributes) { if (dtoGenericAttributes == null) { return; } var attributes = new List <GenericAttribute>(); // IF LIST IS EMPTY DELETE ALL GENERIC ATTRIBUTES! if (dtoGenericAttributes.Count == 0) { attributes = _genericAttributeService.GetAttributesForEntity(entityToUpdate.Id, "Product").ToList(); attributes = attributes.Where(a => a.Key != "nop.product.admindid" && a.Key != "nop.product.attributevalue.recordid" && a.Key != "nop.product.attribute.combination.records" && a.Key != "nop.product.attribute.combination.admind_id").ToList(); _genericAttributeService.DeleteAttributes(attributes); } var attribute = new GenericAttribute(); foreach (var ga in dtoGenericAttributes) { var key = string.Format("nop.product.{0}", ga.Name); attribute = attributes.Where(a => a.Key == key).FirstOrDefault(); if (attribute == null) { _genericAttributeService.SaveAttribute <string>(entityToUpdate, key, ga.Value); } else { attribute.Value = ga.Value; _genericAttributeService.UpdateAttribute(attribute); } } }
public void Should_Update_CreatedOrUpdatedDateUTC_In_UpdateAttribute() { var attribute = new Core.Domain.Common.GenericAttribute { Key = "test", CreatedOrUpdatedDateUTC = DateTime.UtcNow.AddDays(-30) }; _genericAttributeService.UpdateAttribute(attribute); Assert.That(attribute.CreatedOrUpdatedDateUTC, Is.EqualTo(DateTime.UtcNow).Within(1).Minutes); }
public ActionResult GenericAttributeUpdate(GenericAttributeModel model, GridCommand command) { model.Key = model.Key.TrimSafe(); model.Value = model.Value.TrimSafe(); if (ModelState.IsValid) { var storeId = _services.StoreContext.CurrentStore.Id; var infos = GetGenericAttributesInfos(model.EntityName); if (infos.UpdatePermission.HasValue() && !Services.Permissions.Authorize(infos.UpdatePermission)) { NotifyError(Services.Permissions.GetUnauthorizedMessage(infos.UpdatePermission)); } else { var attr = _genericAttributeService.GetAttributeById(model.Id); // If the key changed, ensure it isn't being used by another attribute. if (!attr.Key.IsCaseInsensitiveEqual(model.Key)) { var attr2 = _genericAttributeService.GetAttributesForEntity(model.EntityId, model.EntityName) .Where(x => x.StoreId == storeId && x.Key.Equals(model.Key, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); if (attr2 != null && attr2.Id != attr.Id) { NotifyWarning(T("Admin.Common.GenericAttributes.NameAlreadyExists", model.Key)); return(GenericAttributesSelect(model.EntityName, model.EntityId, command)); } } attr.Key = model.Key; attr.Value = model.Value; _genericAttributeService.UpdateAttribute(attr); } } else { var modelStateErrorMessages = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage); NotifyError(modelStateErrorMessages.FirstOrDefault()); } return(GenericAttributesSelect(model.EntityName, model.EntityId, command)); }
public void ShouldUpdateCreatedOrUpdatedDateUtcInUpdateAttribute() { var attribute = new Core.Domain.Common.GenericAttribute { Key = "test", KeyGroup = "test", Value = "test" }; _genericAttributeService.InsertAttribute(attribute); attribute.CreatedOrUpdatedDateUTC = DateTime.UtcNow.AddDays(-30); _genericAttributeService.UpdateAttribute(attribute); var createdOrUpdatedDate = attribute.CreatedOrUpdatedDateUTC; _genericAttributeService.DeleteAttribute(attribute); Assert.That(createdOrUpdatedDate, Is.EqualTo(DateTime.UtcNow).Within(1).Minutes); }
public void EnableOrDisableUser(int customerId, bool enable) { if (customerId != 0) { var cacheData = WebApiCachingUserData.Data(); var apiUser = cacheData.FirstOrDefault(x => x.CustomerId == customerId); if (apiUser != null) { apiUser.Enabled = enable; var attribute = _genericAttributeService.GetAttributeById(apiUser.GenericAttributeId); if (attribute != null) { attribute.Value = apiUser.ToString(); _genericAttributeService.UpdateAttribute(attribute); } } } }
public ActionResult GenericAttributeUpdate(GenericAttributeModel model, GridCommand command) { if (!_permissionService.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 = _storeContext.CurrentStore.Id; var attr = _genericAttributeService.GetAttributeById(model.Id); // if the key changed, ensure it isn't being used by another attribute if (!attr.Key.IsCaseInsensitiveEqual(model.Key)) { var attr2 = _genericAttributeService.GetAttributesForEntity(model.EntityId, model.EntityName) .Where(x => x.StoreId == storeId && x.Key.Equals(model.Key, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); if (attr2 != null && attr2.Id != attr.Id) { return(Content(string.Format(_localizationService.GetResource("Admin.Common.GenericAttributes.NameAlreadyExists"), model.Key))); } } attr.Key = model.Key; attr.Value = model.Value; _genericAttributeService.UpdateAttribute(attr); return(GenericAttributesSelect(model.EntityName, model.EntityId, command)); }
/// <summary> /// Updates the attribute /// </summary> /// <param name="attribute">Attribute</param> public void UpdateAttribute(GenericAttribute attribute) { _genericAttributeService.UpdateAttribute(attribute); }