24 lines
858 B
C#
24 lines
858 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using TIAM.Entities.Products;
|
|
|
|
namespace TIAM.Database.DbSets.Products;
|
|
|
|
public static class ProductDbSetExtensins
|
|
{
|
|
#region Add, Update, Remove
|
|
|
|
public static bool AddProduct(this IProductDbSet ctx, Product product)
|
|
=> ctx.Products.Add(product).State == EntityState.Added;
|
|
|
|
#endregion Add, Update, Remove
|
|
|
|
public static IQueryable<Product> ProductsWithUserRelations(this IProductDbSet ctx, bool autoInclude = true)
|
|
=> autoInclude
|
|
? ctx.Products
|
|
.Include(x => x.UserProductMappings)
|
|
.ThenInclude(x => x.User)
|
|
: ctx.Products;
|
|
|
|
public static Product? GetProductById(this IProductDbSet ctx, Guid productId, bool includeUsers = true)
|
|
=> ctx.ProductsWithUserRelations(includeUsers).FirstOrDefault(x => x.Id == productId);
|
|
} |