Example #1
0
        public void SelectWithOrderBy()
        {
            Configuration.SetDialect(new TestDialect());
            SetModeling();
            var b = new SelectBuilder();

            b.From <DeliveryNote>();
            b.OrderBy <DeliveryNote>(OrderByDirection.Desc, i => i.Date);
            b.OrderBy <DeliveryNote>(i => i.Year, i => i.SupplierId);

            var gen  = b.GetSqlText();
            var spec = "SELECT * FROM [WH].[DeliveryNote] AS [T0] ORDER BY [T0].[Date] DESC, [T0].[Year] ASC, [T0].[SupplierId] ASC";

            Assert.Equal(spec, gen);
        }
Example #2
0
        public IActionResult Get(int limit, int year, int?month, int?day,
                                 [FromQuery(Name = "filters")] List <Dictionary <string, string> > filters,
                                 [FromQuery(Name = "order[]")] string[] order)
        {
            var path = _config.GetValue <string>("LogPath");
            var file = String.Format("u_ex{0}{1}{2}.log", year % 100, month?.ToString("00") ?? "??", day?.ToString("00") ?? "??");

            if (Directory.GetFiles(path, file).Length == 0)
            {
                return(BadRequest("No log files"));
            }

            var sb = new SelectBuilder()
                     .Select($"TOP {limit} *")
                     .From(Path.Combine(path, file))
                     .Where("1 = 1");

            foreach (var dict in filters)
            {
                var value = "'" + (dict["condition"].Contains("LIKE") ? "%" + dict["value"] + "%" : dict["value"]) + "'";
                sb.And(String.Concat(dict["field"], " ", dict["condition"], " ", value));
            }

            sb.OrderBy(order);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(Ok(GetData(sb.Build())));
            }
            else
            {
                return(StatusCode(StatusCodes.Status501NotImplemented));
            }
        }