/// <summary>
        /// Create XML to add time off request.
        /// </summary>
        /// <param name="startDateTime">Start date.</param>
        /// <param name="endDateTime">End Date.</param>
        /// <param name="queryDateSpan">The query date span.</param>
        /// <param name="personNumber">Person number.</param>
        /// <param name="reason">Reason string.</param>
        /// <param name="comments">The sender notes of the time off request.</param>
        /// <returns>Add time of request.</returns>
        private string CreateAddTimeOffRequest(DateTimeOffset startDateTime, DateTimeOffset endDateTime, string queryDateSpan, string personNumber, string reason, Comments comments)
        {
            // Kronos API expects a collection of periods so first calculate the actual period
            // before adding it to a list.
            var timeOffPeriod  = CalculateTimeOffPeriod(startDateTime, endDateTime, reason);
            var timeOffPeriods = new List <TimeOffPeriod>()
            {
                timeOffPeriod
            };

            TimeOffAddRequest.Request rq = new TimeOffAddRequest.Request()
            {
                Action             = ApiConstants.AddRequests,
                EmployeeRequestMgm = new TimeOffAddRequest.EmployeeRequestMgmt()
                {
                    Employees = new TimeOffAddRequest.Employee()
                    {
                        PersonIdentity = new TimeOffAddRequest.PersonIdentity()
                        {
                            PersonNumber = personNumber
                        }
                    },
                    QueryDateSpan = queryDateSpan,
                    RequestItems  = new TimeOffAddRequest.RequestItems()
                    {
                        GlobalTimeOffRequestItem = new TimeOffAddRequest.GlobalTimeOffRequestItem()
                        {
                            Employee = new TimeOffAddRequest.Employee()
                            {
                                PersonIdentity = new TimeOffAddRequest.PersonIdentity()
                                {
                                    PersonNumber = personNumber
                                }
                            },
                            RequestFor     = ApiConstants.TOR,
                            TimeOffPeriods = new TimeOffPeriods()
                            {
                                TimeOffPeriod = timeOffPeriods
                            },
                            Comments = comments,
                        },
                    },
                },
            };

            return(rq.XmlSerialize());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create XML to add time off request.
        /// </summary>
        /// <param name="startDateTime">Start date.</param>
        /// <param name="endDateTime">End Date.</param>
        /// <param name="personNumber">Person number.</param>
        /// <param name="reason">Reason string.</param>
        /// <param name="kronosTimeZone">The time zone of Kronos WFC.</param>
        /// <returns>Add time of request.</returns>
        private string CreateAddTimeOffRequest(DateTimeOffset startDateTime, DateTimeOffset endDateTime, string personNumber, string reason, TimeZoneInfo kronosTimeZone)
        {
            var duration      = string.Empty;
            var timeOffPeriod = new List <TimeOffAddRequest.TimeOffPeriod>();

            duration = CalculateTimeOffPeriod(startDateTime, endDateTime, reason, timeOffPeriod, kronosTimeZone);

            TimeOffAddRequest.Request rq = new TimeOffAddRequest.Request()
            {
                Action             = ApiConstants.AddRequests,
                EmployeeRequestMgm = new TimeOffAddRequest.EmployeeRequestMgmt()
                {
                    Employees = new TimeOffAddRequest.Employee()
                    {
                        PersonIdentity = new TimeOffAddRequest.PersonIdentity()
                        {
                            PersonNumber = personNumber
                        }
                    },
                    QueryDateSpan = $"{startDateTime.ToString("M/d/yyyy", CultureInfo.InvariantCulture)} - {endDateTime.ToString("M/d/yyyy", CultureInfo.InvariantCulture)}",
                    RequestItems  = new TimeOffAddRequest.RequestItems()
                    {
                        GlobalTimeOffRequestItem = new TimeOffAddRequest.GlobalTimeOffRequestItem()
                        {
                            Employee = new TimeOffAddRequest.Employee()
                            {
                                PersonIdentity = new TimeOffAddRequest.PersonIdentity()
                                {
                                    PersonNumber = personNumber
                                }
                            },
                            RequestFor     = ApiConstants.TOR,
                            TimeOffPeriods = new TimeOffAddRequest.TimeOffPeriods()
                            {
                                TimeOffPeriod = timeOffPeriod
                            },
                        },
                    },
                },
            };

            return(rq.XmlSerialize <TimeOffAddRequest.Request>());
        }