示例#1
0
        public async Task <IActionResult> MapList(MapDeviceSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageDevices))
            {
                return(AccessDeniedKendoGridJson());
            }

            var model = await _deviceModelFactory.PrepareMapDeviceListingModel(searchModel);

            return(Json(model));
        }
 public DeviceTrackingContainerModel()
 {
     DeviceMap     = new DeviceModel();
     DeviceListing = new MapDeviceSearchModel();
 }
示例#3
0
        public async Task <MapDeviceListModel> PrepareMapDeviceListingModel(MapDeviceSearchModel searchModel)
        {
            double distance = 0;

            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            var mapList = await _deviceService.GetAllDevicesAsync();

            if (mapList == null)
            {
                throw new ArgumentNullException(nameof(mapList));
            }

            var model = new MapDeviceListModel
            {
                Data = mapList.PaginationByRequestModel(searchModel).Select(mapLst =>
                {
                    var mapListModel       = mapLst.ToModel <MapDeviceModel>();
                    mapListModel.StoreName = mapLst.Store.P_BranchNo + " - " + mapLst.Store.P_Name;

                    if (mapLst.Store != null && mapLst.Store.Latitude != null && mapLst.Store.Longitude != null)
                    {
                        distance = getDistance(mapLst.Latitude, mapLst.Longitude, (double)mapLst.Store.Latitude, (double)mapLst.Store.Longitude) / 1000; //returns in KM
                    }
                    else
                    {
                        distance = getDistance(mapLst.Latitude, mapLst.Longitude, 0, 0) / 1000; //returns in KM
                    }

                    if (distance > Convert.ToDouble(_configuration["OutofRadarRadius"]))
                    {
                        mapLst.Status = "2";
                    }

                    mapListModel.Status = (mapLst.Status == null || mapLst.Status == "0") ? "Offline" : mapLst.Status == "1" ? "Online" : mapLst.Status == "2" ? "Out of radar" : "N/A";

                    return(mapListModel);
                }),
                Total = mapList.Count
            };

            // sort
            if (searchModel.Sort != null && searchModel.Sort.Any())
            {
                foreach (var s in searchModel.Sort)
                {
                    model.Data = await model.Data.Sort(s.Field, s.Dir);
                }
            }

            // filter
            if (searchModel.Filter != null && searchModel.Filter.Filters != null && searchModel.Filter.Filters.Any())
            {
                var filter = searchModel.Filter;
                model.Data = await model.Data.Filter(filter);

                model.Total = model.Data.Count();
            }

            return(model);
        }