ServiceProviderModel, CreateServiceProvider improvements...

This commit is contained in:
jozsef.b@aycode.com 2024-06-03 09:27:44 +02:00
parent b140458409
commit 6aad8614b9
3 changed files with 35 additions and 42 deletions

View File

@ -16,15 +16,19 @@ public class Company : AcCompany<User, UserToCompany, Profile, Address>, ICompan
{ {
} }
public Company(string name, Guid ownerId) : this(Guid.NewGuid(), name, ownerId) public Company(string name, Guid? ownerId) : this(Guid.NewGuid(), name, ownerId)
{ {
} }
public Company(Guid id, string name, Guid ownerId) : this(id, name, ownerId, Guid.NewGuid()) public Company(Guid id, string name, Guid? ownerId) : this(id, name, ownerId, Guid.NewGuid())
{ {
} }
public Company(Guid id, string name, Guid? ownerId, double commissionPercent) : this(id, name, ownerId, Guid.NewGuid())
{
CommissionPercent = commissionPercent;
}
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

@ -31,12 +31,11 @@ namespace TIAMWebApp.Server.Controllers
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
private async Task<bool> CompanyDataChanging(Company company, DataChangeMode dataChangeMode) private async Task<bool> CompanyDataChanging(Company company, DataChangeMode dataChangeMode)
{ {
var logText = $"CompanyDataChanging {dataChangeMode} called; id: {company.Id}; ownerId: {company.OwnerId}; Name: {company.Name}"; var logText = $"[{dataChangeMode.ToString().ToUpper()}] CompanyDataChanging called; Id: {company.Id}; OwnerId: {company.OwnerId}; Name: {company.Name}";
if (company.Name.IsNullOrEmpty()) if (company.Name.IsNullOrEmpty())
{ {
_logger.Error(logText); _logger.Error(logText);
return false; return false;
} }
@ -47,6 +46,8 @@ namespace TIAMWebApp.Server.Controllers
case DataChangeMode.Add: case DataChangeMode.Add:
if (company.Id.IsNullOrEmpty()) company.Id = Guid.NewGuid(); if (company.Id.IsNullOrEmpty()) company.Id = Guid.NewGuid();
//if (company.OwnerId.IsNullOrEmpty()) company.OwnerId = Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00"); //TESZT - J.
company.SetProfile(new Profile(Guid.NewGuid(), company.Name)); company.SetProfile(new Profile(Guid.NewGuid(), company.Name));
company.Profile.SetAddress(new Address(Guid.NewGuid(), "Controller AddCompanyAsync; address text...")); company.Profile.SetAddress(new Address(Guid.NewGuid(), "Controller AddCompanyAsync; address text..."));
@ -88,35 +89,11 @@ namespace TIAMWebApp.Server.Controllers
[Route(APIUrls.CreateServiceProviderRouteName)] [Route(APIUrls.CreateServiceProviderRouteName)]
[Tags("In-Progress", "ServiceProvider")] [Tags("In-Progress", "ServiceProvider")]
[EndpointSummary("Create service provider")] [EndpointSummary("Create service provider")]
public async Task<string> CreateServiceProvider([FromBody] ServiceProviderModel? serializedServiceProviderModel) public async Task<string> CreateServiceProvider([FromBody] ServiceProviderModel serializedServiceProviderModel)
{ {
_logger.Info(@"CreateServiceProvider called"); _logger.Info($"CreateServiceProvider called; Id: {serializedServiceProviderModel.Id}");
//if (serializedServiceProviderModel.GetArrayLength() == 0) return await AddCompanyAsync(serializedServiceProviderModel.CreateMainEntity());
if (serializedServiceProviderModel == null)
{
return string.Empty; //BadRequest("SerializedLoginModel is required").ToJson();
}
//Company? serviceProvider = JObject.Parse(serializedServiceProviderModel.GetRawText()).ToObject<Company>();
var serviceProvider = serializedServiceProviderModel;
var id = Guid.NewGuid();
var name = serviceProvider.Name;
var commissionRate = serviceProvider.CommissionPercent;
//no owner set yet
var ownerId = serviceProvider.OwnerId == Guid.Empty ? null : serviceProvider.OwnerId;
//ownerId = Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00"); //TESZT - J.
if (name is null) return string.Empty; //BadRequest("Invalid request");
var company = new Company(id, name, ownerId, Guid.NewGuid())
{
CommissionPercent = commissionRate
};
return await AddCompanyAsync(company);
} }
//16. //16.
@ -244,12 +221,11 @@ namespace TIAMWebApp.Server.Controllers
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
private async Task<bool> CarDataChanging(Car car, DataChangeMode dataChangeMode) private async Task<bool> CarDataChanging(Car car, DataChangeMode dataChangeMode)
{ {
var logText = $"CarDataChanging {dataChangeMode} called; id: {car.Id}; ownerId: {car.UserProductMappingId}; licensePlate: {car.LicencePlate}"; var logText = $"[{dataChangeMode.ToString().ToUpper()}] CarDataChanging called; Id: {car.Id}; OwnerId: {car.UserProductMappingId}; LicensePlate: {car.LicencePlate}";
if (car.UserProductMappingId.IsNullOrEmpty() || car.LicencePlate.IsNullOrWhiteSpace()) if (car.UserProductMappingId.IsNullOrEmpty() || car.LicencePlate.IsNullOrWhiteSpace())
{ {
_logger.Error(logText); _logger.Error(logText);
return false; return false;
} }

View File

@ -1,18 +1,31 @@
namespace TIAMWebApp.Shared.Application.Models using AyCode.Models;
using TIAM.Entities.ServiceProviders;
namespace TIAMWebApp.Shared.Application.Models
{ {
public class ServiceProviderModel public class ServiceProviderModel : AcModelDtoBase<Company>
{ {
public Guid Id { get; set; }
public string? Name { get; set; } public string? Name { get; set; }
public Guid? OwnerId { get; set; } public Guid? OwnerId { get; set; }
public int CommissionPercent { get; set; } public double CommissionPercent { get; set; }
public ServiceProviderModel() { }
public ServiceProviderModel(Guid id, string name, Guid? ownerId, int commissionPercent) public ServiceProviderModel() : base()
{ }
public ServiceProviderModel(Guid id, string name, Guid? ownerId, double commissionPercent) : base(id)
{ {
Id = id;
Name = name; Name = name;
OwnerId = ownerId; OwnerId = ownerId;
CommissionPercent = commissionPercent; CommissionPercent = commissionPercent;
} }
public ServiceProviderModel(ICompanyBase company) : this(company.Id, company.Name, company.OwnerId, company.CommissionPercent)
{
}
public override Company CreateMainEntity()
{
return new Company(Id, Name!, OwnerId, CommissionPercent);
}
} }
} }