Exemplo n.º 1
0
        public async Task <ActionResult> GetAllTimes([FromQuery] ParametersPage parametersPage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                var back = await _timeAppService.GetAll(parametersPage);

                var result   = _mapper.MapList <TimeEntity, TimeViewModel>(back);
                var metadata = new
                {
                    result.TotalCount,
                    result.PageSize,
                    result.CurrentPage,
                    result.TotalPages,
                    result.HasNext,
                    result.HasPrevious
                };

                Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));
                return(Ok(result));
            }
            catch (ArgumentException ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemplo n.º 2
0
        public IActionResult Load()
        {
            try
            {
                var draw = HttpContext.Request.Form["draw"].FirstOrDefault();
                // Skiping number of Rows count
                var start = Request.Form["start"].FirstOrDefault();
                // Paging Length 10,20
                var length = Request.Form["length"].FirstOrDefault();
                // Sort Column Name
                var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();
                // Sort Column Direction ( asc ,desc)
                var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();
                // Search Value from (Search box)
                var searchValue = Request.Form["search[value]"].FirstOrDefault().ToLower();

                //Paging Size (10,20,50,100)
                int pageSize = length != null?Convert.ToInt32(length) : 0;

                int skip = start != null?Convert.ToInt32(start) : 0;

                int recordsTotal = 0;

                // Getting all Customer data
                var times        = _timeAppService.GetAll();
                var result       = times.Select(x => TimeViewModel.ToViewModel(x));
                var customerData = result;

                sortColumn = sortColumn.Equals("Id") || string.IsNullOrEmpty(sortColumn) ? "Nome" : sortColumn;
                var prop = ClassUtil.GetProperty <TimeViewModel>(sortColumn);
                if (sortColumnDirection == "asc")
                {
                    customerData = customerData.OrderBy(prop.GetValue);
                }
                else
                {
                    customerData = customerData.OrderByDescending(prop.GetValue);
                }

                //Search
                if (!string.IsNullOrEmpty(searchValue))
                {
                    customerData = customerData.Where(m => m.Nome.ToLower().Contains(searchValue) || m.Sigla.ToLower().Contains(searchValue));
                }

                //total number of rows count
                recordsTotal = customerData.Count();
                //Paging
                var data = customerData.Skip(skip).Take(pageSize).ToList();
                //Returning Json Data
                return(Json(new { draw, recordsFiltered = recordsTotal, recordsTotal, data }));
            }
            catch (Exception)
            {
                throw;
            }
        }
 private IList <string> CarregarTimes()
 {
     return(_timeAppService.GetAll().OrderBy(x => x.Nome).Select(x => x.Nome).ToList());
 }