private UpdatePropertyResultViewModel propertySaveResult(TEntity entity, EditPropertyResult valueToDisplay) { var notification = _validator.Validate(entity); var response = new UpdatePropertyResultViewModel(notification, valueToDisplay.NewValue); if (notification.IsValid()) { _repository.Save(entity); } else { response.AddErrors(notification.ToValidationErrors()); response.Success = false; _repository.RejectChanges(entity); } return(response); }
public virtual EditPropertyResult EditProperty(UpdatePropertyModel <T> update, T entity) { var accessor = getAccessor(update); var oldValue = accessor.GetValue(entity); var newValueString = update.PropertyValue ?? string.Empty; object newValue = null; var targetType = accessor.PropertyType; try { newValue = _converter.FromString(newValueString, targetType); if (!PropertyUtility.IsChanged(targetType, newValue, oldValue)) { return(EditPropertyResult.NotChangedResult()); } } catch (Exception ex) { throw InvalidPropertyConversionException .For(FastPackKeys.INVALID_TYPE_CONVERSION.ToFormat(newValueString, LocalizationManager.GetTextForType( targetType.Name.ToUpper())), ex); } accessor.SetValue(entity, newValue); var prevValue = oldValue == null ? string.Empty : oldValue.ToString(); var result = new EditPropertyResult(accessor, typeof(T), prevValue, newValueString); if (!result.IsListAccessor()) { //Used to be UpdatePropertyModel.formatter.GetDisplay. We had an unused _flattener variable. Why? result.PreviousValue = _formatter.GetDisplay(accessor, oldValue); result.NewValue = _formatter.GetDisplayForProperty(accessor, entity); } return(result); }
public void IsListAccessor_should_be_true_if_the_accessor_is_a_list_type() { var result = new EditPropertyResult(_accessor, typeof(Case)); result.IsListAccessor().ShouldBeTrue(); }
public void ListName_should_be_set_if_the_accessor_is_a_list_type() { var result = new EditPropertyResult(_accessor, typeof(Case)); result.ListName.ShouldEqual("CaseType"); }
public void Log(TEntity entity, EditPropertyResult result) { // Nothing }