Compare commits

..

No commits in common. "6f2b3b915f9d106238a0967312c0097a2f1f9f57" and "269e8bd67952fb188335eed389192891437c26ed" have entirely different histories.

6 changed files with 20 additions and 39 deletions

View File

@ -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());

View File

@ -1,5 +1,4 @@
using AyCode.Utils.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbSets.Permissions;
using TIAM.Database.DbSets.Products;
using TIAM.Database.DbSets.Transfers;
@ -98,13 +97,10 @@ 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? 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);
Company? productOwner = ctx.ServiceProviders.FirstOrDefault(x => x.Id == myproduct.ServiceProviderId);
if (productOwner == null) return false;
var userProductMapping = new UserProductMapping(myproduct.Id, productOwner.OwnerId);
ctx.CreateAssignedUser(userProductMapping);
ctx.AddProduct(myproduct);
@ -122,10 +118,10 @@ namespace TIAM.Database.DbContexts.Admins
public static Company CreateServiceProvider(this IAdminDbContext ctx, Company serviceProvider)
{
if (serviceProvider == null || serviceProvider.OwnerId.IsNullOrEmpty()) return null;
if (serviceProvider == null) return null;
ctx.ServiceProviders.Add(serviceProvider);
var userProductMapping = new UserProductMapping(serviceProvider.Id, serviceProvider.OwnerId.Value);
var userProductMapping = new UserProductMapping(serviceProvider.Id, serviceProvider.OwnerId);
ctx.CreateAssignedUser(userProductMapping);
return serviceProvider;
}

View File

@ -1,5 +1,4 @@
using AyCode.Utils.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbSets.Transfers;
using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Transfers;
@ -12,21 +11,7 @@ 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;
}
=> ctx.ServiceProviders.Add(company).State == EntityState.Added;
public static bool RemoveServiceProvider(this IServiceProviderDbSet ctx, Company company)
=> ctx.ServiceProviders.Remove(company).State == EntityState.Deleted;

View File

@ -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)
{
}
}

View File

@ -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
var ownerId = serviceProvider.OwnerId == Guid.Empty ? null : serviceProvider.OwnerId;
ownerId = serviceProvider.OwnerId == Guid.Empty ? serviceProvider.OwnerId : serviceProvider.OwnerId;
if (name is null)
{

View File

@ -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;