Пример #1
0
        public static int IndexOf <TElement>(this DataServiceQuery <TElement> q, Guid key)
        {
            var condition = new FilterParameterCollection();

            condition.Add("Id", key);
            return(IndexOf <TElement>(q, condition));
        }
Пример #2
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         return _db.Holidays.Filtering(filters, opResolver).Count();
     }
 }
Пример #3
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         return(_db.Governors.AddFilters(filters).TotalCount());
     }
 }
Пример #4
0
        public static int GetIndexOf(this IQueryable query, FilterParameterCollection findCondition, Type type)
        {
            var minfo = typeof(EfSqlExtension).GetGenericMethod("GetIndexOf", new Type[] { typeof(IQueryable <>), typeof(FilterParameterCollection) });
            var val   = minfo.MakeGenericMethod(type).Invoke(null, new object[] { query, findCondition }) as int?;

            return(val ?? 0);
        }
Пример #5
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         return(_db.Governors.Filtering(filters, opResolver).Count());
     }
 }
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            string condition = HttpUtility.ParseQueryString(actionExecutedContext.Request.RequestUri.Query).Get("rf.condition");
            if (condition == "IsHoliday")
            {
                //bug in HttpRequestMessage : RequestUri setter not change Properties. Do it manually.
                //if (request.Properties.ContainsKey(System.Web.Http.Hosting.HttpPropertyKeys.RequestQueryNameValuePairsKey))
                //{
                //    request.Properties.Remove(System.Web.Http.Hosting.HttpPropertyKeys.RequestQueryNameValuePairsKey);
                //    request.GetQueryNameValuePairs();
                //}

                ObjectContent responseContent = actionExecutedContext.Response.Content as ObjectContent;
                IQueryable<WorkCalendar> query = null;
                if (responseContent != null)
                    query = responseContent.Value as IQueryable<WorkCalendar>;

                if (query != null)
                {
                    FilterParameterCollection fc = new FilterParameterCollection(typeof(WorkCalendar));
                    fc.Add("IsWorkingDay", false, OperatorType.Condition);
                    fc.OperatorActionResolver = new ConditionOpRes();
                    responseContent.Value = query.Filtering(fc);
                }
            }

            base.OnActionExecuted(actionExecutedContext);
        }
Пример #7
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         return _db.Governors.AddFilters(filters).TotalCount();
     }
 }
Пример #8
0
        public IEnumerable <BLL.AssetValue> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
        {
            lock (_db)
            {
                orderBy.DefaultOrder         = defaultSorting;
                orderBy.PropertyNameResolver = propResolver;
                if (filters != null)
                {
                    filters.PropertyNameResolver = propResolver;
                }
                int skip   = pageIndex * pageSize;
                var list   = _db.Assets.AddFilters(filters).AddOrders(orderBy).Skip(skip).Take(pageSize);
                var govCtx = _db.Governors;
                foreach (var m in list)
                {
                    //provide action like '$expand' for Governors
                    var gov = govCtx.GetById(m.GovernorId);
                    if (gov == null)
                    {
                        gov = govCtx.ToList().FirstOrDefault(g => g.Id == m.GovernorId);
                    }
                    m.Governor = gov;

                    yield return(ProxyActivator.CreateProxy <AssetValue, BLL.AssetValue>(m));
                }
            }
        }
Пример #9
0
        public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
        {
            string condition = HttpUtility.ParseQueryString(actionExecutedContext.Request.RequestUri.Query).Get("rf.condition");

            if (condition == "IsHoliday")
            {
                //bug in HttpRequestMessage : RequestUri setter not change Properties. Do it manually.
                //if (request.Properties.ContainsKey(System.Web.Http.Hosting.HttpPropertyKeys.RequestQueryNameValuePairsKey))
                //{
                //    request.Properties.Remove(System.Web.Http.Hosting.HttpPropertyKeys.RequestQueryNameValuePairsKey);
                //    request.GetQueryNameValuePairs();
                //}

                ObjectContent             responseContent = actionExecutedContext.Response.Content as ObjectContent;
                IQueryable <WorkCalendar> query           = null;
                if (responseContent != null)
                {
                    query = responseContent.Value as IQueryable <WorkCalendar>;
                }

                if (query != null)
                {
                    FilterParameterCollection fc = new FilterParameterCollection(typeof(WorkCalendar));
                    fc.Add("IsWorkingDay", false, OperatorType.Condition);
                    fc.OperatorActionResolver = new ConditionOpRes();
                    responseContent.Value     = query.Filtering(fc);
                }
            }

            base.OnActionExecuted(actionExecutedContext);
        }
