コード例 #1
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        public int RegisterPermit(Permit permit)
        {
            //Register a new vehicle (create a new permit)
            int id = 0;

            try {
                //Apply simple business rules
                Permit p = ValidatePermitNumber(permit.Number);
                if (p != null)
                {
                    throw new ApplicationException("There is an existing permit in the system for permit # " + permit.Number + ".");
                }

                p = ValidateVehicle(permit.Vehicle.IssueState, permit.Vehicle.PlateNumber);
                if (p != null)
                {
                    throw new ApplicationException("There is an active permit in the system with license plate " + permit.Vehicle.IssueState + " " + permit.Vehicle.PlateNumber + ".");
                }

                //Execute the business transcation
                using (TransactionScope scope = new TransactionScope()) {
                    //Creaet the vehicle, then the permit
                    permit.VehicleID = new PermitGateway().CreateVehicle(permit.Vehicle);
                    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);
        }
コード例 #2
0
        public DataSet FindPermitsByVehicle(string year, string make, string model, string color)
        {
            //Find a permit; can return more than one object??
            DataSet permits = null;

            try {
                permits = new PermitGateway().FindPermitsByVehicle(year, make, model, color);
            }
            catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); }
            return(permits);
        }
コード例 #3
0
        public DataSet FindPermitsByPlate(string issueState, string plateNumber)
        {
            //Find a permit; can return more than one object??
            DataSet permits = null;

            try {
                permits = new PermitGateway().FindPermitsByPlate(issueState, plateNumber);
            }
            catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); }
            return(permits);
        }
コード例 #4
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        public bool ChangeVehicle(Vehicle vehicle)
        {
            //Change license plate or veicle or contact
            bool changed = false;

            try {
                changed = new PermitGateway().UpdateVehicle(vehicle);
            }
            catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); }
            return(changed);
        }
コード例 #5
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        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);
        }
コード例 #6
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        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);
        }
コード例 #7
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        public DataSet ViewPermits()
        {
            //
            DataSet permits = new DataSet();

            try {
                DataSet ds = new PermitGateway().ViewPermits();
                if (ds != null)
                {
                    permits.Merge(ds);
                }
            }
            catch (Exception ex) { throw new FaultException <HRFault>(new HRFault(ex.Message), "Service Error"); }
            return(permits);
        }
コード例 #8
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        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);
        }
コード例 #9
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        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);
        }
コード例 #10
0
ファイル: PermitService.cs プロジェクト: jpheary/Argix10
        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);
        }