コード例 #1
0
        public ReportingStructure getReportingStructureById(String id)
        {
            Employee           employee           = _employeeRepository.GetById(id);
            ReportingStructure reportingStructure = new ReportingStructure();

            reportingStructure.Employee = employee;
            int count = 0;

            if (employee != null)
            {
                List <Employee> directreports = employee.DirectReports;
                if (directreports != null)
                {
                    for (int i = 0; i < directreports.Count; i++)

                    {
                        Employee report = directreports[i];
                        if (report != null)
                        {
                            count = count + 1;
                            if (report.DirectReports != null)
                            {
                                directreports.AddRange(report.DirectReports);
                            }
                        }
                    }
                }
            }
            reportingStructure.NumberOfReports = count;
            return(reportingStructure);
        }
コード例 #2
0
        public async Task <ReportingStructure> GetReportingStructureForEmployee(string id, CancellationToken cancellationToken)
        {
            Employee employee = employee = await _employeeContext
                                           .Employees
                                           .Include(e => e.DirectReports)
                                           .SingleOrDefaultAsync(e => e.EmployeeId == id, cancellationToken);

            if (employee == null)
            {
                return(null);
            }

            IList <string> excludeIds = new List <string>()
            {
                id
            };
            IList <string> directReportIds = employee.DirectReports?.Select(s => s.EmployeeId).ToList();

            ReportingStructure reportingStructure = new ReportingStructure()
            {
                Employee        = $"{ employee.FirstName } {employee.LastName}",
                NumberOfReports = directReportIds.Count()
            };

            if (directReportIds.Count > 0)
            {
                int numberOfReports = await GetNumberOfReports(directReportIds, excludeIds, cancellationToken);

                reportingStructure.NumberOfReports += numberOfReports;
            }

            return(reportingStructure);
        }
コード例 #3
0
        public ReportingStructure getReportingStructure(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new NullReferenceException("Employee id is null.");
            }

            Employee employee = GetById(id);

            //
            if (employee == null)
            {
                return(null);
            }
            int counter = 0;

            int totalDirectReports = getDirectReportCount(id, ref counter);

            //
            ReportingStructure reportingStructure = new ReportingStructure()
            {
                employee        = employee,
                numberOfReports = totalDirectReports
            };

            return(reportingStructure);
        }
コード例 #4
0
 public ReportingStructure Add(ReportingStructure reportingStructure)
 {
     Console.WriteLine("[Repo] Adding: " + reportingStructure);
     reportingStructure.Employee.EmployeeId = Guid.NewGuid().ToString();
     _reportingStructureContext.ReportingStructures.Add(reportingStructure);
     return(reportingStructure);
 }
コード例 #5
0
        public ReportingStructure GetReportingStructure(string id)
        {
            ReportingStructure structure    = new ReportingStructure();
            Employee           rootEmployee = GetById(id);
            int reports = 0;

            if (rootEmployee != null)
            {
                structure.employee = rootEmployee;
                var queue = new Queue <string>();
                queue.Enqueue(rootEmployee.EmployeeId);

                while (queue.Count > 0)
                {
                    var employeeID = queue.Dequeue();
                    var employee   = GetById(employeeID);
                    if (employee.DirectReports != null)
                    {
                        foreach (var dr in employee.DirectReports)
                        {
                            queue.Enqueue(dr.EmployeeId);
                        }
                        reports += employee.DirectReports.Count;
                    }
                    employee = null;
                }
            }
            structure.numberOfReports = reports;
            return(structure);
        }
コード例 #6
0
        public void GetEmployeeReportingStructure_Exceeds_MaxDepth()
        {
            //Arrange
            ILogger <EmployeeService> logger     = Substitute.For <ILogger <EmployeeService> >();
            IEmployeeRepository       repository = Substitute.For <IEmployeeRepository>();

            EmployeeService service = new EmployeeService(logger, repository);

            Employee employee1 = new Employee
            {
                EmployeeId = "fe69bd9b-8970-4856-bbfe-83cc461c2a24",
                FirstName  = "Billy",
                LastName   = "Corgan"
            };

            Employee employee2 = new Employee
            {
                EmployeeId = "cae3e8dc-6287-4aac-b4dc-b4383215c546",
                FirstName  = "D'arcy",
                LastName   = "Wretzky"
            };

            Employee employee3 = new Employee
            {
                EmployeeId = "964489b9-10dc-4c9c-a9a1-d85e99b11521",
                FirstName  = "James",
                LastName   = "Iha"
            };

            Employee employee4 = new Employee
            {
                EmployeeId = "9b3e10d9-2253-4465-9a6f-f7fa7793aa4c",
                FirstName  = "Jimmy",
                LastName   = "Chamberlain"
            };

            employee1.DirectReports = new List <Employee> {
                employee2
            };
            employee2.DirectReports = new List <Employee> {
                employee3
            };
            employee3.DirectReports = new List <Employee> {
                employee4
            };

            repository.GetById(Arg.Any <string>()).ReturnsForAnyArgs(employee1);

            //Act
            ReportingStructure actual = service.GetEmployeeReportingStructure(employee1.EmployeeId);

            //Assert
            Assert.IsNotNull(actual);

            //The NumberOfReports value will be the count under the maximum depth.
            //Since the graph has a depth of 4 and max depth is 3
            //The number of counts under the max depth is 3
            Assert.AreEqual(3, actual.NumberOfReports);
        }