Пример #10
0
        private FilterParameterCollection GetFilters()
        {
            Type modelType = this.FilteredModelType;

            if (modelType == null)
            {
                var dobj = this.DataContext as DataObj;
                if (dobj != null)
                {
                    modelType = dobj.Model.GetType();
                }
            }

            if (modelType != null)
            {
                FilterParameterCollection fc = new FilterParameterCollection(modelType);
                foreach (FilterCC f in DispatcherHelper.FindVisualChildren <FilterCC>(this).Where(f => f.IsEnabled))
                {
                    if (f.Value != null)
                    {
                        if (f.Value.GetType() == typeof(string))
                        {
                            string s = f.Value as string;
                            if (string.IsNullOrEmpty(s) == false)
                            {
                                Type targtType = typeof(string);
                                var  fiedInfo  = modelType.GetProperty(f.FieldName);
                                if (fiedInfo != null && fiedInfo.PropertyType != targtType)
                                {
                                    targtType = fiedInfo.PropertyType;
                                    var val = Convert.ChangeType(f.Value, targtType);
                                    f.Value = val;
                                }

                                if (f.OperatorType == OperatorType.Equals && targtType == typeof(string))
                                {
                                    if (s.Contains("?") || s.Contains("*"))
                                    {
                                        f.OperatorType = OperatorType.Like;
                                    }
                                }
                                fc.Add(f.FieldName, f.Value, f.OperatorType);
                            }
                        }
                        else
                        {
                            fc.Add(f.FieldName, f.Value, f.OperatorType);
                        }
                    }
                    else if (f.OperatorType == OperatorType.IsNull || f.OperatorType == OperatorType.IsNotNull)
                    {
                        fc.Add(f.FieldName, f.Value, f.OperatorType);
                    }
                }
                return(fc);
            }

            return(null);
        }
Пример #11
0
 public int GetIndexOf(BLL.WorkCalendar o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     var condition = new FilterParameterCollection();
     condition.Add("Date", o.Date);
     if (filters != null)
         filters.OperatorActionResolver = opResolver;
     return _db.Holidays.AddFilters(filters).AddOrders(orderBy).IndexOf(condition);
 }
Пример #12
0
 public int GetIndexOf(WorkCalendar o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     orderBy.DefaultOrder = defaultSorting;
     if (filters != null)
     {
         filters.OperatorActionResolver = opResolver;
     }
     return(_db.Holidays.GetIndexOf(filters, orderBy, poco => poco.Date == o.Date));
 }
Пример #13
0
        public static int IndexOf <TElement>(this DataServiceQuery <TElement> q, FilterParameterCollection keyCondition)
        {
            var query    = q.AddQueryOption("rf.indexof", HttpUtility.UrlEncode(keyCondition.JsonSerialize(), Encoding.GetEncoding(1251)));
            var response = query.Execute() as QueryOperationResponse <TElement>;
            int idx      = -1;

            int.TryParse(response.Headers.FirstOrDefault(h => h.Key == "Index-Of-Model").Value, out idx);
            return(idx);
        }
Пример #14
0
        public static string JsonSerialize(this FilterParameterCollection fc)
        {
            var st = new JsonSerializerSettings();

            st.Converters.Add(new FilterResolversJsonConverter());
            string s = JsonConvert.SerializeObject(fc, st);

            return(s);
        }
Пример #15
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         if (filters != null)
             filters.OperatorActionResolver = opResolver;
         return _db.Holidays.AddFilters(filters).TotalCount();
     }
 }
Пример #16
0
        private FilterParameterCollection GetFilters()
        {
            Type modelType = this.FilteredModelType;
            if (modelType == null)
            {
                var dobj = this.DataContext as DataObj;
                if (dobj != null)
                {
                    modelType = dobj.Model.GetType();
                }
            }

            if (modelType != null)
            {
                FilterParameterCollection fc = new FilterParameterCollection(modelType);
                foreach (FilterCC f in DispatcherHelper.FindVisualChildren<FilterCC>(this).Where(f => f.IsEnabled))
                {
                    if (f.Value != null)
                    {
                        if (f.Value.GetType() == typeof(string))
                        {
                            string s = f.Value as string;
                            if (string.IsNullOrEmpty(s) == false)
                            {
                                Type targtType = null;
                                var fiedInfo = modelType.GetProperty(f.FieldName);
                                if (fiedInfo != null)
                                {
                                    targtType = fiedInfo.PropertyType;
                                    var val = Convert.ChangeType(f.Value, targtType);
                                    OperatorType op = f.OperatorType;
                                    if (op == OperatorType.Equals && targtType == typeof(string))
                                    {
                                        if (s.Contains("?") || s.Contains("*"))
                                        {
                                            op = OperatorType.Like;
                                        }
                                    }
                                    fc.Add(f.FieldName, val, op);
                                }
                            }
                        }
                        else
                        {
                            fc.Add(f.FieldName, f.Value, f.OperatorType);
                        }
                    }
                    else if (f.OperatorType == OperatorType.IsNull || f.OperatorType == OperatorType.IsNotNull)
                    {
                        fc.Add(f.FieldName, f.Value, f.OperatorType);
                    }
                }
                return fc;
            }

            return null;
        }
Пример #17
0
 public int GetIndexOf(Governor o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     orderBy.DefaultOrder = defaultSorting;
     if (filters != null)
     {
         filters.OperatorActionResolver = opResolver;
     }
     return(_db.Governors.GetIndexOf(filters, orderBy, poco => poco.Id == o.Id));
 }
Пример #18
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         if (filters != null)
             filters.PropertyNameResolver = propResolver;
         return _db.Assets.AddFilters(filters).TotalCount();
     }
 }
