public static object GetValue(this IHeaderInfo header, Entity entity) { var value = entity?.Properties[header.Name]; switch (header.DataType) { case DataTypeNames.Boolean: return(Change.To <bool>(value)); case DataTypeNames.Integer: return(Change.To <int>(value)); case DataTypeNames.Decimal: return(Change.To <decimal>(value)); case DataTypeNames.Date: case DataTypeNames.Time: case DataTypeNames.Datetime: return(Change.To <DateTime>(value)); case DataTypeNames.Record: return(value as Entity); case DataTypeNames.String: default: return(Change.To <string>(value)); } }
public async Task Invoke(HttpContext context, IHeaderInfo headerInfo) { if (context.Request.Path == "/Ping" || context.Request.Path == "/favicon.ico") { await _next(context); } else { context.Request.Headers.TryGetValue(_UserEmailHeader, out var emailHeaderValue); context.Request.Headers.TryGetValue(_UserNoteHeader, out var noteHeaderValue); string email = emailHeaderValue.FirstOrDefault(); if (!TryExtractUkprnFromHeader(noteHeaderValue, out var ukprn)) { _logger.LogError("GetHeadersMiddleware - invalid or no UKPRN."); context.Response.StatusCode = (int)HttpStatusCode.BadRequest; context.Response.ContentType = "application/json"; var json = GetApiResponseAsJson(context.Response.StatusCode, _InvalidUkprnMessage); await context.Response.WriteAsync(json); } else if (string.IsNullOrWhiteSpace(email)) { _logger.LogError("GetHeadersMiddleware - no Email Address"); context.Response.StatusCode = (int)HttpStatusCode.BadRequest; context.Response.ContentType = "application/json"; var json = GetApiResponseAsJson(context.Response.StatusCode, _InvalidEmailMessage); await context.Response.WriteAsync(json); } else { headerInfo.Ukprn = ukprn; headerInfo.Email = email; await _next(context); } } }
public EpaController(ILogger <EpaController> logger, IHeaderInfo headerInfo, IApiClient apiClient) { _logger = logger; _headerInfo = headerInfo; _apiClient = apiClient; }
public StandardsController(ILogger <StandardsController> logger, IHeaderInfo headerInfo, IApiClient apiClient) { _logger = logger; _headerInfo = headerInfo; _apiClient = apiClient; }
public CertificateController(ILogger <CertificateController> logger, IHeaderInfo headerInfo, IApiClient apiClient) { _logger = logger; _headerInfo = headerInfo; _apiClient = apiClient; }
/// <summary> /// Cast row values to Table Row Model. /// </summary> /// <typeparam name="TRowObject">Table Row Model.</typeparam> /// <param name="rowIndex">Row index.</param> /// <param name="propertiesToSkip">Header name.</param> /// <returns>Model.</returns> public TRowObject CastRow <TRowObject>(int rowIndex, params string[] propertiesToSkip) where TRowObject : new() { var cells = TableService.GetRowCells(rowIndex); if (cells.Count != ControlColumnDataCollection.Count) { // Compare headers to determine why the cells count is different var actual = HeaderNamesService.GetHeaderNames().ToList(); var expected = ControlColumnDataCollection.Select(c => c.HeaderName).ToList(); CollectionAssert.AreEqual(expected, actual, $"Expected: {expected.Stringify()}\r\nActual: {actual.Stringify()}"); } var dto = new TRowObject(); var properties = dto.GetType().GetProperties().ToList(); foreach (var propertyInfo in properties) { IHeaderInfo headerInfo = HeaderNamesService.GetHeaderInfoByProperty(propertyInfo); if (propertiesToSkip.Contains(headerInfo.HeaderName)) { continue; } int?headerPosition = HeaderNamesService.GetHeaderPosition(headerInfo.HeaderName, ControlColumnDataCollection.AsEnumerable <IHeaderInfo>().ToList(), headerInfo.Order); if (headerPosition == null) { continue; } var controlData = GetControlDataByProperty(propertyInfo); if (controlData != null && controlData.ComponentType != null && controlData.ComponentType.IsSubclassOf(typeof(Component))) { var repo = new ComponentRepository(); var xpath = $".{cells[(int)headerPosition].GetXPath()}"; var tableCell = this.CreateByXpath <TableCell>(xpath); dynamic elementValue; if (controlData.By == null) { controlData.By = new FindXpathStrategy(xpath); elementValue = CastCell(repo, controlData, tableCell); controlData.By = null; } else { elementValue = CastCell(repo, controlData, tableCell); } var elementType = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType; var newValue = elementValue == null ? default : Convert.ChangeType(elementValue, elementType); elementValue = Convert.ChangeType(newValue, propertyInfo.PropertyType); propertyInfo.SetValue(dto, elementValue); } else { string htmlNodeValue = HttpUtility.HtmlDecode(TableService.GetRowCells(rowIndex)[(int)headerPosition].InnerText).Trim(); var type = Nullable.GetUnderlyingType(propertyInfo.PropertyType) ?? propertyInfo.PropertyType; object elementValue; if (type == typeof(DateTime) || type == typeof(DateTime?)) { DateTime dateTime; DateTime.TryParse(htmlNodeValue, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out dateTime); elementValue = (DateTime?)dateTime; } else { elementValue = string.IsNullOrEmpty(htmlNodeValue) ? default : Convert.ChangeType(htmlNodeValue, type, CultureInfo.InvariantCulture); } propertyInfo.SetValue(dto, elementValue); } } return(dto); }