public async Task <IActionResult> UpdateDeviceType(int id, DeviceTypeUpdateDto deviceTypeUpdateDto) { var deviceType = await _deviceTypeService.GetDeviceTypeByIdAsync(id); if (deviceType == null) { return(NotFound()); } if (deviceTypeUpdateDto.ParentId == null) { deviceTypeUpdateDto.ParentId = deviceType.ParentId; } _mapper.Map(deviceTypeUpdateDto, deviceType); if (await _deviceTypeService.UpdateDeviceTypeAsync(deviceType)) { return(NoContent()); } throw new Exception($"Updating device type {id} failed to save"); }
public async Task <ActionResult <BaseResponse> > UpdateDeviceType(string GroupId, DeviceTypeUpdateDto 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 = "该组织下不存在该设备" }); } //验证设备类型是否存在 var type = await _ts.CheckTypeAsync(req.TypeId); if (!type.IsExist) { return(new BaseResponse { Success = false, Message = "输入的类型不存在,请确认" }); } else if (type.Status == 0) { 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.UpdateDeviceTypeAsync(Account, req.DeviceSn, req.TypeId); return(rm); }