Пример #19
0
        public int GetIndexOf(BLL.AssetValue o, FilterParameterCollection filters, SortParameterCollection orderBy)
        {
            orderBy.DefaultOrder = defaultSorting;
            orderBy.PropertyNameResolver = propResolver;
            if (filters != null)
                filters.PropertyNameResolver = propResolver;

            return _db.Assets.AddFilters(filters).AddOrders(orderBy).IndexOf(o.Id);
        }
Пример #20
0
 public IEnumerable<WorkCalendar> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     lock (_db)
     {
         orderBy.DefaultOrder = defaultSorting;
         var list = _db.Holidays.Filtering(filters, opResolver).Sorting(orderBy).Paging(pageIndex, pageSize);
         foreach (var m in list)
             yield return m;
     }
 }
Пример #21
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         if (filters != null)
         {
             filters.OperatorActionResolver = opResolver;
         }
         return(_db.Holidays.AddFilters(filters).TotalCount());
     }
 }
Пример #22
0
        public int GetIndexOf(BLL.WorkCalendar o, FilterParameterCollection filters, SortParameterCollection orderBy)
        {
            var condition = new FilterParameterCollection();

            condition.Add("Date", o.Date);
            if (filters != null)
            {
                filters.OperatorActionResolver = opResolver;
            }
            return(_db.Holidays.AddFilters(filters).AddOrders(orderBy).IndexOf(condition));
        }
Пример #23
0
 public int GetListCount(FilterParameterCollection filters)
 {
     lock (_db)
     {
         if (filters != null)
         {
             filters.PropertyNameResolver = propResolver;
         }
         return(_db.Assets.AddFilters(filters).TotalCount());
     }
 }
Пример #24
0
        public int GetIndexOf(BLL.AssetValue o, FilterParameterCollection filters, SortParameterCollection orderBy)
        {
            orderBy.DefaultOrder         = defaultSorting;
            orderBy.PropertyNameResolver = propResolver;
            if (filters != null)
            {
                filters.PropertyNameResolver = propResolver;
            }

            return(_db.Assets.AddFilters(filters).AddOrders(orderBy).IndexOf(o.Id));
        }
Пример #25
0
 public int GetIndexOf(AssetValue o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     orderBy.DefaultOrder         = defaultSorting;
     orderBy.PropertyNameResolver = propResolver;
     if (filters != null)
     {
         filters.OperatorActionResolver = opResolver;
         filters.PropertyNameResolver   = propResolver;
     }
     return(_db.Assets.GetIndexOf(filters, orderBy, poco => poco.Id == o.Id));
 }
Пример #26
0
 public IEnumerable<BLL.Governor> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     lock (_db)
     {
         orderBy.DefaultOrder = defaultSorting;
         int skip = pageIndex * pageSize;
         var list = _db.Governors.AddFilters(filters).AddOrders(orderBy).Skip(skip).Take(pageSize);
         foreach (var m in list)
             yield return ProxyActivator.CreateProxy<Governor, BLL.Governor>(m);
     }
 }
Пример #27
0
 public IEnumerable <Governor> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     lock (_db)
     {
         orderBy.DefaultOrder = defaultSorting;
         var list = _db.Governors.Filtering(filters, opResolver).Sorting(orderBy).Paging(pageIndex, pageSize);
         foreach (var m in list)
         {
             yield return(m);
         }
     }
 }
Пример #28
0
 public IEnumerable<BLL.WorkCalendar> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     lock (_db)
     {
         orderBy.DefaultOrder = defaultSorting;
         int skip = pageIndex * pageSize;
         if (filters != null)
             filters.OperatorActionResolver = opResolver;
         var list = _db.Holidays.AddFilters(filters).AddOrders(orderBy).Skip(skip).Take(pageSize);
         foreach (var m in list)
             yield return ProxyActivator.CreateProxy<WorkCalendar, BLL.WorkCalendar>(m);
     }
 }
Пример #29
0
 public IEnumerable <BLL.Governor> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     lock (_db)
     {
         orderBy.DefaultOrder = defaultSorting;
         int skip = pageIndex * pageSize;
         var list = _db.Governors.AddFilters(filters).AddOrders(orderBy).Skip(skip).Take(pageSize);
         foreach (var m in list)
         {
             yield return(ProxyActivator.CreateProxy <Governor, BLL.Governor>(m));
         }
     }
 }
