예제 #1
0
        public void Delete(RouteValueDictionary values, object data)
        {
            object        id = GetId(values, data);
            PropertyStore ps = PropertyStore.CreateFrom(data);

            Repository.Instance.Delete(data.GetType(), ps, id);
        }
예제 #2
0
        public IEnumerable <PropertyStore> Get(Type type, Dictionary <string, object> clauses, List <string> fields, bool exceptFields)
        {
            // Build a list of multiple types - have to recurse using @Type argument
            if (clauses.ContainsKey("@Types"))
            {
                var newClauses = clauses.Where(kvp => kvp.Key != "@Types").ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
                newClauses.Add("@Type", null);
                foreach (Type subType in (List <Type>)clauses["@Types"])
                {
                    newClauses["@Type"] = subType;
                    var res = Get(type, newClauses, fields, exceptFields);
                    foreach (PropertyStore ps in res)
                    {
                        yield return(ps);
                    }
                }
            }

            Type tableType     = type;
            bool isSummaryType = false;

            if (typeof(Summary).IsAssignableFrom(type))
            {
                isSummaryType = true;
                if (clauses.ContainsKey("@Type"))
                {
                    tableType = (Type)clauses["@Type"];
                }
                else
                {
                    throw new ArgumentException("Must specify a type clause if returning summary type " + type.FullName);
                }
            }

            var query = QueryBuilderFactory.Instance.Create();

            if (isSummaryType)
            {
                query.SqlFields.AddRange(FieldsForSummary(tableType, type));
            }
            else
            {
                query.SqlFields.AddRange(fields);
            }

            PagingSpec paging = null;

            foreach (var kvp in clauses)
            {
                if (kvp.Key == "@Paging")
                {
                    paging = (PagingSpec)kvp.Value;
                }
                else if (!"@Type @Types".Contains(kvp.Key))
                {
                    query.SqlConditionals.Add(kvp.Key);
                    query.SqlParameters.Add("@" + kvp.Key.After("@").UpTo(" "), kvp.Value);
                }
            }

            query          = EventHub.Instance.ProcessEvent <IQueryBuilder>("BeforeContentGet", this, query);
            query.SqlTable = GetTableName(tableType);
            if (paging == null)
            {
                foreach (var ps in query.RunSelect())
                {
                    yield return(ps);
                }
            }
            else
            {
                int    count  = 0;
                string idName = GetIdName(tableType);
                List <PropertyStore> result = query.RunPagedSelect(paging.Skip, paging.Take,
                                                                   idName, type.GetProperty(idName).PropertyType,
                                                                   paging.Sort,
                                                                   string.IsNullOrEmpty(paging.Sort) ? null : type.GetProperty(paging.Sort).PropertyType,
                                                                   out count);
                paging.Total = count;
                result.Insert(0, PropertyStore.CreateFrom(paging));
                foreach (var ps in result)
                {
                    yield return(ps);
                }
            }
        }