From 3e9e047b5188d7620d23f7cf89fa35eb2cffe335 Mon Sep 17 00:00:00 2001 From: CodeLiturgy Date: Thu, 1 Sep 2022 06:54:22 +0100 Subject: [PATCH] Using xml comments in tempaltes --- .../Context/Extensions/CountryExtensions2.cs | 115 ------------------ .../Context/Extensions/EfGetManyAttribute.cs | 6 + .../Context/Extensions/EfGetOneAttribute.cs | 6 + .../Context/Templates/AddToListInEntity.csx | 0 4 files changed, 12 insertions(+), 115 deletions(-) delete mode 100644 BlueWest.Api/Context/Extensions/CountryExtensions2.cs create mode 100644 BlueWest.Api/Context/Extensions/EfGetManyAttribute.cs create mode 100644 BlueWest.Api/Context/Extensions/EfGetOneAttribute.cs create mode 100644 BlueWest.Api/Context/Templates/AddToListInEntity.csx diff --git a/BlueWest.Api/Context/Extensions/CountryExtensions2.cs b/BlueWest.Api/Context/Extensions/CountryExtensions2.cs deleted file mode 100644 index 62d6588..0000000 --- a/BlueWest.Api/Context/Extensions/CountryExtensions2.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Linq; -using System.Linq.Expressions; -using System.Threading.Tasks; -using BlueWest.Data; -using Microsoft.EntityFrameworkCore; - -namespace BlueWest.WebApi.EF -{ - /// - /// Country table database extensions - /// - public static class CountryExtensions2 - { - - /// - /// Add a new country - /// - /// - /// - /// - /*public static (bool, CountryUnique) AddCountry(this CountryDbContext dbContext, CountryCreate countryCreate) - { - Country newCountry = new Country(countryCreate); - dbContext.Countries.Add(newCountry); - bool success = dbContext.SaveChanges() >= 0; - return (success, new CountryUnique(newCountry)); - } */ - /// - /// Updates a country data. - /// - /// DbContext. - /// Country data to update. - /// Country Id. - /// - /*public static (bool, Country) UpdateCountry( - this CountryDbContext dbContext, - CountryUpdate countryUpdate, - int countryId) - { - var country = dbContext.Countries.FirstOrDefault(x => x.Id == countryId); - if (country == null) return (false, null); - country.Update(countryUpdate); - dbContext.Countries.Update(country); - var result = dbContext.SaveChanges() >= 0; - return (result, country); - - }*/ - - /// - /// Adds a new Currency to the specified country - /// - /// - /// - /// - /// - /*public static (bool, string, CurrencyUnique) AddCurrency( - this CountryDbContext dbContext, - int countryId, - CurrencyCreate currencyCreate) - { - var country = dbContext.Countries.FirstOrDefault(d => d.Id == countryId); - - // Check if currency exists - if (country == null) return (false, "Country Not found.", null); - - // Creates new currency - var newCurrency = new Currency(currencyCreate); - country.Currencies.Add(newCurrency); - var success = dbContext.SaveChanges() >= 0; - - return !success ? (false, "Error saving the changes in the database.", null) : (true, string.Empty, new CurrencyUnique(newCurrency)); - }*/ - // country add (add currency) currency create, duplicatioon Validations - - /// - /// Add Currency with optional duplication checks - /// - /// - /// Country Id - /// Data to create currency - /// List of expressions - /// - /*public static (bool, string, CurrencyUnique) AddCurrency( - this CountryDbContext dbContext, - int countryId, CurrencyCreate currencyCreate, - Expression>[] duplicationValidations) - { - - var countryQuery = from aCountry in dbContext.Countries - where aCountry.Id == countryId - let currencies = aCountry.Currencies - select aCountry; - - var country = countryQuery.FirstOrDefault(); - - if (country == null) return (false, $"{nameof(country)} Not found.", null); - - foreach (var duplicationValidation in duplicationValidations) - { - var currencyToGet = dbContext.Currencies.FirstOrDefault(duplicationValidation); - if (currencyToGet != null) - { - return (false, $"Duplication Validation failed: {nameof(duplicationValidation.Body.ToString)}", null); - } - } - - var newCurrency = new Currency(currencyCreate); - country.Currencies.Add(newCurrency); - var success = dbContext.SaveChanges() >= 0; - return !success ? (false, "Error saving the changes in the database.", null) : (true, string.Empty, new CurrencyUnique(newCurrency)); - }*/ - } -} - diff --git a/BlueWest.Api/Context/Extensions/EfGetManyAttribute.cs b/BlueWest.Api/Context/Extensions/EfGetManyAttribute.cs new file mode 100644 index 0000000..f3d878f --- /dev/null +++ b/BlueWest.Api/Context/Extensions/EfGetManyAttribute.cs @@ -0,0 +1,6 @@ +namespace BlueWest.WebApi.EF; + +public class EfGetManyAttribute +{ + +} \ No newline at end of file diff --git a/BlueWest.Api/Context/Extensions/EfGetOneAttribute.cs b/BlueWest.Api/Context/Extensions/EfGetOneAttribute.cs new file mode 100644 index 0000000..6873f90 --- /dev/null +++ b/BlueWest.Api/Context/Extensions/EfGetOneAttribute.cs @@ -0,0 +1,6 @@ +namespace BlueWest.WebApi.EF; + +public class EfGetOneAttribute +{ + +} \ No newline at end of file diff --git a/BlueWest.Api/Context/Templates/AddToListInEntity.csx b/BlueWest.Api/Context/Templates/AddToListInEntity.csx new file mode 100644 index 0000000..e69de29