Пример #30
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            try
            {
                JObject jObject = JObject.Load(reader);
                FilterParameterCollection result = null;
                IFilterOperatorResolver   opres  = null;
                IFilterSortPropResolver   props  = null;

                foreach (var prop in jObject.Properties())
                {
                    if (prop.Name == "params")
                    {
                        var st = new JsonSerializerSettings();
                        st.Converters.Add(new FilterParameterJsonConverter());
                        result = JsonConvert.DeserializeObject <FilterParameterCollection>((string)prop.Value, st);
                    }
                    else if (prop.Name == typeof(IFilterOperatorResolver).Name)
                    {
                        Type opresType = Type.GetType((string)prop.Value);
                        opres = Activator.CreateInstance(opresType) as IFilterOperatorResolver;
                    }
                    else if (prop.Name == typeof(IFilterSortPropResolver).Name)
                    {
                        Type propsType = Type.GetType((string)prop.Value);
                        props = Activator.CreateInstance(propsType) as IFilterSortPropResolver;
                    }
                }

                if (result != null)
                {
                    if (opres != null)
                    {
                        result.OperatorActionResolver = opres;
                    }
                    if (props != null)
                    {
                        result.PropertyNameResolver = props;
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #31
0
 public IEnumerable <AssetValue> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     lock (_db)
     {
         orderBy.DefaultOrder         = defaultSorting;
         orderBy.PropertyNameResolver = propResolver;
         if (filters != null)
         {
             filters.PropertyNameResolver = propResolver;
         }
         var list = _db.Assets.Include("Governor").Include("Governor.Company").Filtering(filters, opResolver).Sorting(orderBy).Paging(pageIndex, pageSize);
         foreach (var m in list)
         {
             yield return(m);
         }
     }
 }
Пример #32
0
 public IEnumerable <BLL.WorkCalendar> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     lock (_db)
     {
         orderBy.DefaultOrder = defaultSorting;
         int skip = pageIndex * pageSize;
         if (filters != null)
         {
             filters.OperatorActionResolver = opResolver;
         }
         var list = _db.Holidays.AddFilters(filters).AddOrders(orderBy).Skip(skip).Take(pageSize);
         foreach (var m in list)
         {
             yield return(ProxyActivator.CreateProxy <WorkCalendar, BLL.WorkCalendar>(m));
         }
     }
 }
Пример #33
0
        public IEnumerable<BLL.AssetValue> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
        {
            lock (_db)
            {
                orderBy.DefaultOrder = defaultSorting;
                orderBy.PropertyNameResolver = propResolver;
                if (filters != null)
                    filters.PropertyNameResolver = propResolver;
                int skip = pageIndex * pageSize;
                var list = _db.Assets.AddFilters(filters).AddOrders(orderBy).Skip(skip).Take(pageSize);
                var govCtx = _db.Governors;
                foreach (var m in list)
                {
                    //provide action like '$expand' for Governors
                    var gov = govCtx.GetById(m.GovernorId);
                    if (gov == null)
                        gov = govCtx.ToList().FirstOrDefault(g => g.Id == m.GovernorId);
                    m.Governor = gov;

                    yield return ProxyActivator.CreateProxy<AssetValue, BLL.AssetValue>(m);
                }
            }
        }
Пример #34
0
 public int GetIndexOf(WorkCalendar o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     orderBy.DefaultOrder = defaultSorting;
     if (filters != null) filters.OperatorActionResolver = opResolver;
     return _db.Holidays.GetIndexOf(filters, orderBy, poco => poco.Date == o.Date);
 }
Пример #35
0
 public int GetIndexOf(object o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     throw new NotImplementedException();
 }
Пример #36
0
 public int GetIndexOf(BLL.Governor o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     return _db.Governors.AddFilters(filters).AddOrders(orderBy).IndexOf(o.Id);
 }
Пример #37
0
 public static IEnumerable<Addr> GetList(FilterParameterCollection filters, int pageIndex, int pageSize)
 {
     return DbHelper.CreateCommand("select * from tblAddress").AddFiltering(filters).AddPaging(pageIndex, pageSize, "KodPS, AddrType").Select<Addr>().ToList();
 }
Пример #38
0
        static void Main(string[] args)
        {
            OAuthProvider.Behavior = Activator.CreateInstance(OAuthConfiguration.Configuration.ClientSettings.WcfDSBehaviorType) as IOAuthBehavior;
            Logon.Page = new LogonProc();
            var ctx = new WebApiCtx();
            FilterParameterCollection fc = new FilterParameterCollection();
            fc.Add("ShortName", "магомед ук");
            SortParameterCollection sc = new SortParameterCollection();
            sc.Add(null, "Company.Name", System.ComponentModel.ListSortDirection.Ascending);
            sc.Add(null, "Id", System.ComponentModel.ListSortDirection.Ascending);

            //var val = ctx.Governors.AddFilters(fc).AddOrders(sc).First();
            //var val = ctx.Governors.First();
            //val.Company.lawFormValue = 6;
            Guid g = new Guid("CEB5254F-5FFE-469B-ABC5-09AB388E6505");
            //var val = ctx.Governors.Where(gov => gov.Id == g).FirstOrDefault();
            Guid g2 = new Guid("CEB5254F-5FFE-469B-ABC5-09AB388E6505");
            Governor val2 = null;
            //ctx.TryGetEntity(new Uri("http://localhost:555/Governors(guid'ceb5254f-5ffe-469b-abc5-09ab388e6505')"), out val2);
            //Governor val2 = ctx.Governors.Where(gov => gov.Id == g2).FirstOrDefault();
            //val2 = ctx.Entities.FirstOrDefault(e => e.Identity.Contains("Governors(guid'ceb5254f-5ffe-469b-abc5-09ab388e6505')")).Entity as Governor;
            //val2 = ctx.Governors.GetById(g);

            ctx.Governors.ToList();

            //Console.WriteLine(ctx.Governors.TotalCount());

            //var ass = ctx.Assets.Where(a => a.Id == new Guid("D3B67671-87C5-4B33-8DF1-7D83947E5FB8")).First();

            var ass = new AssetValue();
            ass.Id = Guid.NewGuid();
            ass.InsuranceTypeValue = 1;
            ass.TakingDate = DateTime.Today;
            ass.Value = 3344434.56m;
            ass.GovernorId = g2;

            string s = JsonConvert.SerializeObject(ass);
            var list = new List<string>();
            list.Add(s);

            UriBuilder urib = new UriBuilder(ctx.BaseUri);
            //urib.Path = string.Format("{0}/CreateBatch", ctx.Assets.RequestUri.PathAndQuery);
            //var r = ctx.Execute<bool>(urib.Uri, "POST", true, new BodyOperationParameter("Values", list)).FirstOrDefault();

            //ctx.AddToAssets(ass);
            //ctx.SetLink(ass, "Governor", val2);

            //ctx.SaveChanges();
            //ctx.AttachLink(ass, "Governor", val2);

            //Guid g = new Guid("32D3F7C1-97E1-4A69-8C8A-E3706490329E");
            //var val = ctx.Holidays.Where(h => h.Id == g).FirstOrDefault();

            //val.Comment = "Test Comment";


            var newc = new Company();
            newc.Id = Guid.NewGuid();
            newc.Name = "Test Governor Company Name";
            var newg = new Governor();
            newg.Id = Guid.NewGuid();
            newg.ShortName = "Test Governor Name";
            newg.Company = newc;
            ctx.AddToGovernors(newg);
            ctx.SaveChanges();
            newg.ShortName = "Test Governor Name Updated";
            ctx.UpdateObject(newg);
            //ctx.SaveChanges(SaveChangesOptions.PatchOnUpdate);
            System.Threading.Thread.Sleep(1000);
            ctx.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);
            ctx.DeleteObject(newg);
            ctx.SaveChanges();

            //var serviceCreds = new NetworkCredential("Administrator", "SecurePassword");
            //var cache = new CredentialCache();
            //var serviceUri = new Uri("http://ipv4.fiddler:333/api/issue");
            //cache.Add(serviceUri, "Basic", serviceCreds);
            //ctx.Credentials = cache;
            //var r = ctx.Execute(new Uri("http://ipv4.fiddler:333/api/issue"), "POST", new BodyOperationParameter("rst", new TokenRequest() { GrantType = "client_credentials", Scope = "http://localhost" }));
            Console.ReadLine();
        }
