public virtual ServiceOperationResult Save(TEntity entity, bool validateChilds = false) { var result = EngineContext.Current.Resolve <ServiceOperationResult>(); if (entity == null) { result.AddResourceError(CommonConstants.Messages.NullEntity); return(result); } if (entity.Id != default(long) && GetById(entity.Id) == null) { result.AddResourceError(CommonConstants.Messages.UnknownEntity); return(result); } if (!_validationProvider.Validate(entity, result)) { return(result); } try { _session.SaveOrUpdate(entity); } catch (Exception exception) { return(result); } return(result); }
public ServiceOperationResult Save(TSettings settings) { var result = EngineContext.Current.Resolve <ServiceOperationResult>(); if (settings == null) { result.AddResourceError(CommonConstants.Messages.NullEntity); return(result); } if (!_validationProvider.Validate(settings, result)) { return(result); } try { var properties = from pi in typeof(TSettings).GetProperties() where pi.CanWrite && pi.CanRead where CommonHelper.GetCustomTypeConverter(pi.PropertyType).CanConvertFrom(typeof(string)) select pi; foreach (var property in properties) { var key = string.Concat(typeof(TSettings).Name, ".", property.Name); var value = property.GetValue(settings, null) ?? ""; result.CopyFrom(_settingService.Save(key, value)); } } catch { return(result); } _cachedSettings = settings; return(result); }