diff --git a/BlueWest.Api/Context/CompanyDbContext.cs b/BlueWest.Api/Context/CompanyDbContext.cs
index 818e84d..19278e9 100644
--- a/BlueWest.Api/Context/CompanyDbContext.cs
+++ b/BlueWest.Api/Context/CompanyDbContext.cs
@@ -17,6 +17,7 @@ namespace BlueWest.WebApi.EF
/// Companies.
///
[EfAddMethods(typeof(CompanyCreate), typeof(CompanyUnique))]
+
[EfUpdateMethods(
updateType: typeof(CompanyUpdate),
returnType: typeof(CompanyUnique),
@@ -32,6 +33,7 @@ namespace BlueWest.WebApi.EF
/// Industries.
///
[EfAddMethods(typeof(IndustryCreate), typeof(IndustryUnique))]
+
[EfUpdateMethods(
updateType: typeof(IndustryUpdate),
returnType: typeof(IndustryUnique),
@@ -43,10 +45,26 @@ namespace BlueWest.WebApi.EF
#endregion
+ #region Products
+
+ ///
+ /// Products
+ ///
+
+ [EfAddMethods(typeof(ProductCreate), typeof(ProductUnique))]
+
+ [EfUpdateMethods(
+ updateType: typeof(ProductUpdate),
+ returnType: typeof(ProductUnique),
+ keyPropertyMemberName: nameof(Product.Id)
+ )
+ ]
+
public DbSet Products { get; set; }
+ #endregion
-
-
+ #region Initialization
+
///
/// CompanyDbContext constructor.
///
@@ -66,6 +84,9 @@ namespace BlueWest.WebApi.EF
modelBuilder.ConfigureCurrentDbModel();
}
+ #endregion
+
+
}
}
diff --git a/BlueWest.Api/Context/Extensions/CurrencyExtensions.cs b/BlueWest.Api/Context/Extensions/CurrencyExtensions.cs
deleted file mode 100644
index 5bb1bc4..0000000
--- a/BlueWest.Api/Context/Extensions/CurrencyExtensions.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-using System;
-using System.Linq;
-using System.Linq.Expressions;
-using BlueWest.Data;
-using Microsoft.EntityFrameworkCore;
-
-namespace BlueWest.WebApi.EF
-{
- ///
- /// Currency table data extensions
- ///
- public static partial class CurrencyExtensions
- {
-
- ///
- /// Add new Currency
- ///
- ///
- ///
- ///
- /*
- public static (bool, Currency) AddCurrency(this CountryDbContext dbContext, CurrencyCreate currencyToCreate)
- {
- var newCurrency = new Currency(currencyToCreate);
- dbContext.Add(newCurrency);
- var resultOperation = dbContext.SaveChanges() >= 0;
- return (resultOperation, newCurrency);
- }
- */
-
-
- ///
- /// Updates currency
- ///
- ///
- ///
- ///
- ///
- /*public static (bool, Currency) UpdateCurrency(this CountryDbContext dbContext, int currencyId, CurrencyUpdate currencyToUpdate)
- {
- var currency = dbContext.Currencies.SingleOrDefault(x => x.Id == currencyId);
- if (currency == null) return (false, null);
- currency.Update(currencyToUpdate);
- dbContext.Update(currency);
- var resultOperation = dbContext.SaveChanges() >= 0;
- return (resultOperation, currency);
-
- }*/
-
- ///
- /// Add Country associated with specified Currency.
- ///
- ///
- ///
- ///
- ///
- ///
- /*public static (bool, string, CountryUnique) AddCountry(
- this CountryDbContext dbContext,
- int currencyId, CountryCreate countryCreate,
- Expression>[] duplicationValidations)
- {
-
- var queryable = from aCurrency in dbContext.Currencies
- where aCurrency.Id == currencyId
- select aCurrency;
-
- queryable.Include(x => x.Countries);
-
- var currency = queryable.SingleOrDefault();
-
- // Check if currency exists
- if (currency == null) return (false, $"{nameof(Currency)}: {currencyId} - Not found.", null);
-
- // Check if there's currency with the same code
- foreach (var duplicationValidation in duplicationValidations)
- {
- var countryToCheck = dbContext.Countries.FirstOrDefault(duplicationValidation);
-
- if (countryToCheck != null)
- {
- return (false, $"Duplication Validation failed: {duplicationValidation.Body}", null);
- }
- }
-
- // Creates new currency
- var newCountry = new Country(countryCreate);
- currency.Countries.Add(newCountry);
- var success = dbContext.SaveChanges() >= 0;
- return (success, string.Empty, new CountryUnique(newCountry));
- }*/
-
- }
-}
-
diff --git a/BlueWest.Api/Context/Extensions/EfAddEntityToListAttribute.cs b/BlueWest.Api/Context/Extensions/EfAddEntityToListAttribute.cs
deleted file mode 100644
index bbded21..0000000
--- a/BlueWest.Api/Context/Extensions/EfAddEntityToListAttribute.cs
+++ /dev/null
@@ -1,9 +0,0 @@
-using System;
-
-namespace BlueWest.WebApi.EF;
-
-[AttributeUsage(AttributeTargets.Property)]
-public class EfAddEntityToListAttribute : Attribute
-{
- public EfAddEntityToListAttribute(Type listEntityType, Type listEntityCreateType, Type listEntityReturnType, string keyMembernameof) { }
-}
\ No newline at end of file
diff --git a/BlueWest.Api/Context/Templates/GetManyTemplate.csx b/BlueWest.Api/Context/Templates/GetManyTemplate.csx
index d9951db..9c28bc6 100644
--- a/BlueWest.Api/Context/Templates/GetManyTemplate.csx
+++ b/BlueWest.Api/Context/Templates/GetManyTemplate.csx
@@ -7,7 +7,7 @@
/// Optional Order direction
/// Optional where predicate.
/// Optional order by predicate.
-/// A bool if the result is successfull, and the first occurrence of {entityTypeName}>
+/// A bool if the result is successful and has at least 1 occurrence of {propertyName}.
public static (bool, {returnTypeFullName}[]) Get{propertyName}(this {contextFullName} dbContext, int skip = 0, int take = 50, int orderDir = 1,
Expression > where = null,
Expression > orderBy = null)
diff --git a/BlueWest.Api/Context/Templates/GetOneByTemplate.csx b/BlueWest.Api/Context/Templates/GetOneByTemplate.csx
index 01f74ed..6f72f4c 100644
--- a/BlueWest.Api/Context/Templates/GetOneByTemplate.csx
+++ b/BlueWest.Api/Context/Templates/GetOneByTemplate.csx
@@ -2,7 +2,7 @@
/// Gets the first result in the table, and returns a projection of
///
/// The database context.
-/// By {byParamPropertyName} parameter type.
+/// By {byParamPropertyName} parameter type.
/// A bool if the result is successfull, and the first occurrence of {entityTypeName}>
public static (bool, {returnTypeFullName}) GetOne{entityTypeName}By{byParamPropertyName} (this {contextFullName} dbContext, {byParamFullType} {byParamVarName})
diff --git a/BlueWest.Api/Context/Templates/GetOneTemplate.csx b/BlueWest.Api/Context/Templates/GetOneTemplate.csx
index cba3955..0462426 100644
--- a/BlueWest.Api/Context/Templates/GetOneTemplate.csx
+++ b/BlueWest.Api/Context/Templates/GetOneTemplate.csx
@@ -3,7 +3,7 @@
///
/// The database context.
/// FirstOrDefault argument to pass.
-/// A bool if the result is successfull, and the first occurrence of {returnTypeName}
+/// A bool if the first occurrence of {returnTypeName} is returned.
public static (bool, {returnTypeFullName}) Get{entityTypeName}With (this {contextFullName} dbContext, Expression> with)
{
diff --git a/BlueWest.Api/Context/Templates/UpdateEntityTemplate.csx b/BlueWest.Api/Context/Templates/UpdateEntityTemplate.csx
index 9433679..99cb497 100644
--- a/BlueWest.Api/Context/Templates/UpdateEntityTemplate.csx
+++ b/BlueWest.Api/Context/Templates/UpdateEntityTemplate.csx
@@ -3,6 +3,7 @@
///
/// Database context
/// The data type with the add data to update {entityTypeName}
+/// The primary key.
/// Returns the current data.
public static (bool, {returnTypeFullName}) Update{entityTypeName}( this {contextFullName} dbContext, {updateTypeFullName} {updateVarName}, {keyTypeFullName} {keyVarName})
{
diff --git a/BlueWest.Api/Controllers/CurrencyController.cs b/BlueWest.Api/Controllers/CurrencyController.cs
index 5f850d7..5bcb7dd 100644
--- a/BlueWest.Api/Controllers/CurrencyController.cs
+++ b/BlueWest.Api/Controllers/CurrencyController.cs
@@ -79,14 +79,12 @@ namespace BlueWest.WebApi.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[HttpGet("{currencyCode}", Name = nameof(GetCurrencyWithCode))]
- public ActionResult GetCurrencyWithCode(Expression> with)
+ public ActionResult GetCurrencyWithCode(string currencyCode)
{
- var currency =
- _dbContext.Currencies
- .Select(currency => new CurrencyUnique(currency))
- .FirstOrDefault(with);
+ var (success, currency) =
+ _dbContext.GetCurrencyWith(x => x.Code == currencyCode);
- if (currency != null)
+ if (success)
{
return Ok(currency);
}
diff --git a/BlueWest.Api/Dockerfile b/BlueWest.Api/Dockerfile
index f39653f..46f67a9 100644
--- a/BlueWest.Api/Dockerfile
+++ b/BlueWest.Api/Dockerfile
@@ -26,6 +26,11 @@ RUN dotnet restore "BlueWest.Api/BlueWest.Api.csproj"
COPY ["include/BlueWest.MapTo/src/BlueWest.MapTo/BlueWest.MapTo.csproj", "include/BlueWest.MapTo/src/BlueWest.MapTo/"]
RUN dotnet restore "include/BlueWest.MapTo/src/BlueWest.MapTo/BlueWest.MapTo.csproj"
+
+COPY ["include/BlueWest.EfMethods/src/BlueWest.EfMethods/BlueWest.EfMethods.csproj", "include/BlueWest.EfMethods/src/BlueWest.EfMethods/"]
+RUN dotnet restore "include/BlueWest.EfMethods/src/BlueWest.EfMethods/BlueWest.EfMethods.csproj"
+
+
COPY ["include/Math-Expression-Evaluator/SimpleExpressionEvaluator/SimpleExpressionEvaluator.csproj", "include/Math-Expression-Evaluator/SimpleExpressionEvaluator/"]
RUN dotnet restore "include/Math-Expression-Evaluator/SimpleExpressionEvaluator/SimpleExpressionEvaluator.csproj"
diff --git a/BlueWest.Data.Capital/Company/Product/Product.cs b/BlueWest.Data.Capital/Company/Product/Product.cs
index 831883d..2e3570a 100644
--- a/BlueWest.Data.Capital/Company/Product/Product.cs
+++ b/BlueWest.Data.Capital/Company/Product/Product.cs
@@ -3,12 +3,15 @@ using MapTo;
namespace BlueWest.Data
{
- [MapFrom(new []{typeof(ProductUpdate), typeof(ProductCreate)})]
+ [MapFrom(new []{typeof(ProductUpdate), typeof(ProductCreate), typeof(ProductUnique)})]
public partial class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Size { get; set; }
+ public double Price { get; set; }
+
+ public Currency Currency { get; set; }
public Industry Industry { get; set; }
public List Seller { get; set; }
}
diff --git a/BlueWest.Data.Capital/Company/Product/ProductUnique.cs b/BlueWest.Data.Capital/Company/Product/ProductUnique.cs
new file mode 100644
index 0000000..6c88883
--- /dev/null
+++ b/BlueWest.Data.Capital/Company/Product/ProductUnique.cs
@@ -0,0 +1,15 @@
+using MapTo;
+
+namespace BlueWest.Data
+{
+ [MapFrom(typeof(Product))]
+
+ public partial class ProductUnique
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string Size { get; set; }
+ public Industry Industry { get; set; }
+ }
+}
+
diff --git a/include/BlueWest.EfGenerator b/include/BlueWest.EfMethods
similarity index 100%
rename from include/BlueWest.EfGenerator
rename to include/BlueWest.EfMethods