using AyCode.Utils.Extensions; using Microsoft.EntityFrameworkCore; using TIAM.Database.DbSets.Transfers; using TIAM.Entities.ServiceProviders; using TIAM.Entities.Transfers; namespace TIAM.Database.DbSets.ServiceProvider; public static class ServiceProviderDbSetExtensions { #region Add, Update, Remove public static bool AddServiceProvider(this IServiceProviderDbSet ctx, Company company) { var companyProfile = company.Profile; if (company.ProfileId.IsNullOrEmpty() || companyProfile.Id != company.ProfileId || companyProfile.AddressId.IsNullOrEmpty() || companyProfile.Address.Id != companyProfile.AddressId) { return false; } if (!company.OwnerId.IsNullOrEmpty()) { } return 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 GetServiceProviders(this IServiceProviderDbSet ctx) => ctx.ServiceProviders; public static List GetServiceProvidersByOwnerId(this IServiceProviderDbSet ctx, Guid ownerId) => ctx.ServiceProviders.Where(x => x.OwnerId == ownerId).ToList(); }