Exemple #1
0
        public static void Delete(long id, ISave db = null)
        {
            if (db == null)
            {
                db = GetRepo();
            }
            var model = BaseCruds.Read <IContentModel>(BaseIContentModelType, b => b.Id == id, db).FirstOrDefault();

            if (model == null)
            {
                return;
            }
            var childrens = BaseCruds.Read <IContentModel>(BaseIContentModelType, b => b.ParentId == id, db).ToList();

            if (childrens.Count > 0)
            {
                childrens.ForEach(b => Delete(b.Id, db));
            }
            BaseCruds.Delete(model, db);
        }
Exemple #2
0
        public static IEnumerable <DropDownSummary> GetAllAvaliableSelectList()
        {
            var list = GetAllAvaliableSelect();

            if (list == null)
            {
                return(Enumerable.Empty <DropDownSummary>());
            }
            return(list.Select(b =>
            {
                var count = BaseCruds.Read <IInt64Key>(b, c => true, out ISave db).ToList().Count;
                var allowChild = b.GetObjectCustomAttribute <AllowChildrenAttribute>();
                var dropDownName = allowChild != null && String.IsNullOrEmpty(allowChild.Name) ? allowChild.Name : b.Name;
                return new DropDownSummary()
                {
                    Count = count,
                    DropDownName = dropDownName,
                    TypeName = b.FullName
                };
            }));
        }
Exemple #3
0
 public static IQueryable <T> Read <T>(Expression <Func <T, bool> > where, ISave repo) where T : class
 {
     return(BaseCruds.Read <T>(where, repo));
 }
Exemple #4
0
        public static void SetDropDownSelect(
            this PropertyInfo p, List <DropDownViewModel> selector, Type relatedType, string postValue, IEnumerable <string> postValues = null)
        {
            List <String> values;

            if (postValues != null && postValues.Count() > 0)
            {
                values = postValues.ToList();
            }
            else
            {
                values = !String.IsNullOrEmpty(postValue) ? new List <string>()
                {
                    postValue
                } : new List <string>();
            }

            if (relatedType.IsEnum)
            {
                Array enumValues = relatedType.GetEnumValues();
                foreach (var item in enumValues)
                {
                    var select = new DropDownViewModel();
                    select.Name   = item.ToString();
                    select.Value  = item.ToString();
                    select.Select = values.Contains(select.Value);
                    selector.Add(select);
                }
            }
            else
            {
                //dropdown Classes
                var isContent = relatedType.GetInterfaces().Any(b => b == typeof(IInt64Key));
                if (isContent)
                {
                    var allSelect = BaseCruds.Read <IBasicContent>(relatedType, b => true).ToList();

                    var selects = new List <DropDownViewModel>();
                    foreach (var item in allSelect)
                    {
                        var select = new DropDownViewModel();
                        select.Name   = item.DisplayName();
                        select.Value  = item.Id.ToString();
                        select.Select = values.Contains(select.Value);
                        selector.Add(select);
                    }
                }
                else
                {
                    var allSelect = BaseCruds.Read <IStringKey>(relatedType, b => true).ToList();

                    var selects = new List <DropDownViewModel>();
                    foreach (var item in allSelect)
                    {
                        var select = new DropDownViewModel();
                        select.Name   = item.ToString();
                        select.Value  = item.Id;
                        select.Select = values.Contains(select.Value);
                        selector.Add(select);
                    }
                }
            }
        }
Exemple #5
0
 public static T GetByPK <T>(long id, out ISave db) where T : class, IContentModel
 {
     db = GetRepo();
     return(BaseCruds.Read <T>(BaseIContentModelType, b => b.Id == id, db).FirstOrDefault());
 }
        public static IEnumerable <T> GetPropertyEnumerableByKey <T>(this object input, string key)
        {
            var listResult = new List <T>();

            if (input == null)
            {
                return(listResult);
            }
            var type = input.GetType().GetRealType();
            var p    = type.GetProperties().Where(b => string.Equals(b.Name, key, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (p == null)
            {
                return(listResult);
            }
            var inputType = p.GetObjectCustomAttribute <InputTypeAttribute>();
            var value     = p.GetValue(input);

            if (inputType != null && inputType.RelatedType != null && !inputType.RelatedType.IsEnum)
            {
                var longKey = inputType.RelatedType.GetInterfaces().Any(b => b == typeof(IInt64Key));
                var values  = value.Text().StringValueToList();
                if (inputType.MultiSelect)
                {
                    var types = inputType.RelatedType.GetInterfaces().ToList();
                    types.Add(inputType.RelatedType);
                    IEnumerable <object> objList;
                    if (longKey)
                    {
                        var longValues = values.Select(b => b.MyTryConvert <long>()).ToList();
                        objList = BaseCruds.Read <IInt64Key>(inputType.RelatedType, b => longValues.Contains(b.Id)).ToList();
                    }
                    else
                    {
                        if (typeof(T) == typeof(string) || typeof(T) == typeof(String))
                        {
                            objList = BaseCruds.Read <IStringKey>(inputType.RelatedType, b => values.Contains(b.Id)).ToList().Select(b => (b as IDisplayName).DisplayName()).ToList();
                        }
                        else
                        {
                            objList = BaseCruds.Read <IStringKey>(inputType.RelatedType, b => values.Contains(b.Id)).ToList();
                        }
                    }
                    if (types.Contains(typeof(T)))
                    {
                        return(objList.Select(b => b.MyTryConvert <T>()).ToList());
                    }
                    var isDisplayName = inputType.RelatedType.GetInterfaces().Any(b => b.Name == typeof(IDisplayName).Name);
                    if (isDisplayName)
                    {
                        value = String.Join(",", objList.Select(b => (b as IDisplayName).DisplayName()));
                    }
                    else
                    {
                        value = String.Join(",", objList.ToString());
                    }
                }
                else
                {
                    var firstValue = values.FirstOrDefault();
                    if (longKey)
                    {
                        var longValue = firstValue.MyTryConvert <long>();
                        value = BaseCruds.Read <IInt64Key>(inputType.RelatedType, b => b.Id == longValue).ToList().Select(b => b.MyTryConvert <T>()).FirstOrDefault();
                    }
                    else
                    {
                        if (typeof(T) == typeof(string) || typeof(T) == typeof(String))
                        {
                            value = BaseCruds.Read <IStringKey>(inputType.RelatedType, b => values.Contains(b.Id)).ToList().Select(b => (b as IDisplayName).DisplayName()).ToList().FirstOrDefault();
                        }
                        else
                        {
                            value = BaseCruds.Read <IStringKey>(inputType.RelatedType, b => values.Contains(b.Id)).ToList().Select(b => b.MyTryConvert <T>()).ToList().FirstOrDefault();
                        }
                    }
                }
            }
            if (value == null)
            {
                return(listResult);
            }
            listResult.Add(value.MyTryConvert <T>());
            return(listResult);
        }