/// <summary> /// This method update the counter of the requested user /// </summary> /// <param name="arrivalStatistics">Current <see cref="ArrivalStatistics"/> object </param> /// <param name="employee">Employee ID To update his arrival counter</param> /// <param name="orgID"> Organization ID </param> /// <seealso cref="getUser(string, string)"/> private void updateLists(ArrivalStatistics arrivalStatistics, string employee, string orgID) { User user = getUser(orgID, employee); if (arrivalStatistics.Employees.ContainsKey(user.ID)) { arrivalStatistics.Employees[user.ID] = ++arrivalStatistics.Employees[user.ID]; } else { arrivalStatistics.Employees.Add(user.ID, 1); } if (arrivalStatistics.Departments.ContainsKey(user.Department)) { arrivalStatistics.Departments[user.Department] = ++arrivalStatistics.Departments[user.Department]; } else { arrivalStatistics.Departments.Add(user.Department, 1); } if (arrivalStatistics.Roles.ContainsKey(user.Role)) { arrivalStatistics.Roles[user.Role] = ++arrivalStatistics.Roles[user.Role]; } else { arrivalStatistics.Roles.Add(user.Role, 1); } if (arrivalStatistics.Floors.ContainsKey(user.Floor)) { arrivalStatistics.Floors[user.Floor] = ++arrivalStatistics.Floors[user.Floor]; } else { arrivalStatistics.Floors.Add(user.Floor, 1); } }
/// <summary> /// This method gets all the events in the requested reriod of time /// </summary> /// <param name="orgID"> Organization ID </param> /// <param name="periodToGet"> Amount of days to get</param> /// <returns>Data as <see cref="ArrivalStatistics"/></returns> /// <seealso cref="GetCalendar(string)"/> /// <seealso cref="updateLists(ArrivalStatistics, string, string)"/> public ArrivalStatistics GetLastActivities(string orgID, int periodToGet) { ArrivalStatistics arrivalStatistics = new ArrivalStatistics(); var events = GetCalendar(orgID); DateTime today_date = DateTime.Today; DateTime week_ago = DateTime.Today.AddDays(-periodToGet); try { foreach (Calendar calendar in events) { DateTime curr = Convert.ToDateTime(calendar.Date); if (DateTime.Compare(curr, week_ago) >= 0 && DateTime.Compare(curr, today_date) <= 0) { if (!calendar.EmployeesArriving.Equals("")) { List <string> employees = new List <string>(calendar.EmployeesArriving.Trim().Split(';')); foreach (string employee in employees) { if (employee.Equals("")) { continue; } arrivalStatistics.TotalArrivals++; updateLists(arrivalStatistics, employee, orgID); } } } } return(arrivalStatistics); } catch (Exception e) { throw new Exception("Fail to get Last " + periodToGet + " activities. " + e.Message); } }