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 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 void Delete(EMVehicleInUserGroup entity) { string sql = string.Format(@"delete from movo_vehicle_usergroup where VehicleCode='{0}' and UserGroupID={1};", entity.VehicleCode, entity.UserGroupID); MySqlDB.ExecuteNonQuery(CommandType.Text, sql); }
private EMVehicleInUserGroup ConvertInfo(DataRow row) { if (row == null) { return null; } EMVehicleInUserGroup info = new EMVehicleInUserGroup(); info.UserGroupID = System.Convert.ToUInt64(row["UserGroupID"]); info.VehicleCode = new Guid(row["VehicleCode"].ToString()); info.LicenceNumber = row["LicenceNumber"].ToString(); return info; }
public void Insert(EMVehicleInUserGroup entity) { string sql = string.Format(@"INSERT INTO movo_vehicle_usergroup (`VehicleCode`, `UserGroupID`) VALUES ('{0}',{1});", entity.VehicleCode, entity.UserGroupID); MySqlDB.ExecuteNonQuery(CommandType.Text, sql); }