Пример #39
0
 public IEnumerable <object> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     return(_rep.GetList(filters, pageIndex, pageSize, orderBy).Cast <object>().ToList());
 }
Пример #40
0
 public FilterBlockEventArgs(FilterParameterCollection fc)
 {
     this.Filters = fc;
 }
Пример #41
0
 public int GetIndexOf(object o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     return _rep.GetIndexOf((AssetValue)o, filters, orderBy);
 }
Пример #42
0
 public FilterBlockEventArgs(FilterParameterCollection fc)
 {
     this.Filters = fc;
 }
 public int GetIndexOf(object o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     return _rep.GetIndexOf((WorkCalendar)o, filters, orderBy);
 }
 public IEnumerable<object> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     return _rep.GetList(filters, pageIndex, pageSize, orderBy).Cast<object>().ToList();
 }
 public int GetListCount(FilterParameterCollection filters)
 {
     return _rep.GetListCount(filters);
 }
Пример #46
0
 public int GetIndexOf(BLL.Governor o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     return(_db.Governors.AddFilters(filters).AddOrders(orderBy).IndexOf(o.Id));
 }
Пример #47
0
 public int GetListCount(FilterParameterCollection filters)
 {
     return(_rep.GetListCount(filters));
 }
Пример #48
0
        static void Main(string[] args)
        {
            OAuthProvider.Behavior = Activator.CreateInstance(OAuthConfiguration.Configuration.ClientSettings.WcfDSBehaviorType) as IOAuthBehavior;
            Logon.Page             = new LogonProc();
            var ctx = new WebApiCtx();
            FilterParameterCollection fc = new FilterParameterCollection();

            fc.Add("ShortName", "магомед ук");
            SortParameterCollection sc = new SortParameterCollection();

            sc.Add(null, "Company.Name", System.ComponentModel.ListSortDirection.Ascending);
            sc.Add(null, "Id", System.ComponentModel.ListSortDirection.Ascending);

            //var val = ctx.Governors.AddFilters(fc).AddOrders(sc).First();
            //var val = ctx.Governors.First();
            //val.Company.lawFormValue = 6;
            Guid g = new Guid("CEB5254F-5FFE-469B-ABC5-09AB388E6505");
            //var val = ctx.Governors.Where(gov => gov.Id == g).FirstOrDefault();
            Guid     g2   = new Guid("CEB5254F-5FFE-469B-ABC5-09AB388E6505");
            Governor val2 = null;

            //ctx.TryGetEntity(new Uri("http://localhost:555/Governors(guid'ceb5254f-5ffe-469b-abc5-09ab388e6505')"), out val2);
            //Governor val2 = ctx.Governors.Where(gov => gov.Id == g2).FirstOrDefault();
            //val2 = ctx.Entities.FirstOrDefault(e => e.Identity.Contains("Governors(guid'ceb5254f-5ffe-469b-abc5-09ab388e6505')")).Entity as Governor;
            //val2 = ctx.Governors.GetById(g);

            ctx.Governors.ToList();

            //Console.WriteLine(ctx.Governors.TotalCount());

            //var ass = ctx.Assets.Where(a => a.Id == new Guid("D3B67671-87C5-4B33-8DF1-7D83947E5FB8")).First();

            var ass = new AssetValue();

            ass.Id = Guid.NewGuid();
            ass.InsuranceTypeValue = 1;
            ass.TakingDate         = DateTime.Today;
            ass.Value      = 3344434.56m;
            ass.GovernorId = g2;

            string s    = JsonConvert.SerializeObject(ass);
            var    list = new List <string>();

            list.Add(s);

            UriBuilder urib = new UriBuilder(ctx.BaseUri);
            //urib.Path = string.Format("{0}/CreateBatch", ctx.Assets.RequestUri.PathAndQuery);
            //var r = ctx.Execute<bool>(urib.Uri, "POST", true, new BodyOperationParameter("Values", list)).FirstOrDefault();

            //ctx.AddToAssets(ass);
            //ctx.SetLink(ass, "Governor", val2);

            //ctx.SaveChanges();
            //ctx.AttachLink(ass, "Governor", val2);

            //Guid g = new Guid("32D3F7C1-97E1-4A69-8C8A-E3706490329E");
            //var val = ctx.Holidays.Where(h => h.Id == g).FirstOrDefault();

            //val.Comment = "Test Comment";


            var newc = new Company();

            newc.Id   = Guid.NewGuid();
            newc.Name = "Test Governor Company Name";
            var newg = new Governor();

            newg.Id        = Guid.NewGuid();
            newg.ShortName = "Test Governor Name";
            newg.Company   = newc;
            ctx.AddToGovernors(newg);
            ctx.SaveChanges();
            newg.ShortName = "Test Governor Name Updated";
            ctx.UpdateObject(newg);
            //ctx.SaveChanges(SaveChangesOptions.PatchOnUpdate);
            System.Threading.Thread.Sleep(1000);
            ctx.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);
            ctx.DeleteObject(newg);
            ctx.SaveChanges();

            //var serviceCreds = new NetworkCredential("Administrator", "SecurePassword");
            //var cache = new CredentialCache();
            //var serviceUri = new Uri("http://ipv4.fiddler:333/api/issue");
            //cache.Add(serviceUri, "Basic", serviceCreds);
            //ctx.Credentials = cache;
            //var r = ctx.Execute(new Uri("http://ipv4.fiddler:333/api/issue"), "POST", new BodyOperationParameter("rst", new TokenRequest() { GrantType = "client_credentials", Scope = "http://localhost" }));
            Console.ReadLine();
        }
