本文整理汇总了C#中System.Entity.CreateRecord方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.CreateRecord方法的具体用法?C# Entity.CreateRecord怎么用?C# Entity.CreateRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.CreateRecord方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public string Create(
Entity entity,
FormCollection collection,
HttpFileCollectionBase files)
{
var entityRecord = entity.CreateRecord(collection, files, x => x.OnCreateDefaultValue);
if (_validator.Validate(entityRecord) == false)
{
_notificator.Error(IlaroAdminResources.RecordNotValid);
return null;
}
var existingRecord = _source.GetRecord(
entity,
entityRecord.Keys.Select(value => value.AsObject).ToArray());
if (existingRecord != null)
{
_notificator.Error(IlaroAdminResources.EntityAlreadyExist);
return null;
}
var propertiesWithUploadedFiles = _filesHandler.Upload(
entityRecord,
x => x.OnCreateDefaultValue);
var id = _creator.Create(
entityRecord,
() => _changeDescriber.CreateChanges(entityRecord));
if (id.IsNullOrWhiteSpace() == false)
_filesHandler.ProcessUploaded(propertiesWithUploadedFiles);
else
_filesHandler.DeleteUploaded(propertiesWithUploadedFiles);
return id;
}
示例2: GetEntityRecord
public EntityRecord GetEntityRecord(Entity entity, params string[] key)
{
var keys = new object[key.Length];
for (int i = 0; i < key.Length; i++)
{
keys[i] = new PropertyValue(entity.Keys[i]).ToObject(key[i]);
}
var item = GetRecord(entity, keys);
if (item == null)
{
_notificator.Error(IlaroAdminResources.EntityNotExist);
return null;
}
return entity.CreateRecord(item);
}
示例3: Delete
public bool Delete(Entity entity, string key, IEnumerable<PropertyDeleteOption> options)
{
var existingRecord = _source.GetRecord(entity, key);
if (existingRecord == null)
{
_notificator.Error(IlaroAdminResources.EntityNotExist);
return false;
}
var entityRecord = entity.CreateRecord(existingRecord);
options = options ?? new List<PropertyDeleteOption>();
var deleteOptions = options.ToDictionary(x => x.HierarchyName);
var result = _deleter.Delete(
entityRecord,
deleteOptions,
() => _changeDescriber.DeleteChanges(entityRecord, existingRecord));
if (result)
{
var propertiesWithFilesToDelete = entityRecord.Values
.Where(value => value.Property.TypeInfo.IsFile && value.Property.TypeInfo.IsFileStoredInDb == false);
_filesHandler.Delete(propertiesWithFilesToDelete);
}
return result;
}
示例4: Edit
public bool Edit(
Entity entity,
string key,
FormCollection collection,
HttpFileCollectionBase files,
object concurrencyCheckValue = null)
{
try
{
var existingRecord = _source.GetRecord(entity, key);
if (existingRecord == null)
{
_notificator.Error(IlaroAdminResources.EntityNotExist);
return false;
}
var entityRecord = entity.CreateRecord(key, collection, files, x => x.OnUpdateDefaultValue);
if (_validator.Validate(entityRecord) == false)
{
_notificator.Error(IlaroAdminResources.RecordNotValid);
return false;
}
var propertiesWithUploadedFiles = _filesHandler.Upload(
entityRecord,
x => x.OnUpdateDefaultValue);
_comparer.SkipNotChangedProperties(entityRecord, existingRecord);
var result = false;
try
{
result = _updater.Update(
entityRecord,
concurrencyCheckValue,
() => _changeDescriber.UpdateChanges(entityRecord, existingRecord));
}
catch (Exception ex)
{
_log.Error(ex.Message);
_notificator.Error(ex.Message);
}
if (result)
_filesHandler.ProcessUploaded(propertiesWithUploadedFiles, existingRecord);
else
_filesHandler.DeleteUploaded(propertiesWithUploadedFiles);
return result;
}
catch (Exception ex)
{
_log.Error(ex.Message);
_notificator.Error(ex.Message);
return false;
}
}
示例5: GetRecords
public PagedRecords GetRecords(
Entity entity,
IList<BaseFilter> filters = null,
string searchQuery = null,
string order = null,
string orderDirection = null,
bool determineDisplayValue = false,
int? page = null,
int? take = null,
bool loadForeignKeys = false)
{
var search = new EntitySearch
{
Query = searchQuery,
Properties = entity.SearchProperties
};
order = order.IsNullOrEmpty() ? entity.Keys.FirstOrDefault().Column : order;
orderDirection = orderDirection.IsNullOrEmpty() ?
"ASC" :
orderDirection.ToUpper();
var orderBy = order + " " + orderDirection;
var columns = string.Join(",",
entity.DisplayProperties
.Union(entity.Keys)
.Where(x =>
!x.IsForeignKey ||
(!x.TypeInfo.IsCollection && x.IsForeignKey))
.Select(x => $"{entity.Table}.{x.Column} as {x.Column}")
.Distinct());
List<object> args;
var where = ConvertFiltersToSql(filters, search, out args);
var table = new DynamicModel(
_admin.ConnectionStringName,
entity.Table,
entity.JoinedKeys);
if (page.HasValue && take.HasValue)
{
var result = table.Paged(
columns: columns,
where: where,
orderBy: orderBy,
currentPage: page.Value,
pageSize: take.Value,
args: args.ToArray());
var records = new List<EntityRecord>();
foreach (var item in result.Items)
{
records.Add(entity.CreateRecord((Dictionary<string, object>)item));
}
return new PagedRecords
{
TotalItems = result.TotalRecords,
TotalPages = result.TotalPages,
Records = records
};
}
else
{
var joins = "";
if (loadForeignKeys)
{
foreach (var foreignKey in entity.ForeignKeys.WhereOneToMany())
{
var joinTable = foreignKey.ForeignEntity.Table;
var joinProperty = foreignKey.ForeignEntity.Keys.FirstOrDefault(x => x.ForeignEntity == entity);
var keyProperty = foreignKey.TypeInfo.IsCollection ?
entity.Keys.FirstOrDefault() :
foreignKey;
joins += Environment.NewLine +
$"left join {joinTable} on {joinTable}.{joinProperty.Column} = {entity.Table}.{keyProperty.Column}";
var propertyToGet = foreignKey.ForeignEntity.Keys.FirstOrDefault(x => x.ForeignEntity != entity) ??
joinProperty;
columns += $",{joinTable}.{propertyToGet.Column} as {foreignKey.Column}";
}
}
var result = table.All(
columns: columns,
joins: joins,
where: where,
orderBy: orderBy,
args: args.ToArray());
var records = result
.Select(item => entity.CreateRecord(item))
.ToList();
return new PagedRecords
{
Records = records
};
}
}
示例6: create_filter_record
private static EntityRecord create_filter_record(
Entity entity,
NameValueCollection request)
{
return request == null ?
entity.CreateEmptyRecord() :
entity.CreateRecord(request, valueMutator: x => (string)x == Const.EmptyFilterValue ? "" : x);
}