Example #1
0
        public static IDataEntity FixNavigationProperties(DataRepositoryProperties props, IDataEntity item)
        {
            if (item != null && props != null)
            {
                Type           type       = item.GetType();
                PropertyInfo[] properties = type.GetProperties();

                foreach (
                    PropertyInfo property in
                    properties.Where(p => typeof(IEnumerable <IDataEntity>).IsAssignableFrom(p.PropertyType))
                    .ToArray())
                {
                    var propType = property.PropertyType;

                    var propCol = (property.GetValue(item) as IEnumerable <IDataEntity>).ToArray();

                    if (!propCol.IsNullOrEmpty())
                    {
                        propCol = _GetItems(props, propCol).ToArray();

                        var containedType = propType.GenericTypeArguments.First();
                        var newList       = _CreateList(containedType, propCol);
                        newList.Append(propCol);
                        //var newCol = _GetItem(props, propCol).Select(i =>(typeof(int))i);
                        property.SetValue(item, newList);
                    }
                }

                return(item);
            }
            return(null);
        }
Example #2
0
        private static IEnumerable <IDataEntity> _GetItems(DataRepositoryProperties props, IEnumerable <IDataEntity> eInput)
        {
            if (props.User != null)
            {
                eInput = eInput.Cast <ITrackable>().Where(q => q.CreatedBy == props.User.Id).Cast <IDataEntity>();
            }

            if (props.ExcludeDeleted)
            {
                eInput = eInput.Cast <IDeletable>().Where(q => !q.IsDeleted).Cast <IDataEntity>();
            }

            return(eInput);
        }
Example #3
0
        public JsonResult GetChildren(int type, int?childType, long parentId)
        {
            var context = new DataContext(false);

            var reposProps = new DataRepositoryProperties()
            {
                NavigationProperties = (childType.HasValue ? _GetNavigationProperties((ModelType)type, new [] { (ModelType)childType }) : _GetNavigationProperties((ModelType)type))
            };

            var dataSvc = new DataAccess(context, reposProps);

            var children = dataSvc.GetChildren(type, parentId);

            var vm = new TabContainerModel(children.Select(child => (IModel)_UpdateContainer(new TableContainerModel((IContainerModel)child))).ToList());

            return(Json(vm, JsonRequestBehavior.AllowGet));
        }
Example #4
0
        public JsonResult RemoveAll(int type, IEnumerable <string> itemJSONCol)
        {
            var context = new DataContext(false);

            var reposProps = new DataRepositoryProperties()
            {
                NavigationProperties = _GetNavigationProperties((ModelType)type)
            };

            var dataSvc = new DataAccess(context, reposProps);

            var modelCol = dataSvc.Remove(type, itemJSONCol);

            if (modelCol.IsNullOrEmpty())
            {
                return(Json(modelCol, JsonRequestBehavior.AllowGet));
            }

            var vmCol = _updateAllFuncMap[(ModelType)type](modelCol).ToArray();

            return(Json(vmCol, JsonRequestBehavior.AllowGet));
        }
Example #5
0
        public JsonResult GetAll(int type, long?startIndex, long?total, bool addBlank = true)
        {
            var context = new DataContext(false);

            var reposProps = new DataRepositoryProperties()
            {
                NavigationProperties = _GetNavigationProperties((ModelType)type)
            };

            var dataSvc = new DataAccess(context, reposProps);

            var modelCol = dataSvc.GetAll(type, startIndex, total, addBlank);

            if (modelCol.IsNullOrEmpty())
            {
                return(Json(null));
            }

            var vmCol = _updateAllFuncMap[(ModelType)type](modelCol);

            //var data = BinarySerializer.Serialize(vmCol);

            return(Json(vmCol));
        }
Example #6
0
 public DataAccess(IDataContext context, DataRepositoryProperties props = null) : this()
 {
     _context    = context;
     _reposProps = props;
 }
Example #7
0
        public EFDataRepository()
        {
            Properties = new DataRepositoryProperties();

            _type = typeof(T);
        }