Пример #49
0
 public int GetIndexOf(object o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     return(_rep.GetIndexOf((AssetValue)o, filters, orderBy));
 }
Пример #50
0
        public static SqlCommand AddFiltering(this SqlCommand cmd, FilterParameterCollection filters)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            if (filters == null || filters.Count == 0)
            {
                return(cmd);
            }

            cmd.CommandText = EnvelopeExpression(cmd.CommandText, "*") + " where 1=1";

            StringBuilder sb = new StringBuilder();

            Dictionary <FilterParameter, string> filterParameter_SqlPars = new Dictionary <FilterParameter, string>();
            const string parameterPrefix = "@";

            Dictionary <string, int> columnStats    = new Dictionary <string, int>();
            Dictionary <string, int> columnCurStats = new Dictionary <string, int>();
            Dictionary <string, int> orGroupStats   = new Dictionary <string, int>();
            Dictionary <string, int> andGroupStats  = new Dictionary <string, int>();

            foreach (FilterParameter fp in filters.Where(f => f.Operator != OperatorType.Top))
            {
                if (columnStats.ContainsKey(fp.ColumnName) == false)
                {
                    columnStats.Add(fp.ColumnName, 0);
                }

                columnStats[fp.ColumnName]++;

                if (!string.IsNullOrEmpty(fp.AndGroupName))
                {
                    if (andGroupStats.ContainsKey(fp.AndGroupName) == false)
                    {
                        andGroupStats.Add(fp.AndGroupName, 1);
                    }
                    andGroupStats[fp.AndGroupName]++;
                }
                if (!string.IsNullOrEmpty(fp.OrGroupName))
                {
                    if (orGroupStats.ContainsKey(fp.OrGroupName) == false)
                    {
                        orGroupStats.Add(fp.OrGroupName, 1);
                    }
                    orGroupStats[fp.OrGroupName]++;
                }
            }

            foreach (FilterParameter fp in filters.Where(f => f.Operator != OperatorType.Top))
            {
                string safeParameterBaseName = fp.ColumnName.Replace("[", "").Replace("]", "").Replace(".", "__");

                if (columnStats[fp.ColumnName] == 1)
                {
                    filterParameter_SqlPars.Add(fp, parameterPrefix + safeParameterBaseName);
                }

                else
                {
                    if (columnCurStats.ContainsKey(fp.ColumnName) == false)
                    {
                        columnCurStats.Add(fp.ColumnName, 0);
                    }

                    columnCurStats[fp.ColumnName]++;
                    filterParameter_SqlPars.Add(fp, parameterPrefix + safeParameterBaseName + "_" + columnCurStats[fp.ColumnName]);
                }
            }

            string orGroup  = string.Empty;
            string andGroup = string.Empty;

            foreach (FilterParameter fp in filters.Where(f => f.Operator != OperatorType.Top))
            {
                OperatorType op = fp.Operator;
                string       columnNameWithDelimiter = string.Empty;

                if (
                    (fp.Value == null ||
                     (fp.Value.GetType() == typeof(Guid) && (Guid)fp.Value == Guid.Empty) ||
                     (fp.Value.GetType().IsArray&& ((Array)fp.Value).Length == 0)
                     /*HARDCODE*/
                     || (fp.Value.GetType() == typeof(bool) && (bool)fp.Value == false) ||
                     (fp.Value.GetType() == typeof(string) && string.IsNullOrEmpty((string)fp.Value) && op == OperatorType.Query)
                    ) &&
                    op != OperatorType.IsFalse &&
                    op != OperatorType.IsTrue &&
                    op != OperatorType.IsNull &&
                    op != OperatorType.IsNotNull &&
                    op != OperatorType.EqualsWithNull
                    )
                {
                    continue;
                }
                else if (op != OperatorType.None)
                {
                    if (!string.IsNullOrEmpty(orGroup) && orGroup != fp.OrGroupName)
                    {
                        columnNameWithDelimiter += " ) ";
                        orGroup = string.Empty;
                    }
                    if (!string.IsNullOrEmpty(andGroup) && andGroup != fp.AndGroupName)
                    {
                        columnNameWithDelimiter += " ) ";
                        andGroup = string.Empty;
                    }
                    if (string.IsNullOrEmpty(orGroup) && string.IsNullOrEmpty(andGroup))
                    {
                        columnNameWithDelimiter += " and ";
                    }
                    if (!string.IsNullOrEmpty(fp.OrGroupName) && !string.IsNullOrEmpty(fp.AndGroupName) && fp.OrGroupName != orGroup && fp.AndGroupName != andGroup)
                    {
                        columnNameWithDelimiter += " (( ";
                        orGroup  = fp.OrGroupName;
                        andGroup = fp.AndGroupName;
                    }
                    else if (!string.IsNullOrEmpty(fp.OrGroupName) && !string.IsNullOrEmpty(fp.AndGroupName) && fp.OrGroupName == orGroup && fp.AndGroupName != andGroup)
                    {
                        columnNameWithDelimiter += " or ( ";
                        andGroup = fp.AndGroupName;
                    }
                    else if (!string.IsNullOrEmpty(fp.OrGroupName) && !string.IsNullOrEmpty(fp.AndGroupName) && fp.OrGroupName != orGroup && fp.AndGroupName == andGroup)
                    {
                        columnNameWithDelimiter += " and ( ";
                        orGroup = fp.OrGroupName;
                    }
                    else if (!string.IsNullOrEmpty(fp.OrGroupName) && !string.IsNullOrEmpty(fp.AndGroupName) && fp.OrGroupName == orGroup && fp.AndGroupName == andGroup)
                    {
                        //если группа And является вторичной по отношению к группе Or [например ((X and Y) or Z)]
                        if (andGroupStats[fp.AndGroupName] < orGroupStats[fp.OrGroupName])
                        {
                            columnNameWithDelimiter += " and ";
                        }
                        else
                        {
                            columnNameWithDelimiter += " or ";
                        }
                    }
                    else if (string.IsNullOrEmpty(fp.OrGroupName) && !string.IsNullOrEmpty(fp.AndGroupName) && fp.AndGroupName != andGroup)
                    {
                        columnNameWithDelimiter += " ( ";
                        andGroup = fp.AndGroupName;
                    }
                    else if (string.IsNullOrEmpty(fp.OrGroupName) && !string.IsNullOrEmpty(fp.AndGroupName) && fp.AndGroupName == andGroup)
                    {
                        columnNameWithDelimiter += " and ";
                    }
                    else if (!string.IsNullOrEmpty(fp.OrGroupName) && string.IsNullOrEmpty(fp.AndGroupName) && fp.OrGroupName != orGroup)
                    {
                        columnNameWithDelimiter += " ( ";
                        orGroup = fp.OrGroupName;
                    }
                    else if (!string.IsNullOrEmpty(fp.OrGroupName) && string.IsNullOrEmpty(fp.AndGroupName) && fp.OrGroupName == orGroup)
                    {
                        columnNameWithDelimiter += " or ";
                    }

                    columnNameWithDelimiter += fp.ColumnName + " ";
                }

                if (fp.Value != null && fp.Value is IEnumerable && fp.Value.GetType() != typeof(string))
                {
                    op = OperatorType.In;
                    IEnumerable en = (IEnumerable)fp.Value;
                    if (en.GetEnumerator().MoveNext() == false)
                    {
                        continue;
                    }

                    sb.Append(columnNameWithDelimiter);
                    int inParamIndex = 0;
                    sb.Append(" in (");
                    foreach (object o in en)
                    {
                        if (inParamIndex > 0)
                        {
                            sb.Append(",");
                        }

                        bool isGuid = (o != null && o.GetType() == typeof(Guid));
                        if (isGuid)
                        {
                            sb.Append(CreateSqlLiteral(o));
                        }

                        else
                        {
                            string baseParameter = filterParameter_SqlPars[fp];
                            string arrParameter  = baseParameter + "_" + (inParamIndex + 1);
                            cmd.AddParameter(arrParameter, o);
                            sb.Append(arrParameter);
                        }

                        inParamIndex++;
                    }
                    sb.Append(")");

                    continue;
                }

                string format = "";

                if (op == OperatorType.IsFalse)
                {
                    sb.Append(columnNameWithDelimiter);
                    sb.Append("= 'false'");
                    continue;
                }

                else if (op == OperatorType.IsTrue)
                {
                    sb.Append(columnNameWithDelimiter);
                    sb.Append("= 'true'");
                    continue;
                }

                else if (op == OperatorType.IsNull)
                {
                    sb.Append(columnNameWithDelimiter);
                    sb.Append("is null");
                    continue;
                }

                else if (op == OperatorType.IsNotNull)
                {
                    sb.Append(columnNameWithDelimiter);
                    sb.Append("is not null");
                    continue;
                }

                else if (op == OperatorType.Like)
                {
                    format = "like ('%' + {0} + '%')";
                }

                else if (op == OperatorType.NotLike)
                {
                    format = "not like ('%' + {0} + '%')";
                }

                else if (op == OperatorType.StartsWith)
                {
                    format = "like ({0} + '%')";
                }

                else if (op == OperatorType.Equals)
                {
                    format = "= {0}";
                }

                else if (op == OperatorType.EqualsWithNull && fp.Value != null && fp.Value != DBNull.Value)
                {
                    format = "= {0}";
                }

                else if (op == OperatorType.EqualsWithNull && (fp.Value == null || fp.Value == DBNull.Value))
                {
                    format = "is null";
                }

                else if (op == OperatorType.NotEquals)
                {
                    format = "!= {0}";
                }

                else if (op == OperatorType.LessOrEquals)
                {
                    format = "<= {0}";
                }

                else if (op == OperatorType.MoreOrEquals)
                {
                    format = ">= {0}";
                }

                else if (op == OperatorType.LessThan)
                {
                    format = "< {0}";
                }

                else if (op == OperatorType.MoreThan)
                {
                    format = "> {0}";
                }

                if (op == OperatorType.LessOrEquals || op == OperatorType.LessThan)
                {
                    if (fp.Value is DateTime)
                    {
                        DateTime dt = (DateTime)fp.Value;
                        if (dt.Hour == 0 && dt.Minute == 0 && dt.Second == 0 && dt.Millisecond == 0)
                        {
                            fp.Value = dt.AddDays(1).AddSeconds(-1);
                        }
                    }
                }

                else if (op == OperatorType.Like)
                {
                    if (fp.Value is string)
                    {
                        fp.Value = ((string)fp.Value).Replace("[", "[[]").Replace("%", "[%]").Replace("_", "[_]");;
                    }
                }

                string parameterName = filterParameter_SqlPars[fp];
                object val           = fp.Value;
                if (val == null)
                {
                    val = DBNull.Value;
                }

                cmd.Parameters.AddWithValue(parameterName, val);
                sb.Append(columnNameWithDelimiter);
                sb.AppendFormat(format, parameterName);
            }

            if (!string.IsNullOrEmpty(orGroup))
            {
                sb.Append(" ) ");
            }
            if (!string.IsNullOrEmpty(andGroup))
            {
                sb.Append(" ) ");
            }

            if (cmd.Parameters.Count > 2100)
            {
                throw new ArgumentException("Задано слишком много параметров. Максимальное количество параметров: 2100.");
            }

            cmd.CommandText += sb.ToString();
            return(cmd);
        }
Пример #51
0
 public static int GetListCount(FilterParameterCollection filters)
 {
     return DbHelper.CreateCommand("select * from tblAddress").AddFiltering(filters).SelectCount();
 }
Пример #52
0
 public IEnumerable<object> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     return Addr.GetList(filters, pageIndex, pageSize);
 }
Пример #53
0
 public int GetIndexOf(object o, FilterParameterCollection filters, SortParameterCollection orderBy)
 {
     throw new NotImplementedException();
 }
Пример #54
0
 public IEnumerable <object> GetList(FilterParameterCollection filters, int pageIndex, int pageSize, SortParameterCollection orderBy)
 {
     return(Addr.GetList(filters, pageIndex, pageSize));
 }