public static int SaveMake(VehicleMake vehicleMaketoSave) { BrokenRuleCollection saveBrokenRules = new BrokenRuleCollection(); if (vehicleMaketoSave == null) saveBrokenRules.Add("Vehicle Make", "Invalid vehicleMake object."); else { if (string.IsNullOrEmpty(vehicleMaketoSave.VehicleMakeName)) saveBrokenRules.Add("Vehicle Make Name", "Value is Required."); } if (saveBrokenRules.Count() > 0) throw new BLLException("Validation rules failed.", saveBrokenRules); else { //check to make sure name dosent exist VehicleMake tempMake = GetMake(vehicleMaketoSave.VehicleMakeName); if (tempMake == null) return VehicleMakeDAL.Save(vehicleMaketoSave); else return tempMake.VehicleMakeId; } }
private static VehicleMake FillDataRecord(IDataRecord myDataRecord) { VehicleMake myObject = new VehicleMake(); myObject.VehicleMakeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("VehicleMakeId")); myObject.VehicleMakeName = myDataRecord.GetString(myDataRecord.GetOrdinal("VehicleMakeName")); return myObject; }
public static int Save(VehicleMake vehicleMaketoSave) { int result = 0; ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem; //check for Valid Person - if existis, UPDATE else INSERT // 10 = INSERT_ITEM //20 = UPDATE_ITEM if (vehicleMaketoSave.VehicleMakeId > 0) queryId = ExecuteTypeEnum.UpdateItem; using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString)) { using (SqlCommand myCommand = new SqlCommand("usp_ExecuteVehicleMake", myConnection)) { myCommand.CommandType = CommandType.StoredProcedure; myCommand.Parameters.AddWithValue("@QueryId", queryId); if (vehicleMaketoSave.VehicleMakeId > 0) myCommand.Parameters.AddWithValue("@VehicleMakeId", vehicleMaketoSave.VehicleMakeId); if (vehicleMaketoSave.VehicleMakeName != null) myCommand.Parameters.AddWithValue("@VehicleMakeName", vehicleMaketoSave.VehicleMakeName); //add return Output parameter to command object myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("returnValue")); myConnection.Open(); myCommand.ExecuteNonQuery(); //get return Value from stored Procedure and return ID result = (int)myCommand.Parameters["@returnValue"].Value; } myConnection.Close(); } return result; }
public static int SaveModel(string vehicleMakeName, VehicleModel vehicleModeltoSave) { BrokenRuleCollection saveBrokenRules = new BrokenRuleCollection(); if (string.IsNullOrEmpty(vehicleMakeName)) saveBrokenRules.Add("Vehicle Make Name", "Vehicle Model must be associated with a valid Vehicle Make Name."); if (vehicleModeltoSave == null) saveBrokenRules.Add("Vehicle Model", "Invaild VehicleModel object."); else { if (string.IsNullOrEmpty(vehicleModeltoSave.VehicleModelName)) saveBrokenRules.Add("Vehicle Make Name", "Value is Required."); } if (saveBrokenRules.Count() > 0) throw new BLLException("Validation rules failed.", saveBrokenRules); else { //check to make sure name dosent exist VehicleMake itemMake = GetMake(vehicleMakeName); if (itemMake == null) { itemMake = new VehicleMake(); itemMake.VehicleMakeId = SaveMake(new VehicleMake{VehicleMakeName = vehicleMakeName}); } vehicleModeltoSave.Make = itemMake; return VehicleModelDAL.Save(vehicleModeltoSave); } }
private static VehicleModel FillDataRecord(IDataRecord myDataRecord) { VehicleModel myObject = new VehicleModel(); myObject.VehicleModelId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("VehicleModelId")); myObject.VehicleModelName = myDataRecord.GetString(myDataRecord.GetOrdinal("VehicleModelName")); VehicleMake vehicleMake = new VehicleMake(); vehicleMake.VehicleMakeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("VehicleMakeId")); if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("VehicleMakeName"))) vehicleMake.VehicleMakeName = myDataRecord.GetString(myDataRecord.GetOrdinal("VehicleMakeName")); myObject.Make = vehicleMake; return myObject; }