コード例 #7
0
        public ReportingStructure GetReportingStructureById(string id)
        {
            ReportingStructure rs = new ReportingStructure();

            rs.Employee        = GetById(id);
            rs.NumberOfReports = CountReports(rs.Employee);
            return(rs);
        }
コード例 #8
0
        public ReportingStructure GetReportingStructureByEmplopyeeId(string id)
        {
            ReportingStructure reportingStructure = new ReportingStructure();

            reportingStructure.Employee        = GetEmployeeById(id);
            reportingStructure.NumberOfReports = FindTotalReports(id, 0);
            return(reportingStructure);
        }
        public ReportingStructure GetReportingStructureByEmployeeId(string id)
        {
            ReportingStructure reportingStructure = new ReportingStructure();

            reportingStructure.Employee        = _employeeContext.GetById(id);
            reportingStructure.NumberOfReports = GetNumberOfReportsById(id);
            return(reportingStructure);
        }
        public ReportingStructure GetByEmployeeId(string id)
        {
            ReportingStructure reportingStructure = new ReportingStructure();

            reportingStructure.Employee        = GetEmployeeById(id);
            reportingStructure.NumberOfReports = GetNumberOfDirectReports(reportingStructure.Employee);

            return(reportingStructure);
        }
コード例 #11
0
        public void AddCalculatedRules()
        {
            using (PmsEteckContext _context = new PmsEteckContext())
            {
                _context.Database.SetCommandTimeout(300);
                _context.Database.OpenConnection();
                using (DbCommand _command = _context.Database.GetDbConnection().CreateCommand())
                {
                    _command.CommandTimeout = 300;
                    _command.CommandText    = "budget.GetCalculatedDimensionRules";
                    _command.CommandType    = CommandType.StoredProcedure;
                    _command.Parameters.Add(new SqlParameter("@budgetDimensionId", iBudgetDimensionKey));

                    using (DbDataReader reader = _command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            ReportingStructure reportingStructure = db.ReportingStructure.Find((int)reader["iReportingStructureKey"]);
                            BudgetDimensionRules.Add(
                                new BudgetDimensionRule()
                            {
                                iReportingStructureKey = reportingStructure.iReportingStructureKey,
                                iRecNo           = reportingStructure.RecNo.Value,
                                dTotal           = reader["dTotal"] != DBNull.Value ? (decimal)reader["dTotal"] : 0,
                                dJanuary         = reader["dJanuary"] != DBNull.Value ? (decimal)reader["dJanuary"] : 0,
                                dFebruary        = reader["dFebruary"] != DBNull.Value ? (decimal)reader["dFebruary"] : 0,
                                dMarch           = reader["dMarch"] != DBNull.Value ? (decimal)reader["dMarch"] : 0,
                                dApril           = reader["dApril"] != DBNull.Value ? (decimal)reader["dApril"] : 0,
                                dMay             = reader["dMay"] != DBNull.Value ? (decimal)reader["dMay"] : 0,
                                dJune            = reader["dJune"] != DBNull.Value ? (decimal)reader["dJune"] : 0,
                                dJuly            = reader["dJuly"] != DBNull.Value ? (decimal)reader["dJuly"] : 0,
                                dAugust          = reader["dAugust"] != DBNull.Value ? (decimal)reader["dAugust"] : 0,
                                dSeptember       = reader["dSeptember"] != DBNull.Value ? (decimal)reader["dSeptember"] : 0,
                                dOctober         = reader["dOctober"] != DBNull.Value ? (decimal)reader["dOctober"] : 0,
                                dNovember        = reader["dNovember"] != DBNull.Value ? (decimal)reader["dNovember"] : 0,
                                dDecember        = reader["dDecember"] != DBNull.Value ? (decimal)reader["dDecember"] : 0,
                                PercentJanuary   = reader["PercentJan"] != DBNull.Value ? (decimal)reader["PercentJan"] : (decimal)1 / 12,
                                PercentFebruary  = reader["PercentFeb"] != DBNull.Value ? (decimal)reader["PercentFeb"] : (decimal)1 / 12,
                                PercentMarch     = reader["PercentMar"] != DBNull.Value ? (decimal)reader["PercentMar"] : (decimal)1 / 12,
                                PercentApril     = reader["PercentApr"] != DBNull.Value ? (decimal)reader["PercentApr"] : (decimal)1 / 12,
                                PercentMay       = reader["PercentMay"] != DBNull.Value ? (decimal)reader["PercentMay"] : (decimal)1 / 12,
                                PercentJune      = reader["PercentJun"] != DBNull.Value ? (decimal)reader["PercentJun"] : (decimal)1 / 12,
                                PercentJuly      = reader["PercentJul"] != DBNull.Value ? (decimal)reader["PercentJul"] : (decimal)1 / 12,
                                PercentAugust    = reader["PercentAug"] != DBNull.Value ? (decimal)reader["PercentAug"] : (decimal)1 / 12,
                                PercentSeptember = reader["PercentSep"] != DBNull.Value ? (decimal)reader["PercentSep"] : (decimal)1 / 12,
                                PercentOctober   = reader["PercentOct"] != DBNull.Value ? (decimal)reader["PercentOct"] : (decimal)1 / 12,
                                PercentNovember  = reader["PercentNov"] != DBNull.Value ? (decimal)reader["PercentNov"] : (decimal)1 / 12,
                                PercentDecember  = reader["PercentDec"] != DBNull.Value ? (decimal)reader["PercentDec"] : (decimal)1 / 12,
                                bSpatie          = reader["bSpatie"] != DBNull.Value ? (bool)reader["bSpatie"] : false,
                                bSubtotaal       = reader["bSubtotaal"] != DBNull.Value ? (bool)reader["bSubtotaal"] : false,
                            });
                        }
                        ;
                    }
                }
            }
        }
