当前位置: 首页>>代码示例>>C#>>正文


C# Entity.CreateRecord方法代码示例

本文整理汇总了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;
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:35,代码来源:EntityService.cs

示例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);
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:16,代码来源:RecordsSource.cs

示例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;
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:27,代码来源:EntityService.cs

示例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;
            }
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:59,代码来源:EntityService.cs

示例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
                };
            }
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:100,代码来源:RecordsSource.cs

示例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);
 }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:8,代码来源:RecordsService.cs


注:本文中的System.Entity.CreateRecord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。