Compare commits
2 Commits
269e8bd679
...
6f2b3b915f
| Author | SHA1 | Date |
|---|---|---|
|
|
6f2b3b915f | |
|
|
ceb46f215b |
|
|
@ -225,13 +225,13 @@ namespace TIAM.Database.DataLayers.Admins
|
|||
//15. (IServiceProviderDataService) Create service provider
|
||||
public Task<bool> CreateServiceProviderAsync(Company serviceProvider) => TransactionAsync(ctx => ctx.AddServiceProvider(serviceProvider));
|
||||
|
||||
public bool CreateProductAsync(Product product)
|
||||
{
|
||||
Context.CreateProduct(product);
|
||||
GlobalLogger.Info($@"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}");
|
||||
var result = Context.SaveChangesAsync();
|
||||
return result.Result > 0;
|
||||
}
|
||||
//public bool CreateProductAsync(Product product)
|
||||
//{
|
||||
// Context.CreateProduct(product);
|
||||
// GlobalLogger.Info($@"Saving product to db {product.Id}, {product.Name}, {product.ServiceProviderId}");
|
||||
// var result = Context.SaveChangesAsync();
|
||||
// return result.Result > 0;
|
||||
//}
|
||||
|
||||
public Task<List<Company>> GetServiceProvidersAsync() => SessionAsync(ctx => ctx.GetServiceProviders().ToList());
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using AyCode.Utils.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Database.DbSets.Permissions;
|
||||
using TIAM.Database.DbSets.Products;
|
||||
using TIAM.Database.DbSets.Transfers;
|
||||
|
|
@ -97,10 +98,13 @@ namespace TIAM.Database.DbContexts.Admins
|
|||
public static bool CreateProduct(this IAdminDbContext ctx, Product myproduct)
|
||||
{
|
||||
if (myproduct == null) return false;
|
||||
|
||||
//Automatically add assigneduser for owner
|
||||
Company? productOwner = ctx.ServiceProviders.FirstOrDefault(x => x.Id == myproduct.ServiceProviderId);
|
||||
if (productOwner == null) return false;
|
||||
var userProductMapping = new UserProductMapping(myproduct.Id, productOwner.OwnerId);
|
||||
Company? company = ctx.ServiceProviders.FirstOrDefault(x => x.Id == myproduct.ServiceProviderId);
|
||||
if (company == null || company.OwnerId.IsNullOrEmpty()) return false;
|
||||
|
||||
var userProductMapping = new UserProductMapping(myproduct.Id, company.OwnerId.Value);
|
||||
|
||||
ctx.CreateAssignedUser(userProductMapping);
|
||||
ctx.AddProduct(myproduct);
|
||||
|
||||
|
|
@ -118,10 +122,10 @@ namespace TIAM.Database.DbContexts.Admins
|
|||
|
||||
public static Company CreateServiceProvider(this IAdminDbContext ctx, Company serviceProvider)
|
||||
{
|
||||
if (serviceProvider == null) return null;
|
||||
if (serviceProvider == null || serviceProvider.OwnerId.IsNullOrEmpty()) return null;
|
||||
|
||||
ctx.ServiceProviders.Add(serviceProvider);
|
||||
var userProductMapping = new UserProductMapping(serviceProvider.Id, serviceProvider.OwnerId);
|
||||
var userProductMapping = new UserProductMapping(serviceProvider.Id, serviceProvider.OwnerId.Value);
|
||||
ctx.CreateAssignedUser(userProductMapping);
|
||||
return serviceProvider;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using AyCode.Utils.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Database.DbSets.Transfers;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Transfers;
|
||||
|
|
@ -11,7 +12,21 @@ public static class ServiceProviderDbSetExtensions
|
|||
#region Add, Update, Remove
|
||||
|
||||
public static bool AddServiceProvider(this IServiceProviderDbSet ctx, Company company)
|
||||
=> ctx.ServiceProviders.Add(company).State == EntityState.Added;
|
||||
{
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class Company : AcCompany<User, UserToCompany, Profile>, ICompany<User, U
|
|||
{
|
||||
}
|
||||
|
||||
public Company(Guid id, string name, Guid ownerId, Guid affiliateId) : base(id, name, ownerId, affiliateId)
|
||||
public Company(Guid id, string name, Guid? ownerId, Guid affiliateId) : base(id, name, ownerId, affiliateId)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -46,10 +46,10 @@ namespace TIAMWebApp.Server.Controllers
|
|||
var id = Guid.NewGuid();
|
||||
var name = serviceProvider.Name;
|
||||
var commissionRate = serviceProvider.CommissionPercent;
|
||||
Guid ownerId;
|
||||
|
||||
|
||||
//no owner set yet
|
||||
ownerId = serviceProvider.OwnerId == Guid.Empty ? serviceProvider.OwnerId : serviceProvider.OwnerId;
|
||||
var ownerId = serviceProvider.OwnerId == Guid.Empty ? null : serviceProvider.OwnerId;
|
||||
|
||||
if (name is null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ namespace TIAMWebApp.Shared.Application.Models
|
|||
{
|
||||
public Guid Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public Guid OwnerId { get; set; }
|
||||
public Guid? OwnerId { get; set; }
|
||||
public int CommissionPercent { get; set; }
|
||||
public ServiceProviderModel() { }
|
||||
public ServiceProviderModel(Guid id, string name, Guid ownerId, int commissionPercent)
|
||||
public ServiceProviderModel(Guid id, string name, Guid? ownerId, int commissionPercent)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
|
|
|
|||
Loading…
Reference in New Issue