36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using TIAM.Entities.ServiceProviders;
|
|
|
|
|
|
namespace TIAM.Database.DbSets.ServiceProvider;
|
|
|
|
public static class ServiceProviderDbSetExtensions
|
|
{
|
|
#region Add, Update, Remove
|
|
|
|
public static bool AddServiceProvider(this IServiceProviderDbSet ctx, Company company)
|
|
=> ctx.ServiceProviders.Add(company).State == EntityState.Added;
|
|
|
|
public static bool RemoveServiceProvider(this IServiceProviderDbSet ctx, Company company)
|
|
=> ctx.ServiceProviders.Remove(company).State == EntityState.Deleted;
|
|
|
|
public static bool RemoveServiceProvider(this IServiceProviderDbSet ctx, Guid companyId)
|
|
{
|
|
var company = ctx.GetServiceProviderById(companyId);
|
|
return company == null || ctx.RemoveServiceProvider(company);
|
|
}
|
|
|
|
#endregion Add, Update, Remove
|
|
|
|
public static Company? GetServiceProviderById(this IServiceProviderDbSet ctx, Guid companyId)
|
|
=> ctx.ServiceProviders.FirstOrDefault(x => x.Id == companyId);
|
|
|
|
public static IQueryable<Company> GetServiceProviders(this IServiceProviderDbSet ctx)
|
|
=> ctx.ServiceProviders;
|
|
|
|
public static List<Company> GetServiceProvidersByOwnerId(this IServiceProviderDbSet ctx, Guid ownerId)
|
|
=> ctx.ServiceProviders.Where(x => x.OwnerId == ownerId).ToList();
|
|
|
|
|
|
|
|
} |