コード例 #12
0
        public ReportingStructure Create(ReportingStructure reportingStructure)
        {
            if (reportingStructure != null)
            {
                _reportingStructureRepository.Add(reportingStructure);
                _reportingStructureRepository.SaveAsync().Wait();
            }

            return(reportingStructure);
        }
コード例 #13
0
        public ReportingStructure GetById(string id)
        {
            ReportingStructure report = _reportingStructureContext.ReportingStructures
                                        .Where(e => e.Employee.EmployeeId == id)
                                        .Include(e => e.Employee)
                                        .Include(e => e.Employee.DirectReports)
                                        .FirstOrDefault();

            return(report);
        }
コード例 #14
0
        public ReportingStructure GetReportingByEmployee(Employee employee)
        {
            ReportingStructure ret = null;

            ret = new ReportingStructure()
            {
                Employee = employee,
                NumberOfDirectReports = GetNumberOfDirectReports(employee),
            };
            return(ret);
        }
コード例 #15
0
 /// <summary>
 /// Nests all the given <paramref name="rootEmployee"/>'s direct reports and continues recursively
 /// until an employee in the tree has no direct reports. Also updates the Reporting Structure's NumberOfReports property as it goes.
 /// </summary>
 /// <param name="rootEmployee">The top-level employee that will get its direct reports nested in its DirectReports property</param>
 /// <param name="rs">The reporting structure object that will get its count updated</param>
 /// <returns>
 /// void, updates the references passed to it
 /// </returns>
 public void AppendDirectReportsRecursively(Employee rootEmployee, ReportingStructure rs)
 {
     rootEmployee.DirectReports = _employeeContext.Employees.Include(e => e.DirectReports).SingleOrDefault(e => e.EmployeeId == rootEmployee.EmployeeId).DirectReports;
     if (rootEmployee.DirectReports.Count > 0)
     {
         foreach (Employee directReport in rootEmployee.DirectReports)
         {
             AppendDirectReportsRecursively(directReport, rs);
         }
     }
     rs.NumberOfReports++;
 }
