public DBProcessResult DeleteUserGroup(ulong userGroupID) { DBProcessResult result = new DBProcessResult(); try { if (AnyUserInGroup(userGroupID)) { result.IsSuccess = false; result.Message = "用户组下有用户,不能删除,请先转移或删除用户!"; return result; } IMUserGroupService userGroupSev = new MUserGroupService(); IEMVehicleInUserGroupService viuSev = new EMVehicleInUserGroupService(); //删除用户组 userGroupSev.Delete(userGroupID); //删除旧车辆与用户组的关系,并新增关系 viuSev.DeleteByUserGroupID(userGroupID); result.IsSuccess = true; } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; Logger.Error(ex.Message, ex); } return result; }
public DBProcessResult UpdateUserGruop(EMUserGroupWithVehiclesViewModel viewModel) { DBProcessResult result = new DBProcessResult(); try { IMUserGroupService userGroupSev = new MUserGroupService(); bool isExists = userGroupSev.IsExist(viewModel.UserGourpView.UserGroupName, viewModel.UserGourpView.UserGroupID, viewModel.UserGourpView.TenantCode); if (isExists) { result.IsSuccess = false; result.Message = "用户组名已经存在"; return result; } IEMVehicleInUserGroupService viuSev = new EMVehicleInUserGroupService(); //修改用户组 EMUserGroup entity = ConvertHelper.ConvertObj<EMUserGroupViewModel, EMUserGroup>(viewModel.UserGourpView); userGroupSev.Update(entity); //删除旧车辆与用户组的关系,并新增关系 viuSev.DeleteByUserGroupID(entity.UserGroupID); List<EMVehicleInUserGroup> vehicleList = new List<EMVehicleInUserGroup>(); foreach (EMVehicleInUserGroupViewModel vehicleView in viewModel.Vehicles) { EMVehicleInUserGroup vehicle = new EMVehicleInUserGroup(); vehicle.UserGroupID = entity.UserGroupID; vehicle.VehicleCode = vehicleView.VehicleCode; vehicleList.Add(vehicle); } viuSev.Insert(vehicleList); result.IsSuccess = true; } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; Logger.Error(ex.Message, ex); } return result; }
public EMUserGroupWithVehiclesViewModel GetUserGruopWithVehicles(ulong userGroupID) { EMUserGroupWithVehiclesViewModel uvView = new EMUserGroupWithVehiclesViewModel(); try { IMUserGroupService userGroup = new MUserGroupService(); IEMVehicleInUserGroupService viugSev = new EMVehicleInUserGroupService(); EMUserGroup ugEntity = userGroup.Get(userGroupID); uvView.UserGourpView = ConvertHelper.ConvertObj<EMUserGroup, EMUserGroupViewModel>(ugEntity); List<EMVehicleInUserGroup> vehicleList = viugSev.SelectByUserGroupID(userGroupID).ToList(); uvView.Vehicles = ConvertHelper.ConvertList<EMVehicleInUserGroup, EMVehicleInUserGroupViewModel>(vehicleList); return uvView; } catch (Exception ex) { Logger.Error(ex.Message, ex); return null; } }
public DBProcessResult<EMUserGroupViewModel> InsertUserGruop(EMUserGroupWithVehiclesViewModel viewModel) { DBProcessResult<EMUserGroupViewModel> result = new DBProcessResult<EMUserGroupViewModel>(); try { IMUserGroupService userGroupSev = new MUserGroupService(); bool isExists = userGroupSev.IsExist(viewModel.UserGourpView.UserGroupName , viewModel.UserGourpView.TenantCode); if (isExists) { result.IsSuccess = false; result.Message = "用户组名已经存在"; return result; } IdentityNoService codeSec = new IdentityNoService(); IEMVehicleInUserGroupService viuSev = new EMVehicleInUserGroupService(); //新增用户组 viewModel.UserGourpView.UserGroupID = codeSec.GetUserGroupID(); EMUserGroup entity = ConvertHelper.ConvertObj<EMUserGroupViewModel, EMUserGroup>(viewModel.UserGourpView); userGroupSev.Add(entity); //新增车辆与用户组的关系 List<EMVehicleInUserGroup> vehicleList = new List<EMVehicleInUserGroup>(); foreach (EMVehicleInUserGroupViewModel vehicleView in viewModel.Vehicles) { EMVehicleInUserGroup vehicle = new EMVehicleInUserGroup(); vehicle.UserGroupID = entity.UserGroupID; vehicle.VehicleCode = vehicleView.VehicleCode; vehicleList.Add(vehicle); } viuSev.Insert(vehicleList); result.IsSuccess = true; result.ReturnValue = viewModel.UserGourpView; } catch (Exception ex) { result.IsSuccess = false; result.Message = ex.Message; Logger.Error(ex.Message, ex); } return result; }
public DBProcessResult TransferVehicle(string vehicleCode, string newTenantCode) { DBProcessResult result = new DBProcessResult(); try { //查询新客户的默认车辆组 EMVehicleGroupService VGSev = new EMVehicleGroupService(); ulong newVehicleGroupID = VGSev.GetTopGroupID(newTenantCode); EMVehicleService VSev = new EMVehicleService(); EMVehicle vehicle = VSev.Select(new Guid(vehicleCode)); //更新车辆的车辆组和Tenantcode vehicle.GroupID = newVehicleGroupID; vehicle.TenantCode = newTenantCode; VSev.Update(vehicle); //将车辆从旧的车辆和用户组关系中删除 EMVehicleInUserGroupService VIUSev = new EMVehicleInUserGroupService(); VIUSev.DeleteByVehicleCode(vehicleCode); //删除车辆报警参数设置 MySqlHelper.TransCommand(getCmdTextList(vehicleCode)); result.IsSuccess = true; result.Message = "转移车辆成功!"; } catch { result.IsSuccess = false; result.Message = "转移车辆失败!"; } return result; }