示例#1
0
        public override RoboUIGridRequest CreateGridRequest(ControllerContext controllerContext)
        {
            var result  = new RoboUIGridRequest();
            var request = controllerContext.HttpContext.Request;

            var page = request.Form["page"];

            if (page.Count > 0)
            {
                result.PageIndex = Convert.ToInt32(page);
            }

            var pageSize = request.Form["pageSize"];

            if (pageSize.Count > 0)
            {
                result.PageSize = Convert.ToInt32(pageSize);
            }

            var sort = (string)request.Form["sort"];

            if (!string.IsNullOrEmpty(sort))
            {
                result.Sorts = GridDescriptorSerializer.Deserialize <SortDescriptor>(sort);
            }

            var value = (string)request.Form["filter"];

            if (!string.IsNullOrEmpty(value))
            {
                // Process [today], [beginWeek], [endWeek], [beginMonth], [endMonth], [beginPrevMonth] tokens
                var dtNow = DateTime.UtcNow.Date;
                int startIndex;
                var endIndex = 0;
                while ((startIndex = value.IndexOf("[today", endIndex, StringComparison.Ordinal)) != -1)
                {
                    endIndex = value.IndexOf("]", startIndex, StringComparison.Ordinal);
                    var days = value.Substring(startIndex + 6, endIndex - startIndex - 6);
                    value = value.Replace("[today" + days + "]", dtNow.AddDays(Convert.ToInt32(days)).ToString("O"));
                }

                //value = value.Replace("[beginWeek]", dtNow.StartOfWeek(DayOfWeek.Monday).ToString("O"));
                //value = value.Replace("[endWeek]", dtNow.EndOfWeek(DayOfWeek.Sunday).AddDays(1).ToString("O"));
                value = value.Replace("[beginMonth]", new DateTime(dtNow.Year, dtNow.Month, 1, 0, 0, 0, DateTimeKind.Utc).ToString("O"));
                value = value.Replace("[endMonth]", dtNow.Month == 12
                    ? new DateTime(dtNow.Year + 1, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("O")
                    : new DateTime(dtNow.Year, dtNow.Month + 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("O"));
                value = value.Replace("[beginPrevMonth]", new DateTime(dtNow.Year, dtNow.Month == 1 ? 12 : dtNow.Month - 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("O"));
                value = value.Replace("[beginYear]", new DateTime(dtNow.Year, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("O"));
                value = value.Replace("[endYear]", new DateTime(dtNow.Year + 1, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToString("O"));

                result.Filters = FilterDescriptorFactory.Create(value);
            }

            return(result);
        }
示例#2
0
        public override async Task ExecuteGridRequest <TModel>(RoboUIGridResult <TModel> roboUIGrid, RoboUIGridRequest request,
                                                               ControllerContext controllerContext)
        {
            var formProvider = roboUIGrid.RoboUIFormProvider ?? RoboUI.DefaultRoboUIFormProvider;

            var response = controllerContext.HttpContext.Response;

            response.ContentType = "application/json";

            var data = await roboUIGrid.FetchAjaxSource(request);

            await WriteJsonData(response, data,
                                data.TotalRecords > 0?data.TotalRecords : data.Count,
                                formProvider,
                                roboUIGrid.Columns.Select(x => (RoboUIGridColumn)x).ToList(),
                                roboUIGrid.RowActions.Count > 0 && !roboUIGrid.HideActionsColumn
                                ?roboUIGrid.RowActions.Select(x => (IRoboUIGridRowAction)x).ToList()
                                    : new List <IRoboUIGridRowAction>(),
                                    roboUIGrid.GetModelId, roboUIGrid.Editable);
        }
示例#3
0
 public abstract Task ExecuteGridRequest <TModel>(RoboUIGridResult <TModel> roboUIGrid, RoboUIGridRequest request, ControllerContext controllerContext) where TModel : class;