コード例 #16
0
 public ReportingStructure GetReportingStructureById(string id)
 {
     if (!String.IsNullOrEmpty(id))
     {
         ReportingStructure ret = new ReportingStructure();
         Employee           e   = _employeeRepository.GetById(id);
         ret.Employee        = e;
         ret.NumberOfReports = GetReportCount(e.DirectReports);
         return(ret);
     }
     return(null);
 }
        /// <summary>
        /// Finds the number of direct reports for the specified <paramref name="employeeId"/>,
        /// and it's direct reports recursively.
        /// </summary>
        /// <param name="employeeId">The Id of the Employee.</param>
        /// <returns>ReportingStructure</returns>
        /// <exception cref="EmployeeNotFoundException">If employee Id is invalid.</exception>
        /// <exception cref="Exception">In case of some other error.</exception>
        public ReportingStructure GetByEmployeeId(string employeeId)
        {
            try
            {
                var employeeExists = _employeeRepository.Exists(employeeId);
                if (!employeeExists)
                {
                    throw new EmployeeNotFoundException($"Employee [Id: '{employeeId}'] not found.");
                }

                Employee employee = null;
                // to avoid an extra call to get Employee when building the reporting structure.
                bool isRoot          = true;
                int  numberOfReports = 0;
                var  queue           = new Queue <string>();
                queue.Enqueue(employeeId);

                // BFS.
                while (queue.Any())
                {
                    var id   = queue.Dequeue();
                    var temp = _employeeRepository.GetById(id, true);
                    if (isRoot)
                    {
                        employee = temp;
                        isRoot   = false;
                    }
                    numberOfReports += temp.DirectReports.Count;

                    foreach (var directReport in temp.DirectReports)
                    {
                        queue.Enqueue(directReport.EmployeeId);
                    }
                }

                var reportingStructure = new ReportingStructure(employee, numberOfReports);

                return(reportingStructure);
            }
            catch (EmployeeNotFoundException e)
            {
                _logger.LogError(e.Message);
                throw e;
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(null);
            }
        }
コード例 #18
0
        public ReportingStructure countReports(Employee employee)
        {
            ReportingStructure result = new ReportingStructure();

            result.employee = employee;

            vistedIds.Clear();
            result.numberOfReports = countReportsRecur(employee);

            //The above function populates employee.DirectReports
            //Making DirectReports null is done for readability's sake
            result.employee.DirectReports = null;

            return(result);
        }
コード例 #19
0
        public ReportingStructure GetByEmployeeId(string id)
        {
            if (!string.IsNullOrEmpty(id))
            {
                var employee = _employeeRepository.GetById(id);
                ReportingStructure structure = new ReportingStructure {
                    Employee        = employee,
                    NumberOfReports = GetNoReports(employee)
                };

                return(structure);
            }

            return(null);
        }
コード例 #20
0
        public ReportingStructure GetById(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                ReportingStructure reportingStructure = new ReportingStructure();
                reportingStructure.employee = _employeeRepository.GetById(id);

                // Calculate the number of direct reports
                reportingStructure.numberOfReports = FindNumberOfReports(reportingStructure.employee);

                return(reportingStructure);
            }

            return(null);
        }
コード例 #21
0
        /// <summary>
        /// Gets all direct reports
        /// </summary>
        /// <param name="id">The Employee's unique identifier</param>
        /// <returns>
        /// Returns ReportingStructure with nested direct reports
        /// </returns>
        public ReportingStructure GetEmployeeReportingStructure(string id)
        {
            ReportingStructure rs           = new ReportingStructure();
            Employee           rootEmployee = _employeeContext.Employees.Include(e => e.DirectReports).SingleOrDefault(e => e.EmployeeId == id);

            // Adds the direct reports recursively, and increments the counter
            AppendDirectReportsRecursively(rootEmployee, rs);
            rs.Employee   = rootEmployee;
            rs.EmployeeId = rootEmployee.EmployeeId;

            // the recursive function will add one for all employees, this removes one for the root employee her/himself
            rs.NumberOfReports--;

            return(rs);
        }
コード例 #22
0
        public ReportingStructure GetById(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                var reportEmployee = _employeeRepository.GetById(id);
                int reportCount    = getReportingCount(reportEmployee);;

                var result = new ReportingStructure();
                result.employee        = reportEmployee;
                result.numberOfReports = reportCount;

                return(result);
            }

            return(null);
        }
        public void GetReportsById_Returns_Ok_Trunk()
        {
            // Arrange
            string employeeId      = "16a596ae-edd3-4847-99fe-c4518e82c86f";
            int    expectedReports = 4;

            // Execute
            var getRequestTask = _httpClient.GetAsync($"api/reportingStructure/{employeeId}");
            var response       = getRequestTask.Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            ReportingStructure reportingStructure = response.DeserializeContent <ReportingStructure>();

            Assert.AreEqual(expectedReports, reportingStructure.NumberOfReports);
        }
        //Tests Get Reports by ID with 0 direct reports
        public void GetReportsById_Returns_Ok_Leaf()
        {
            // Arrange
            string employeeId      = "c0c2293d-16bd-4603-8e08-638a9d18b22c";
            int    expectedReports = 0;

            // Execute
            var getRequestTask = _httpClient.GetAsync($"api/reportingStructure/{employeeId}");
            var response       = getRequestTask.Result;

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            ReportingStructure reportingStructure = response.DeserializeContent <ReportingStructure>();

            Assert.AreEqual(expectedReports, reportingStructure.NumberOfReports);
        }
