Пример #1
0
        /// <summary>
        /// 监控页面的获取设备列表
        /// </summary>
        /// <param name="pi"></param>
        /// <param name="pc"></param>
        /// <returns></returns>
        public JsonResult AjaxGetMonitorList(int pi, int pc)
        {
            List <DeviceAndUser> dus = DeviceLogic.GetDeviceList(AuthUser.UserTypeId.Value, AuthUser.Id, pi, pc);
            string deviceIds         = "";

            foreach (var du in dus)
            {
                deviceIds += du.APIDeviceId + ",";
            }
            deviceIds = deviceIds.TrimEnd(',');
            DeviceListModel  list = DeviceData.GetDeviceList(deviceIds, pi, pc);
            DeviceListResult res  = new DeviceListResult();

            res.Items = new List <DeviceInfo>();
            if (list.Items.Count > 0)
            {
                list.Items.ForEach(p =>
                {
                    DeviceAndUser du = dus.FirstOrDefault(t => t.APIDeviceId == p.Id);
                    if (du != null)
                    {
                        DeviceInfo di    = new DeviceInfo();
                        di.Id            = du.DeviceId;
                        di.APIId         = du.APIDeviceId ?? 0;
                        di.Battery       = p.Battery;
                        di.Icon          = du.IconId ?? 0;
                        di.Model         = p.Model;
                        di.IMEI          = du.Imei;
                        di.Latitude      = Convert.ToDecimal(WebHelper.GetLatLngString(p.Latitude));
                        di.Longitude     = Convert.ToDecimal(WebHelper.GetLatLngString(p.Longitude));
                        di.ServerUtcDate = p.ServerUtcDate.AddHours(8);
                        di.DeviceUtcDate = p.DeviceUtcDate.AddHours(8);
                        di.Type          = p.Type;
                        di.Sim           = p.Sim;
                        di.Status        = p.Status;
                        if (DateTime.Now.AddMinutes(-15) < di.ServerUtcDate)
                        {
                            di.Status = 2;
                        }

                        di.UserId   = du.UserId;
                        di.UserName = string.IsNullOrWhiteSpace(du.UserName) ? du.LoginName : du.UserName;
                        di.Sex      = du.Sex ?? 2;
                        res.Items.Add(di);
                    }
                });
            }
            else
            {
                res.State   = State.Falid;
                res.Message = list.Message;
            }
            return(Json(res));
        }
Пример #2
0
        public async Task <bool> Create(Guid clientId, Guid serialNumber)
        {
            var listDevices = new List <Device>();

            listDevices.Add(new Device {
                SirialNumber = serialNumber
            });
            var user = new DeviceAndUser {
                UserId = clientId, DeviceId = listDevices
            };

            await _context.DeviceAndUsers.AddAsync(user);

            await SaveAsync();

            return(true);
        }