示例#1
0
        public async Task <BaseResponse> UpdateDeviceAsync(string account, string GroupId, DeviceUpdateViewModel req)
        {
            var device = await _dr.FindAsync(req.DeviceSn);

            try
            {
                var dto = _mapper.Map(req, device);
                dto.Modify     = account;
                dto.ModifyTime = DateTime.Now;
                await _dr.SaveAsync(dto);

                _log.LogInformation($"{account}修改标识为{req.DeviceSn}的设备成功");
                return(new BaseResponse {
                    Success = true, Message = "修改设备数据成功"
                });
            }
            catch (Exception ex)
            {
                _log.LogError($"{account}修改标识为{req.DeviceSn}的设备失败,失败原因:{ex.Message}->{ex.StackTrace}->{ex.InnerException}");
                return(new BaseResponse {
                    Success = false, Message = "修改设备数据失败,请联系管理员"
                });
            }
        }
示例#2
0
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     Load_DetailedInfo();
     DataContext = new DeviceUpdateViewModel(SerialNumber);
 }
示例#3
0
        public async Task <ActionResult <BaseResponse> > UpdateDevice(string GroupId, DeviceUpdateViewModel req)
        {
            var    GId     = User.Claims.FirstOrDefault(a => a.Type == "GroupId").Value;
            var    isAdmin = User.Claims.FirstOrDefault(a => a.Type == "IsAdmin").Value.ToLower() == "true" ? true : false;
            string Code    = User.Claims.FirstOrDefault(a => a.Type == "Code").Value;
            string Account = User.Claims.FirstOrDefault(a => a.Type == "Account").Value;
            string Roles   = User.Claims.FirstOrDefault(a => a.Type == "Role").Value;
            //验证设备是否存在
            var dto = await _ds.IsExistCheck(a => a.DeviceSn == req.DeviceSn && a.GroupId == GroupId);

            if (!dto.IsExist)
            {
                return(new BaseResponse {
                    Success = false, Message = "该组织下不存在该设备"
                });
            }
            //验证权限
            #region
            if (dto.ProjectId.HasValue) //不是无项目的设备
            {
                if (GroupId != GId)
                {
                    if (!(isAdmin && Code == _config["Group"]))
                    {
                        return(new BaseResponse {
                            Success = false, Message = "用户没有权限修改其它组织设备的权限"
                        });
                    }
                }
                else
                {
                    if (!isAdmin)
                    {
                        var bAuth = await _rp.IsAuth(Roles, dto.PathId, 2);//是否有权限编辑

                        if (!bAuth)
                        {
                            return(new BaseResponse {
                                Success = false, Message = "用户没有权限修改设备"
                            });
                        }
                    }
                }
            }
            else
            {
                if (!(isAdmin && (GroupId == GId || Code == _config["Group"])))
                {
                    return(new BaseResponse {
                        Success = false, Message = "用户没有权限操作无项目的设备"
                    });
                }
            }
            #endregion
            var rm = await _ds.UpdateDeviceAsync(Account, GroupId, req);

            return(rm);
        }