/// <summary> /// Method to save or update Teams to Department mapping. /// </summary> /// <param name="entity">Mapping entity reference.</param> /// <returns>http status code representing the asynchronous operation.</returns> public async Task <bool> TeamsToDepartmentMappingAsync(TeamsDepartmentMappingModel entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } try { var result = await this.StoreOrUpdateEntityAsync(entity).ConfigureAwait(false); return(result.HttpStatusCode == (int)HttpStatusCode.NoContent); } catch (Exception) { return(false); throw; } }
public async Task <IActionResult> ImportMappingAsync() { var configurationEntities = await this.configurationProvider.GetConfigurationsAsync().ConfigureAwait(false); var configEntity = configurationEntities?.FirstOrDefault(); if (configEntity != null && !string.IsNullOrEmpty(configEntity.WorkforceIntegrationId)) { // Getting the posted file. var file = this.HttpContext.Request.Form.Files[0]; bool isValidFile = true; int noOfColumns = 0; if (file != null) { using (XLWorkbook workbook = new XLWorkbook(file.OpenReadStream())) { IXLWorksheet worksheet = workbook.Worksheet(1); // Validation to check if row other than column exists if (worksheet.RowsUsed().Count() == 1) { isValidFile = false; return(this.Json(new { isWorkforceIntegrationPresent = true, response = isValidFile })); } // Getting count of total used cells var usedCellsCount = worksheet.RowsUsed().CellsUsed().Count(); foreach (IXLRow row in worksheet.RowsUsed()) { if (row.RangeAddress.FirstAddress.RowNumber == 1) { // Getting count of total coumns available in the template noOfColumns = row.CellsUsed().Count(); continue; } // Validation to check if any cell has empty value if ((usedCellsCount % noOfColumns) != 0 || noOfColumns != Convert.ToInt16(Resources.NoOfColumnsInExcel, CultureInfo.InvariantCulture)) { isValidFile = false; return(this.Json(new { isWorkforceIntegrationPresent = true, response = isValidFile })); } TeamsDepartmentMappingModel entity = new TeamsDepartmentMappingModel() { PartitionKey = row.Cell(1).Value.ToString(), RowKey = Utility.OrgJobPathDBConversion(row.Cell(2).Value.ToString()), TeamId = row.Cell(3).Value.ToString(), ShiftsTeamName = row.Cell(4).Value.ToString(), TeamsScheduleGroupId = row.Cell(5).Value.ToString(), TeamsScheduleGroupName = row.Cell(6).Value.ToString(), }; if (isValidFile) { var tenantId = this.appSettings.TenantId; var clientId = this.appSettings.ClientId; var clientSecret = this.appSettings.ClientSecret; var instance = this.appSettings.Instance; var accessToken = await this.graphUtility.GetAccessTokenAsync(tenantId, instance, clientId, clientSecret, configEntity.AdminAadObjectId).ConfigureAwait(false); var graphClient = CreateGraphClientWithDelegatedAccess(accessToken); var isSuccess = await this.graphUtility.AddWFInScheduleAsync(entity.TeamId, graphClient, configEntity.WorkforceIntegrationId, accessToken).ConfigureAwait(false); if (isSuccess) { await this.teamDepartmentMappingProvider.TeamsToDepartmentMappingAsync(entity).ConfigureAwait(false); } } } } } return(this.Json(new { isWorkforceIntegrationPresent = true, response = isValidFile })); } else { return(this.Json(new { isWorkforceIntegrationPresent = false, error = Resources.WorkforceIntegrationNotRegister })); } }