public IActionResult Estuaries() { var model = dbContext.Estuaries.OrderBy(i => i.Name).ToList(); SAEONLogs.Verbose("Model: {@Model}", model); return(View(model)); }
public IActionResult UpdateImage(ImageModel model) { using (SAEONLogs.MethodCall(GetType())) { { try { SAEONLogs.Verbose("Model: {@Model}", model); if (model is null) { throw new ArgumentNullException(nameof(model)); } var estuary = dbContext.Estuaries.Include(i => i.Images).First(i => i.Id == model.EstuaryId); var image = dbContext.Images.First(i => i.Id == model.Id); image.Type = model.Type; image.SubType = model.SubType; image.Name = model.Name; image.Notes = model.Notes; image.Source = model.Source; image.Link = model.Link; image.LinkHiRes = model.LinkHiRes; image.HiResImageSize = model.HiResImageSize; dbContext.SaveChanges(); return(RedirectToAction(nameof(Images), new { id = model.EstuaryId })); } catch (Exception ex) { SAEONLogs.Exception(ex); throw; } } } }
public async Task <T> GetItemAsync(T item, Expression <Func <T, object> > partitionKeyExpression) { if (item is null) { throw new ArgumentNullException(nameof(item)); } if (partitionKeyExpression is null) { throw new ArgumentNullException(nameof(partitionKeyExpression)); } using (SAEONLogs.MethodCall <T>(GetType(), new MethodCallParameters { { "id", item.Id }, { "partitionKey", GetPartitionKeyValue(item, partitionKeyExpression) } })) { try { CheckItem(item); if (AutoEnsureContainer) { await EnsureContainerAsync().ConfigureAwait(false); } return(await container.ReadItemAsync <T>(item.Id, GetPartitionKey(item, partitionKeyExpression)).ConfigureAwait(false)); } catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { SAEONLogs.Verbose("Item with ID {ID} not found", item.Id); return(default);
public List <ImageModel> GetImages(int id, ImageFilterModel filters) { using (SAEONLogs.MethodCall(GetType(), new MethodCallParameters { { "Id", id }, { "Filters", filters } })) { try { SAEONLogs.Verbose("Filters: {@Filters}", filters); var estuary = dbContext.Estuaries.Include(i => i.Images.Where(i => !string.IsNullOrWhiteSpace(i.Link) && i.Available != "N")).Where(i => i.Id == id).FirstOrDefault(); if (estuary is null) { return(new List <ImageModel>()); } var query = estuary.Images.AsQueryable(); if (!string.IsNullOrWhiteSpace(filters?.Type)) { query = query.Where(i => i.Type == filters.Type); } if (!string.IsNullOrWhiteSpace(filters?.SubType)) { query = query.Where(i => i.SubType == filters.SubType); } return(query .Where(i => System.IO.File.Exists(Path.Combine(env.ContentRootPath, i.Link.RemoveStartingBackSlash().RemoveStartingForwardSlash()))) .OrderBy(i => i.Type) .ThenBy(i => i.SubType) .ThenBy(i => i.DateTaken) .ThenBy(i => i.Date) .ThenBy(i => i.Name) .Select(i => new ImageModel { Id = i.Id, Type = i.Type, SubType = i.SubType, Name = i.Name, Date = i.Date, Source = i.Source, Reference = i.Reference, Notes = i.Notes, //Link = i.Link, //LinkHiRes = i.LinkHiRes, HiResImageSize = i.HiResImageSize }) .ToList()); } catch (Exception ex) { SAEONLogs.Exception(ex); throw; } } }
public static WorksheetPart InsertSheet(SpreadsheetDocument document, string sheetName = "") { using (SAEONLogs.MethodCall(typeof(WorksheetPart))) { try { if (document is null) { throw new ArgumentNullException(nameof(document)); } // Add a blank WorksheetPart. WorksheetPart worksheetPart = document.WorkbookPart.AddNewPart <WorksheetPart>(); worksheetPart.Worksheet = new Worksheet(new SheetData()); Sheets sheets = document.WorkbookPart.Workbook.GetFirstChild <Sheets>(); if (sheets is null) { sheets = document.WorkbookPart.Workbook.AppendChild <Sheets>(new Sheets()); } string relationshipId = document.WorkbookPart.GetIdOfPart(worksheetPart); SAEONLogs.Verbose("relationshipId: {relationshipId}", relationshipId); // Get a unique ID for the new worksheet. uint sheetId = 1; if (sheets.Elements <Sheet>().Any()) { sheetId = sheets.Elements <Sheet>().Select(s => s.SheetId.Value).Max() + 1; } SAEONLogs.Verbose("sheetId: {sheetId}", sheetId); // Give the new worksheet a name. if (string.IsNullOrEmpty(sheetName)) { sheetName = "Sheet" + sheetId; } SAEONLogs.Verbose("sheetName: {sheetName}", sheetName); // Append the new worksheet and associate it with the workbook. Sheet sheet = new Sheet() { Id = relationshipId, SheetId = sheetId, Name = sheetName }; sheets.Append(sheet); return(worksheetPart); } catch (Exception ex) { SAEONLogs.Exception(ex); throw; } } }
//[ResponseCache(Duration = 604800)] public IActionResult Index() { using (SAEONLogs.MethodCall(GetType())) { try { SAEONLogs.Verbose("ContentRoot: {contentRoot} WebRoot: {webRoot}", env.ContentRootPath, env.WebRootPath); List <SitemapNode> nodes = new List <SitemapNode> { new SitemapNode(Url.Action("Index", "Home")), new SitemapNode(Url.Action("Index", "Search")), new SitemapNode(Url.Action("About", "Home")), new SitemapNode(Url.Action("Acknowledgements", "Home")), new SitemapNode(Url.Action("Background", "Home")), new SitemapNode(Url.Action("Contact", "Home")), new SitemapNode(Url.Action("Links", "Home")), new SitemapNode(Url.Action("Privacy", "Home")), new SitemapNode(Url.Action("Researchers", "Home")), }; foreach (var estuary in dbContext.Estuaries.Include(i => i.Literatures.Where(i => !string.IsNullOrWhiteSpace(i.Link) && i.Available != "N")).Include(i => i.Images.Where(i => !string.IsNullOrWhiteSpace(i.Link) && i.Available != "N")).OrderBy(i => i.Name)) { var node = new SitemapNode(Url.Action("Index", "Info", new { id = estuary.Id })); var images = new List <SitemapImage>(); foreach (var image in estuary.Images.Where(i => i.Link.StartsWith("\\Archive\\")).OrderBy(i => i.Name)) { var fileName = Path.Combine(env.ContentRootPath, image.Link.RemoveStartingBackSlash()); if (!System.IO.File.Exists(fileName)) { SAEONLogs.Verbose("Cant find {fileName}", fileName); } else { var uri = $"{Request.Scheme}://{Request.Host}/Image/LoRes/{image.Id}"; var sitemapImage = new SitemapImage(Uri.EscapeUriString(uri)) { Title = image.Name, License = "https://creativecommons.org/licenses/by-nc-sa/4.0/" }; images.Add(sitemapImage); } } node.Images = images; nodes.Add(node); } return(new SitemapProvider().CreateSitemap(new SitemapModel(nodes))); } catch (Exception ex) { SAEONLogs.Exception(ex); throw; } } }
public static CsvWriter GetCsvWriter <T>(TextWriter writer, CsvConfiguration config, IEnumerable <T> list) where T : class { var result = GetCsvWriter(writer, config); var type = list.GetType(); var itemType = type.GetGenericArguments().Length > 0 ? type.GetGenericArguments()[0] : type.GetElementType(); var updates = false; var ignores = itemType.GetProperties().Where(property => property.GetCustomAttributes(true).OfType <JsonIgnoreAttribute>().Any()).ToList(); SAEONLogs.Verbose("Type: {Type} IgnoreProperties: {@IgnoreProperties}", itemType, ignores); #if NET5_0 var names = itemType.GetProperties().Where(property => property.GetCustomAttributes(true).OfType <JsonPropertyNameAttribute>().Any()).ToList(); SAEONLogs.Verbose("Names: {@Names}", names); #endif if (ignores.Any() || #if NET5_0 names.Any() #else false #endif ) { var map = result.Context.AutoMap(itemType); foreach (var memberMap in map.MemberMaps) { var propName = memberMap.Data.Member.Name; if (ignores.Any(i => i.Name == propName)) { memberMap.Ignore(); updates = true; } #if NET5_0 var name = names.FirstOrDefault(i => i.Name == propName); if (name is not null) { var newName = name.GetCustomAttribute <JsonPropertyNameAttribute>(true).Name; //SAEONLogs.Verbose("OldName: {OldName} NewName: {NewName}", propName, newName); memberMap.Name(newName, propName); updates = true; } #endif //SAEONLogs.Verbose("MemberMap: {@MemberMap}", memberMap); } //SAEONLogs.Verbose("Map: {@Map}", map); if (updates) { result.Context.RegisterClassMap(map); } } return(result); }