예제 #1
0
        public IActionResult PostFilter([FromBody] FilterViewModel vmdl)
        {
            try
            {
                vmdl.OrderBy = vmdl.OrderBy ?? "Name";
                vmdl.Order   = vmdl.Order ?? "ASC";

                var b = vmdl.FilteredList(_bl)
                        .ToList()
                        .Select(i =>
                {
                    var newDeviceViewModel   = new DeviceViewModel(i).LoadMeta(i);
                    newDeviceViewModel.Stock = _bl.GetDevices().ToList().Where(j => j.Status.Description == "Verfügbar")
                                               .Count(j => j.DeviceGroupSlug == newDeviceViewModel.DeviceGroupSlug);
                    return(newDeviceViewModel);
                })
                        .ToList();
                var count = b.Count;
                b = vmdl.Limit < 0
                    ? b.ToList()
                    : b.Skip(vmdl.Offset).Take(vmdl.Limit).ToList();

                return(Ok(new DeviceListViewModel(b, vmdl.Limit, count)));
            }
            catch (SecurityException)
            {
                _log.LogWarning("'{0}' tried to list Devices as Admin/Verwalter", _bl.GetCurrentUid());
                return(Unauthorized());
            }
            catch (Exception ex)
            {
                _log.LogError("Exception: {0}", ex);
                return(StatusCode(500));
            }
        }