コード例 #25
0
        // Fetch all the employee's reporting to the specific ID
        public ReportingStructure GetReportEmployees(string employeeId)
        {
            try
            {
                Employee employee        = _employeeRepository.GetById(employeeId, true);
                int      numberOfReports = 0;
                var      stack           = new Stack <Employee>();
                // Depth-first search to find all the child nodes.
                if (employee != null)
                {
                    stack.Push(employee);
                    while (stack.Count != 0)
                    {
                        var current = stack.Pop();

                        foreach (Employee directReport in current.DirectReports ?? new List <Employee>())
                        {
                            Employee childEmp = _employeeRepository.GetById(directReport.EmployeeId, true);
                            numberOfReports += 1;
                            current.DirectReports.Append(directReport);
                            stack.Push(directReport);
                        }
                    }

                    ReportingStructure reportingStructure = new ReportingStructure()
                    {
                        Employee = employee, NumberOfReports = numberOfReports
                    };

                    return(reportingStructure);
                }
                else
                {
                    _logger.LogError($"Employee [Id: '{employeeId}'] not found.");
                    return(null);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message);
                return(null);
            }
        }
        /// <summary>
        /// Creates a ReportingStructure at the time of request by the given employee id.
        /// </summary>
        /// <param name="id"> The employee's id that will be used to fill out the ReportingStructure. </param>
        /// <returns> A newly created ReportingStructure with the employee and how many reports they have. </returns>
        public ReportingStructure GetById(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                ReportingStructure reportingStructure = new ReportingStructure();

                // Getting the employee in order to add it to the struture
                var employee = _employeeRepository.GetById(id);

                reportingStructure.Employee = employee;

                int reports = GetDirectReports(employee);

                reportingStructure.NumberOfReports = reports;

                return(reportingStructure);
            }

            return(null);
        }
コード例 #27
0
        public ReportingStructure GetReportsById(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                ReportingStructure createdReport = new ReportingStructure();
                //Get the employee based on the id
                createdReport.Employee = _employeeRepository.GetById(id);
                //If the employee is null no reporting structure can be generate return not found
                if (createdReport.Employee == null)
                {
                    return(null);
                }
                //Get the number of reports using the function below
                createdReport.NumberOfReports = GetDirectReportCount(createdReport.Employee);

                return(createdReport);
            }

            //No id return not found
            return(null);
        }
コード例 #28
0
        public ReportingStructure GetDirectReportsById(string id)
        {
            // Use the already existing method to get the Employee
            // by their ID
            Employee foundEmployee = GetById(id);

            if (foundEmployee != null)
            {
                var reportStruct = new ReportingStructure()
                {
                    Employee        = foundEmployee,
                    NumberOfReports = calcNumberOfReports(foundEmployee)
                };

                return(reportStruct);
            }
            else
            {
                return(null);
            }
        }
コード例 #29
0
        /// <summary>
        /// Gets the employee reporting structure.
        /// </summary>
        /// <remarks>
        /// If the employee DirectReport is null, 0 is assigned to NumberOfReports
        /// </remarks>
        /// <param name="employeeId">The employee identifier.</param>
        /// <returns>
        /// The employee reporting structure.
        /// </returns>
        public ReportingStructure GetEmployeeReportingStructure(string employeeId)
        {
            Employee employee = GetById(employeeId);

            if (employee == null)
            {
                return(null);
            }

            int numberOfDirectReports = 0;

            CountDirectReports(employee, ref numberOfDirectReports, startingDepth: 0, maximumDepth: 3);

            ReportingStructure reportingStructure = new ReportingStructure
            {
                Employee        = employee,
                NumberOfReports = numberOfDirectReports
            };

            return(reportingStructure);
        }
コード例 #30
0
        public ReportingStructure GetByEmployeeId(string id)
        {
            var employee = _employeeService.GetById(id);

            if (employee == null)
            {
                return(null);
            }
            else
            {
                var numberOfReports = CalculateNumberOfReports(employee);

                var reportingStructure = new ReportingStructure
                {
                    Employee        = employee,
                    NumberOfReports = numberOfReports
                };

                return(reportingStructure);
            }
        }