Merge
This commit is contained in:
commit
88c82e48e0
|
|
@ -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());
|
||||
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ namespace TIAM.Database.DbContexts.Admins
|
|||
|
||||
new EmailMessageEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<EmailMessage>());
|
||||
|
||||
modelBuilder.Entity<Company>().Navigation(e => e.Profile).AutoInclude(true);
|
||||
modelBuilder.Entity<Company>().HasOne(x => x.Profile).WithOne().OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
//modelBuilder.Entity<UserProductToCar>().Ignore(x => x.Id);
|
||||
//modelBuilder.Entity<Car>().Ignore(x => x.Id);
|
||||
////modelBuilder.Entity<UserProductToCars>().Ignore(x => x.Cars);
|
||||
|
|
|
|||
|
|
@ -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,16 +122,16 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
public static bool UpdateServiceProvider(this IAdminDbContext ctx, Company serviceProvider)
|
||||
=> ctx.ServiceProviders.Update(serviceProvider).State == EntityState.Modified;
|
||||
=> ctx.ServiceProviders.Update(serviceProvider).State == EntityState.Modified;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -7,4 +7,18 @@ namespace TIAM.Entities.Addresses;
|
|||
[Table(nameof(Address))]
|
||||
public class Address : AcAddress, IAddress
|
||||
{
|
||||
public Address() : base()
|
||||
{ }
|
||||
|
||||
public Address(Guid id) : base(id)
|
||||
{
|
||||
}
|
||||
|
||||
public Address(Guid id, string? addressText) : base(id, addressText)
|
||||
{
|
||||
}
|
||||
|
||||
public Address(Guid id, double? latitude, double? longitude, string? addressText) : base(id, latitude, longitude, addressText)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -7,5 +7,12 @@ namespace TIAM.Entities.Profiles;
|
|||
[Table(nameof(Profile))]
|
||||
public class Profile : AcProfile<Address>, IProfile<Address>
|
||||
{
|
||||
|
||||
public Profile() : base()
|
||||
{ }
|
||||
|
||||
public Profile(Guid id) : base(id)
|
||||
{ }
|
||||
|
||||
public Profile(Guid id, string name) : base(id, name)
|
||||
{ }
|
||||
}
|
||||
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
@ -152,10 +152,7 @@ namespace TIAMSharedUI.Pages.Components
|
|||
//the following line creates a lambda expression that returns the value of the property
|
||||
var lambda = Expression.Lambda(typeof(Func<>).MakeGenericType(property.PropertyType), access);
|
||||
|
||||
_logger.DetailConditional($"{property.Name}, {property.GetType().FullName}");
|
||||
_logger.DetailConditional(lambda.ToString());
|
||||
|
||||
_logger.DetailConditional($"lambda: {lambda.ToString()}");
|
||||
_logger.DetailConditional($"{property.Name}, {property.GetType().FullName}; lambda: {lambda.ToString()}");
|
||||
|
||||
layoutItemBuilder.OpenElement(i++, "div");//open div
|
||||
layoutItemBuilder.AddAttribute(i++, "id", stepId.ToString());
|
||||
|
|
@ -508,7 +505,7 @@ namespace TIAMSharedUI.Pages.Components
|
|||
layoutItemBuilder.CloseElement();
|
||||
|
||||
|
||||
_logger.DetailConditional($"loop {k}, length: {length}, formSteps: {FormSteps.Count} ");
|
||||
//_logger.DetailConditional($"loop {k}, length: {length}, formSteps: {FormSteps.Count} ");
|
||||
k++;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,36 +3,23 @@ using Microsoft.AspNetCore.Mvc;
|
|||
using QRCoder;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using AyCode.Core.Server.Loggers;
|
||||
using TIAM.Database.DataLayers.Admins;
|
||||
//using TIAM.Database.DataLayers.ServiceProviders;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAMWebApp.Shared.Application.Models;
|
||||
using Product = TIAM.Entities.Products.Product;
|
||||
using TIAM.Entities.Transfers;
|
||||
using System.Text.Json.Nodes;
|
||||
using System.Text.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using TIAM.Entities.Profiles;
|
||||
using TIAM.Entities.Addresses;
|
||||
using TIAM.Entities.Profiles;
|
||||
using AyCode.Core.Loggers;
|
||||
|
||||
namespace TIAMWebApp.Server.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/v1/[controller]")]
|
||||
public class ServiceProviderAPIController : ControllerBase
|
||||
public class ServiceProviderAPIController(AdminDal adminDal, IEnumerable<IAcLogWriterBase> logWriters) : ControllerBase
|
||||
{
|
||||
private readonly AdminDal _adminDal;
|
||||
|
||||
private readonly ILogger<ServiceProviderAPIController> _logger;
|
||||
|
||||
public ServiceProviderAPIController(ILogger<ServiceProviderAPIController> logger, AdminDal adminDal)
|
||||
{
|
||||
_logger = logger;
|
||||
_adminDal = adminDal;
|
||||
}
|
||||
private readonly TIAM.Core.Loggers.Logger<ServiceProviderAPIController> _logger = new(logWriters.ToArray());
|
||||
|
||||
//15.
|
||||
[AllowAnonymous]
|
||||
|
|
@ -42,7 +29,8 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[EndpointSummary("Create service provider")]
|
||||
public async Task<IActionResult> CreateServiceProvider([FromBody] ServiceProviderModel serializedServiceProviderModel)
|
||||
{
|
||||
GlobalLogger.Info(@"CreateUser called");
|
||||
_logger.Info(@"CreateServiceProvider called");
|
||||
|
||||
//if (serializedServiceProviderModel.GetArrayLength() == 0)
|
||||
if (serializedServiceProviderModel == null)
|
||||
{
|
||||
|
|
@ -55,21 +43,13 @@ namespace TIAMWebApp.Server.Controllers
|
|||
var serviceProvider = serializedServiceProviderModel;
|
||||
if (serviceProvider != null)
|
||||
{
|
||||
|
||||
|
||||
var id = Guid.NewGuid();
|
||||
var name = serviceProvider.Name;
|
||||
var commissionRate = serviceProvider.CommissionPercent;
|
||||
Guid ownerId;
|
||||
if(serviceProvider.OwnerId == Guid.Empty)
|
||||
{
|
||||
//no owner set yet
|
||||
ownerId = serviceProvider.OwnerId;
|
||||
}
|
||||
else
|
||||
{
|
||||
ownerId = serviceProvider.OwnerId;
|
||||
}
|
||||
|
||||
|
||||
//no owner set yet
|
||||
var ownerId = serviceProvider.OwnerId == Guid.Empty ? null : serviceProvider.OwnerId;
|
||||
|
||||
if (name is null)
|
||||
{
|
||||
|
|
@ -78,14 +58,17 @@ namespace TIAMWebApp.Server.Controllers
|
|||
else
|
||||
{
|
||||
|
||||
GlobalLogger.Info($@"ServiceProvider to be created: {id}, {name}, {ownerId}");
|
||||
Company toCreate = new Company(id, name, ownerId, Guid.NewGuid());
|
||||
toCreate.Profile = new Profile();
|
||||
toCreate.Profile.Id = Guid.NewGuid();
|
||||
toCreate.Profile.Address = new Address();
|
||||
toCreate.Profile.Address.Id = Guid.NewGuid();
|
||||
toCreate.CommissionPercent = commissionRate;
|
||||
var result = await _adminDal.CreateServiceProviderAsync(toCreate);
|
||||
_logger.Info($@"ServiceProvider to be creating; id: {id}, name: {name}, ownerId: {ownerId}");
|
||||
|
||||
var toCreate = new Company(id, name, ownerId, Guid.NewGuid())
|
||||
{
|
||||
CommissionPercent = commissionRate
|
||||
};
|
||||
|
||||
toCreate.SetProfile(new Profile(Guid.NewGuid(), toCreate.Name));
|
||||
toCreate.Profile.SetAddress(new Address(Guid.NewGuid(), "Controller CreateServiceProvider; address text..."));
|
||||
|
||||
var result = await adminDal.CreateServiceProviderAsync(toCreate);
|
||||
if (!result)
|
||||
{
|
||||
serviceProvider = null;
|
||||
|
|
@ -113,7 +96,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.GetServiceProvidersRouteName)]
|
||||
public async Task<string> GetServiceProviders()
|
||||
{
|
||||
return await _adminDal.GetServiceProvidersJsonAsync();
|
||||
return await adminDal.GetServiceProvidersJsonAsync();
|
||||
}
|
||||
|
||||
//18.
|
||||
|
|
@ -122,9 +105,9 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.GetServiceProviderByIdRouteName)]
|
||||
public async Task<Company?> GetServiceProviderById([FromBody] Guid id)
|
||||
{
|
||||
GlobalLogger.Info($@"GetServiceProviderById called with id: {id}");
|
||||
_logger.Info($@"GetServiceProviderById called with id: {id}");
|
||||
|
||||
return await _adminDal.GetServiceProviderByIdAsync(id);
|
||||
return await adminDal.GetServiceProviderByIdAsync(id);
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
|
@ -132,17 +115,11 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.UpdateServiceProviderRouteName)]
|
||||
public async Task<Company> UpdateServiceProvider(Company companyToModify)
|
||||
{
|
||||
GlobalLogger.Info($"UpdateServiceProvider called! + {companyToModify.Id}");
|
||||
var result = await _adminDal.UpdateServiceProviderAsync(companyToModify);
|
||||
if(result)
|
||||
{
|
||||
return companyToModify;
|
||||
_logger.Info($"UpdateServiceProvider called! + {companyToModify.Id}");
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var result = await adminDal.UpdateServiceProviderAsync(companyToModify);
|
||||
|
||||
return result ? companyToModify : null;
|
||||
}
|
||||
|
||||
//17.
|
||||
|
|
@ -152,9 +129,9 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("Finished", "ServiceProvider")]
|
||||
public async Task<Dictionary<Guid, string>> GetServiceProvidersByOwnerId([FromBody] Guid ownerId)
|
||||
{
|
||||
GlobalLogger.Info($@"GetServiceProvidersByOwnerId called with ownerId: {ownerId}");
|
||||
_logger.Info($@"GetServiceProvidersByOwnerId called with ownerId: {ownerId}");
|
||||
|
||||
var serviceProviders = await _adminDal.GetServiceProvidersAsync();
|
||||
var serviceProviders = await adminDal.GetServiceProvidersAsync();
|
||||
|
||||
//return serviceProviders.Where(x => x.OwnerId == ownerId).ToList();
|
||||
var myServiceproviders = serviceProviders.Where(x => x.OwnerId == ownerId).ToDictionary(x => x.Id, x => x.Name);
|
||||
|
|
@ -177,11 +154,11 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
GlobalLogger.Info($@"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
||||
_logger.Info($@"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
||||
|
||||
var userProductMapping = new UserProductMapping(createUserProductMappingModel.ContextId, createUserProductMappingModel.ContextId);
|
||||
|
||||
var result = await _adminDal.AddUserProductMappingAsync(userProductMapping);
|
||||
var result = await adminDal.AddUserProductMappingAsync(userProductMapping);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
|
@ -193,11 +170,11 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Route(APIUrls.GetUserProductMappingsForProductRouteName)]
|
||||
public async Task<Dictionary<Guid, string>> GetUserProductMappingsForProduct(Guid serviceProviderId)
|
||||
{
|
||||
GlobalLogger.Info($@"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
||||
_logger.Info($@"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
||||
|
||||
var userProductMappingDictionary = new Dictionary<Guid, string>();
|
||||
|
||||
var serviceProviders = await _adminDal.GetServiceProvidersAsync();
|
||||
var serviceProviders = await adminDal.GetServiceProvidersAsync();
|
||||
|
||||
var myServiceproviders = serviceProviders.Where(x => x.Id == serviceProviderId).ToDictionary(x => x.Id, x => x.Name);
|
||||
//put serviceprovider id and name into a dictionary
|
||||
|
|
@ -210,14 +187,15 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("In-Progress", "Product")]
|
||||
public async Task<IActionResult> AddProduct([FromBody] Product product)
|
||||
{
|
||||
GlobalLogger.Info(@"AddProduct called");
|
||||
_logger.Info(@"AddProduct called");
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
return BadRequest("Product is required");
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = _adminDal.AddProductAsync(product);
|
||||
var result = adminDal.AddProductAsync(product);
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
|
|
@ -228,7 +206,8 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("In-Progress", "Product")]
|
||||
public async Task<IActionResult> GetQRCodeByProductId([FromBody] Guid productId)
|
||||
{
|
||||
GlobalLogger.Info(@"GetQRCode called");
|
||||
_logger.Info(@"GetQRCode called");
|
||||
|
||||
if (productId == Guid.Empty)
|
||||
{
|
||||
return BadRequest("Product is required");
|
||||
|
|
@ -243,7 +222,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
//Bitmap qrCodeImage = qrCode.GetGraphic(20);
|
||||
var rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "assets");
|
||||
var qrCodeImage = qrCode.GetGraphic(20, Color.DarkMagenta, Color.White, (Bitmap)Bitmap.FromFile(rootpath + "/myimage.png"));
|
||||
GlobalLogger.Info($@"qrCodeLogo: {rootpath}/myimage.png");
|
||||
_logger.Info($@"qrCodeLogo: {rootpath}/myimage.png");
|
||||
var ms = new MemoryStream();
|
||||
qrCodeImage.Save(ms, ImageFormat.Jpeg);
|
||||
var byteImage = ms.ToArray();
|
||||
|
|
@ -260,7 +239,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("In-Progress", "Product")]
|
||||
public IActionResult GetProductsByServiceProviderId([FromBody] Guid serviceProviderId)
|
||||
{
|
||||
GlobalLogger.Info($@"GetProductsByServiceProviderId called with serviceProviderId: {serviceProviderId}");
|
||||
_logger.Info($@"GetProductsByServiceProviderId called with serviceProviderId: {serviceProviderId}");
|
||||
|
||||
if (serviceProviderId == Guid.Empty)
|
||||
{
|
||||
|
|
@ -268,7 +247,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
}
|
||||
else
|
||||
{
|
||||
var products = _adminDal.GetProductsJsonByServiceProviderId(serviceProviderId);
|
||||
var products = adminDal.GetProductsJsonByServiceProviderId(serviceProviderId);
|
||||
if (products != null)
|
||||
{
|
||||
return Ok(products);
|
||||
|
|
@ -290,9 +269,9 @@ namespace TIAMWebApp.Server.Controllers
|
|||
[Tags("In-Progress", "Product")]
|
||||
public async Task<string> GetAllProducts()
|
||||
{
|
||||
GlobalLogger.Info("GetAllProducts called");
|
||||
_logger.Info("GetAllProducts called");
|
||||
|
||||
var products = _adminDal.GetProductsJson();
|
||||
var products = adminDal.GetProductsJson();
|
||||
if (products != null)
|
||||
{
|
||||
return products;
|
||||
|
|
|
|||
|
|
@ -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