예제 #1
0
        private async Task <IActionResult> GridDataSource <T>([FromBody] DataManagerRequest dm, int id, DateTime beginDate, DateTime endDate, RateValueType rate)
            where T : IApplication
        {
            var app =
                (await _manager.GetApplicationsAsync())
                .FirstOrDefault(a => a.Id == id);

            if (app is null)
            {
                app = await _manager.GetNewApplication();

                app.BeginDate = beginDate;
                app.EndDate   = endDate;
                app.Rate      = new Rate {
                    Type = rate
                };
            }

            IEnumerable dataSource = null;

            if (typeof(T) == typeof(RsApplication))
            {
                dataSource = await _manager.GetCrossingGridDataAsync(app);

                foreach (RsApplication application in dataSource)
                {
                    application.RsApplicationLink = $"<a href='{Url.RouteUrl(new { controller = "Home", action = "Form", number = application.Number })}' target='_blank'>{application.Number}</a>";
                }
            }
            else if (typeof(T) == typeof(AmRateApplication))
            {
                dataSource = await _manager.GetAmRateApplicationsAsync(app);
            }
            else if (typeof(T) == typeof(AmOzsApplication))
            {
                dataSource = await _manager.GetAmOzsApplicationsAsync(app);
            }

            var operation = new DataOperations();

            if (dm.Search != null && dm.Search.Count > 0)
            {
                dataSource = operation.PerformSearching(dataSource, dm.Search);  //Search
            }

            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
            {
                dataSource = operation.PerformSorting(dataSource, dm.Sorted);
            }

            if (dm.Where != null && dm.Where.Count > 0) //Filtering
            {
                const string @operator = "contains";

                foreach (var whereFilter in dm.Where)
                {
                    whereFilter.Operator = @operator;

                    foreach (var whereFilterPredicate in whereFilter.predicates)
                    {
                        whereFilterPredicate.Operator = @operator;
                    }
                }

                dataSource = operation.PerformFiltering(dataSource, dm.Where, @operator);
            }

            var count = dataSource.OfType <object>().Count();

            if (dm.Skip != 0)
            {
                dataSource = operation.PerformSkip(dataSource, dm.Skip);   //Paging
            }

            if (dm.Take != 0)
            {
                dataSource = operation.PerformTake(dataSource, dm.Take);
            }

            return(dm.RequiresCounts
                ? Json(new { result = dataSource, count = count })
                : Json(dataSource));
        }
예제 #2
0
        public async Task <IActionResult> Form(string number, DateTime beginDate, DateTime endDate, RateValueType rate)
        {
            var year = DateTime.Now.Year;

            var minDate = new DateTime(year, 1, 1);
            var maxDate = new DateTime(year, 12, 31);

            if (beginDate < minDate)
            {
                beginDate = minDate;
            }

            if (endDate < minDate)
            {
                endDate = minDate;
            }

            if (endDate > maxDate)
            {
                endDate = maxDate;
            }

            if (beginDate > endDate)
            {
                beginDate = endDate;
            }

            var app =
                (await _manager.GetApplicationsAsync())
                .FirstOrDefault(a => a.Number == number);

            if (app is null)
            {
                app = await _manager.GetNewApplication();

                app.BeginDate = beginDate;
                app.EndDate   = endDate;
                app.Rate      = new Rate {
                    Type = rate
                };
            }
            else
            {
                ViewBag.CommentsGridDataSource = await _manager.GetCommentsAsync();
            }

            await SetChartData(app);
            await SetFormData();

            return(View(app));
        }
예제 #3
0
 public async Task <IActionResult> AmOzsGridDataSource([FromBody] DataManagerRequest dm, int id, DateTime beginDate, DateTime endDate, RateValueType rate)
 {
     return(await GridDataSource <AmOzsApplication>(dm, id, beginDate, endDate, rate));
 }