public QpPlugin Update(QpPlugin plugin) { if (plugin.OldContract != plugin.Contract) { QpPluginRepository.CreateVersion(plugin); } return(QpPluginRepository.UpdateProperties(plugin)); }
public QpPlugin Read(int id) { var plugin = QpPluginRepository.GetById(id); if (plugin == null) { throw new ApplicationException(string.Format(QpPluginStrings.PluginNotFound, id)); } return(plugin); }
public ListResult <QpPluginListItem> List(ListCommand cmd, int parentId) { var list = QpPluginRepository.List(cmd, out var totalRecords); return(new ListResult <QpPluginListItem> { Data = list.ToList(), TotalRecords = totalRecords }); }
public static List <QpPluginFieldValue> GetPluginValues(int fieldId) { var actualValues = QPContext.EFContext.PluginFieldValueSet .Where(n => n.ContentAttributeId == fieldId) .ToDictionary(k => (int)k.PluginFieldId, n => n.Value); var pluginDict = QpPluginRepository.GetQpFieldPluginDict(); var pluginFieldValues = QpPluginRepository.GetPluginFields(QpPluginRelationType.ContentAttribute) .Select(n => new QpPluginFieldValue() { Field = n, Plugin = pluginDict[n.Id], Value = actualValues.TryGetValue(n.Id, out var result) ? result : String.Empty }).ToList();
public static QpPluginVersion GetMergedVersion(int[] ids, int parentId) { if (ids == null) { throw new ArgumentNullException(nameof(ids)); } if (ids.Length != 2) { throw new ArgumentException("Wrong ids length"); } var parent = QpPluginRepository.GetById(parentId); if (parent == null) { throw new Exception(string.Format(QpPluginStrings.PluginNotFound, parentId)); } var(item1, item2) = GetOrderedIds(ids); QpPluginVersion version1, version2; version1 = QpPluginVersionRepository.GetById(item1, parentId); if (version1 == null) { throw new Exception(string.Format(QpPluginStrings.PluginVersionNotFound, item1, parentId)); } if (item2 == QpPluginVersion.CurrentVersionId) { version2 = CreateVersionFromPlugin(parent); version2.Id = QpPluginVersion.CurrentVersionId; } else { version2 = QpPluginVersionRepository.GetById(item2, parentId); if (version2 == null) { throw new Exception(string.Format(QpPluginStrings.PluginVersionNotFound, item2, parentId)); } } version1.MergeToVersion(version2); return(version1); }
internal static QpPlugin Create() => new QpPlugin { Order = QpPluginRepository.GetPluginMaxOrder() + 1 };
public override void Validate() { var errors = new RulesException <QpPlugin>(); base.Validate(errors); if (!string.IsNullOrEmpty(LoadedContractInvalidMessage)) { errors.ErrorFor(n => ServiceUrl, $"{QpPluginStrings.LoadedContractInvalidMessage}: {LoadedContractInvalidMessage}"); } if (!string.IsNullOrEmpty(ParsedContractInvalidMessage)) { errors.ErrorFor(n => Contract, $"{QpPluginStrings.ParsedContractInvalidMessage}: {ParsedContractInvalidMessage}"); } if (!string.IsNullOrEmpty(ServiceUrl) && !UrlHelpers.IsValidWebFolderUrl(ServiceUrl)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.ServiceUrlInvalidFormat); } if (ContractParsed) { if (string.IsNullOrEmpty(Contract)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.ContractNotEntered); } else { if (string.IsNullOrEmpty(Code)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.CodeNotEntered); } else { if (QpPluginRepository.CodeExists(this)) { errors.ErrorFor(n => Code, QpPluginStrings.CodeExists); } } if (string.IsNullOrEmpty(Version)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.VersionNotEntered); } else { if (Version.Length > MaxVersionLength) { errors.ErrorFor(n => Version, String.Format(QpPluginStrings.VersionMaxLengthExceeded, null, MaxVersionLength)); } else if (OldVersion == Version) { errors.ErrorFor(n => Version, QpPluginStrings.VersionEqual); } } if (Fields.Any(n => String.IsNullOrEmpty(n.Name))) { errors.ErrorForModel(QpPluginStrings.FieldNameNotEntered); } if (Fields.Any(n => n.Name.Length > MaxFieldNameLength)) { errors.ErrorForModel(String.Format(QpPluginStrings.FieldNameMaxLengthExceeded, null, MaxFieldNameLength)); } if (Fields.GroupBy(n => n.Name.ToLower() + n.RelationType).Any(g => g.Count() > 1)) { errors.ErrorForModel(QpPluginStrings.FieldNameDuplicate); } } } if (!errors.IsEmpty) { throw errors; } }
public QpPlugin Save(QpPlugin plugin) => QpPluginRepository.SaveProperties(plugin);
public MessageResult Remove(int id) { Read(id); QpPluginRepository.Delete(id); return(null); }