Ejemplo n.º 1
0
        // Methods for adding/removing reports
        public virtual void AddReport(Employee newReport)
        {
            // Do nothing if adding a null newReport
            if (newReport == null)
            {
                return;
            }

            // Local to hold error string, if found
            string errorString = null;

            // Check number of reports
            if (_reports.Count >= MaxReports)
            {
                errorString = string.Format("Manager already has {0} reports.", MaxReports);
            }
            else if (_reports.IndexOf(newReport) >= 0)
            {
                errorString = "Employee already reports to manager";
            }
            else if (this == newReport)
            {
                errorString = "Manager can not report to himself/herself";
            }

            // Create an exception if we found an error
            if (errorString != null)
            {
                Exception ex = new AddReportException(errorString);

                // Add Manager custom data dictionary
                ex.Data.Add("Manager", this.Name);

                // Also add report that failed to be added, and throw exception
                ex.Data.Add("New Report", newReport.Name);
                throw ex;
            }

            // Only add report if not already a report and not same as this
            else
            {
                // Put Employee in empty position
                _reports.Add(newReport);
            }
        }
        // Methods for adding reports
        public override void AddReport(Employee newReport)
        {
            // Check for proper report to Executive
            if (newReport is Manager || newReport is SalesPerson)
            {
                base.AddReport(newReport);
            }
            else
            {
                // Raise exception for report that is not a Manager or Salesperson
                Exception ex = new AddReportException("Executive report not a Manager or Salesperson");

                // Add Manager custom data dictionary
                ex.Data.Add("Manager", this.Name);

                // Add report that failed to be added, and throw exception
                ex.Data.Add("New Report", newReport.Name);
                throw ex;
            }
        }