public bool RevokePermit(Permit permit) { //Revoke a permit: change the permit to inactive bool revoked = false; try { revoked = new PermitGateway().UpdatePermit(permit); } catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); } return(revoked); }
public Permit ReadPermit(int id) { //Read an existing permit Permit permit = null; try { DataSet ds = new PermitGateway().ReadPermit(id); if (ds != null && ds.Tables["PermitTable"] != null && ds.Tables["PermitTable"].Rows.Count > 0) { permit = new Permit(ds.Tables["PermitTable"].Rows[0]); } } catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); } return(permit); }
public bool UpdatePermit(Permit permit) { //Update an existing permit bool updated = false; try { updated = new DataService().ExecuteNonQuery(SQL_CONNID, USP_PERMIT_UPDATE, new object[] { permit.ID, permit.Inactivated, permit.InactivatedBy, permit.InactivatedReason, permit.Updated, permit.UpdatedBy }); } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } return(updated); }
public Permit ValidatePermitNumber(string number) { //Validate the specified number does not exist in the system //Return the permit if it does Permit permit = null; try { DataSet ds = new PermitGateway().ReadPermit(number); if (ds != null && ds.Tables["PermitTable"] != null && ds.Tables["PermitTable"].Rows.Count > 0) { permit = new Permit(ds.Tables["PermitTable"].Rows[0]); } } catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); } return(permit); }
public int CreatePermit(Permit permit) { //Create a new permit int id = 0; try { id = (int)new DataService().ExecuteNonQueryWithReturn(SQL_CONNID, USP_PERMIT_CREATE, new object[] { null, permit.Number, permit.VehicleID, permit.Activated, permit.ActivatedBy, permit.Updated, permit.UpdatedBy }); } catch (Exception ex) { throw new ApplicationException(ex.Message, ex); } return(id); }
public Permit ValidateVehicle(string issueState, string plateNumber) { //Validate the specified vehicle does not exist in the system with an "active" permit //Return the active permit if it does Permit permit = null; try { DataSet ds = new PermitGateway().ReadPermit(issueState, plateNumber); if (ds != null && ds.Tables["PermitTable"] != null && ds.Tables["PermitTable"].Rows.Count > 0) { DataSet dss = new DataSet(); dss.Merge(ds.Tables["PermitTable"].Select("Inactivated is null")); if (dss.Tables["PermitTable"] != null && dss.Tables["PermitTable"].Rows.Count > 0) { permit = new Permit(dss.Tables["PermitTable"].Rows[0]); } } } catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); } return(permit); }
public int ReplacePermit(Permit permit, string newNumber) { //Replace a lost/stolen/damaged permit int id = 0; try { //Apply simple business rules Permit p = ValidatePermitNumber(newNumber); if (p != null) { throw new ApplicationException("There is an existing permit in the system for permit # " + newNumber + "."); } //Execute the business transcation using (TransactionScope scope = new TransactionScope()) { //Inactivate the current one and create a new one //Current permit should have Inactivated, InactivatedBy, and InactivatedReason set bool inactivated = new PermitGateway().UpdatePermit(permit); if (inactivated) { //Overwrite the permit number on the current permit and create a new one permit.ID = 0; permit.Number = newNumber; permit.Activated = permit.Updated; permit.ActivatedBy = permit.UpdatedBy; permit.Inactivated = DateTime.MinValue; permit.InactivatedBy = ""; permit.InactivatedReason = ""; id = new PermitGateway().CreatePermit(permit); } //Commit the transaction scope.Complete(); } } catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); } return(id); }