public IActionResult Getlist(string listName) { var connectionString = _configuration.GetConnectionString("LaboratoryBookConnectionString"); var laboratoryBook = HttpContext.User.Claims.First(claim => claim.Type == "LaboratoryBook").Value; var columnToGet = new ColumnToGet(); switch (listName) { case "regimes": columnToGet = ColumnToGet.Regime; break; case "operators": columnToGet = ColumnToGet.Operator; break; case "materials": columnToGet = ColumnToGet.Material; break; case "substrates": columnToGet = ColumnToGet.Substrate; break; case "permissionIDs": columnToGet = ColumnToGet.PermissionID; break; default: return(null); } var columnList = LaboratoryBookHelper.GetColumnList(connectionString, laboratoryBook, columnToGet); return(Content(columnList)); }
public async Task <IActionResult> AddRow() { try { var connectionString = _configuration.GetConnectionString("LaboratoryBookConnectionString"); var laboratoryBook = HttpContext.User.Claims.First(claim => claim.Type == "LaboratoryBook").Value; var getRegimesTask = Task.Run <string>(() => LaboratoryBookHelper .GetColumnList( connectionString, laboratoryBook, ColumnToGet.Regime)); var getOperatorsTask = Task.Run <string>(() => LaboratoryBookHelper .GetColumnList( connectionString, laboratoryBook, ColumnToGet.Operator)); var getMaterialsTask = Task.Run <string>(() => LaboratoryBookHelper .GetColumnList( connectionString, laboratoryBook, ColumnToGet.Material)); var getSubstratesTask = Task.Run <string>(() => LaboratoryBookHelper .GetColumnList( connectionString, laboratoryBook, ColumnToGet.Substrate)); var getPermissionIDsTask = Task.Run <string>(() => LaboratoryBookHelper .GetColumnList(connectionString, laboratoryBook, ColumnToGet.PermissionID)); var getColumnValuesTasks = new List <Task <string> >(); getColumnValuesTasks.AddRange(new[] { getRegimesTask, getOperatorsTask, getMaterialsTask, getSubstratesTask, getPermissionIDsTask }); var addRowModel = new AddRowModel(); while (getColumnValuesTasks.Any()) { var compleatedTask = await Task.WhenAny(getColumnValuesTasks.ToArray()); if (compleatedTask == getRegimesTask) { addRowModel.Regimes = compleatedTask.Result.Split(";"); } else if (compleatedTask == getOperatorsTask) { addRowModel.Operators = compleatedTask.Result.Split(";"); } else if (compleatedTask == getMaterialsTask) { addRowModel.Materials = compleatedTask.Result.Split(";"); } else if (compleatedTask == getSubstratesTask) { addRowModel.Substrates = compleatedTask.Result.Split(";"); } else { var userPermission = HttpContext .User .Claims .First(claim => claim.Type == "Permission") .Value; var userPermissionInt = int.Parse(userPermission); addRowModel.PermissionIDs = compleatedTask .Result .Split(";") .Where(permissionId => { var permissionIdInt = int.Parse(permissionId); return(permissionIdInt <= userPermissionInt); }); } getColumnValuesTasks.Remove(compleatedTask); } var maxRowId = LaboratoryBookHelper.GetDbDataScalar( connectionString, $"SELECT MAX(sampleID) FROM laboratory_book_{laboratoryBook}; " ); if (maxRowId is DBNull) { addRowModel.RowId = 1; } else { addRowModel.RowId = ((int)maxRowId) + 1; } var bookInfoDataTable = LaboratoryBookHelper.GetDbDataTable( connectionString, $"SHOW COLUMNS FROM laboratory_book_{laboratoryBook}; " ); var columnNames = new List <string>(); foreach (DataRow dataRow in bookInfoDataTable.Rows) { columnNames.Add((string)dataRow["Field"]); } addRowModel.Columns = columnNames.ToArray(); return(PartialView("_AddRowPartial", addRowModel)); } catch (Exception exception) { return(new ObjectResult(exception.Message)); } }