/// <summary> /// Creates and stores a open shift mapping entity. /// </summary> /// <param name="openShift">An open shift from Shifts.</param> /// <param name="mappedTeam">A team mapping entity.</param> /// <param name="monthPartitionKey">The partition key for the shift.</param> /// <param name="openShiftOrgJobPath">The org job path of the open shift.</param> /// <returns>A task.</returns> private async Task CreateAndStoreOpenShiftMapping(Models.IntegrationAPI.OpenShiftIS openShift, TeamToDepartmentJobMappingEntity mappedTeam, string monthPartitionKey, string openShiftOrgJobPath) { var kronosUniqueId = this.utility.CreateOpenShiftInTeamsUniqueId(openShift, mappedTeam.KronosTimeZone, openShiftOrgJobPath); var startDateTime = DateTime.SpecifyKind(openShift.SharedOpenShift.StartDateTime, DateTimeKind.Utc); AllOpenShiftMappingEntity openShiftMappingEntity = new AllOpenShiftMappingEntity { PartitionKey = monthPartitionKey, RowKey = openShift.Id, KronosOpenShiftUniqueId = kronosUniqueId, KronosSlots = openShift.SharedOpenShift.OpenSlotCount, OrgJobPath = openShiftOrgJobPath, OpenShiftStartDate = startDateTime, }; await this.openShiftMappingEntityProvider.SaveOrUpdateOpenShiftMappingEntityAsync(openShiftMappingEntity).ConfigureAwait(false); }
/// <summary> /// Creates an open shift in Kronos. /// </summary> /// <param name="openShift">The open shift entity to create in Kronos.</param> /// <param name="team">The team the open shift belongs to.</param> /// <returns>A response to return to teams.</returns> public async Task <ShiftsIntegResponse> CreateOpenShiftInKronosAsync(Models.IntegrationAPI.OpenShiftIS openShift, TeamToDepartmentJobMappingEntity team) { // The connector does not support drafting entities as it is not possible to draft shifts in Kronos. // Likewise there is no share schedule WFI call. if (openShift.DraftOpenShift != null) { return(ResponseHelper.CreateBadResponse(openShift.Id, error: "Creating an open shift as a draft is not supported for your team in Teams. Please publish changes directly using the 'Share' button.")); } if (openShift.SharedOpenShift == null) { return(ResponseHelper.CreateBadResponse(openShift.Id, error: "An unexpected error occured. Could not create open shift.")); } if (openShift.SharedOpenShift.Activities.Any()) { return(ResponseHelper.CreateBadResponse(openShift.Id, error: "Adding activities to open shifts is not supported for your team in Teams. Remove all activities and try sharing again.")); } var allRequiredConfigurations = await this.utility.GetAllConfigurationsAsync().ConfigureAwait(false); if ((allRequiredConfigurations?.IsAllSetUpExists).ErrorIfNull(openShift.Id, "App configuration incorrect.", out var response)) { return(response); } var possibleTeams = await this.teamDepartmentMappingProvider.GetMappedTeamDetailsBySchedulingGroupAsync(team.TeamId, openShift.SchedulingGroupId).ConfigureAwait(false); var openShiftOrgJobPath = possibleTeams.FirstOrDefault().RowKey; var commentTimeStamp = this.utility.UTCToKronosTimeZone(DateTime.UtcNow, team.KronosTimeZone).ToString(CultureInfo.InvariantCulture); var comments = XmlHelper.GenerateKronosComments(openShift.SharedOpenShift.Notes, this.appSettings.ShiftNotesCommentText, commentTimeStamp); var openShiftDetails = new { KronosStartDateTime = this.utility.UTCToKronosTimeZone(openShift.SharedOpenShift.StartDateTime, team.KronosTimeZone), KronosEndDateTime = this.utility.UTCToKronosTimeZone(openShift.SharedOpenShift.EndDateTime, team.KronosTimeZone), DisplayName = openShift.SharedOpenShift.DisplayName, }; var creationResponse = await this.openShiftActivity.CreateOpenShiftAsync( new Uri(allRequiredConfigurations.WfmEndPoint), allRequiredConfigurations.KronosSession, this.utility.FormatDateForKronos(openShiftDetails.KronosStartDateTime), this.utility.FormatDateForKronos(openShiftDetails.KronosEndDateTime), openShiftDetails.KronosEndDateTime.Day > openShiftDetails.KronosStartDateTime.Day, Utility.OrgJobPathKronosConversion(openShiftOrgJobPath), openShiftDetails.DisplayName, openShiftDetails.KronosStartDateTime.TimeOfDay.ToString(), openShiftDetails.KronosEndDateTime.TimeOfDay.ToString(), openShift.SharedOpenShift.OpenSlotCount, comments).ConfigureAwait(false); if (creationResponse.Status != ApiConstants.Success) { return(ResponseHelper.CreateBadResponse(openShift.Id, error: "Open shift was not created successfully in Kronos.")); } var monthPartitionKey = Utility.GetMonthPartition( this.utility.FormatDateForKronos(openShiftDetails.KronosStartDateTime), this.utility.FormatDateForKronos(openShiftDetails.KronosEndDateTime)); await this.CreateAndStoreOpenShiftMapping(openShift, team, monthPartitionKey.FirstOrDefault(), openShiftOrgJobPath).ConfigureAwait(false); return(ResponseHelper.CreateSuccessfulResponse(openShift.Id)); }