public static string GetSubject(this AutomobileBase entity) { var subject = entity switch { AutomobileInfo => AutomobileConstant.AutoMobileRecordSubject, GasDiscount => AutomobileConstant.GasDiscountRecordSubject, GasLog => AutomobileConstant.GasLogRecordSubject, _ => string.Empty }; return(subject); }
public static async Task <int> GetCatalogIdAsync(this AutomobileBase entity, IEntityLookup lookup) { if (lookup == null) { throw new ArgumentNullException(nameof(lookup)); } var catalogId = 0; switch (entity) { case AutomobileInfo: var autoCats = await lookup.GetEntitiesAsync <NoteCatalog>(cat => cat.Name == AutomobileConstant.AutoMobileInfoCatalogName); var autoCat = autoCats.FirstOrDefault(); if (autoCat != null) { catalogId = autoCat.Id; } break; case GasDiscount: var discountCats = await lookup.GetEntitiesAsync <NoteCatalog>(cat => cat.Name == AutomobileConstant.GasDiscountCatalogName); var discountCat = discountCats.FirstOrDefault(); if (discountCat != null) { catalogId = discountCat.Id; } break; case GasLog: var logCats = await lookup.GetEntitiesAsync <NoteCatalog>(cat => cat.Name == AutomobileConstant.GasLogCatalogName); var logCat = logCats.FirstOrDefault(); if (logCat != null) { catalogId = logCat.Id; } break; default: catalogId = 0; break; } return(catalogId); }