Skip to content

Commit

Permalink
Merge pull request #295 from UKGovernmentBEIS/develop
Browse files Browse the repository at this point in the history
Merge  dev to staging
  • Loading branch information
AiswaryaBEIS authored Nov 11, 2024
2 parents 27caeb3 + 10b035e commit dedd145
Show file tree
Hide file tree
Showing 29 changed files with 2,316 additions and 236 deletions.
44 changes: 38 additions & 6 deletions DVSRegister.BusinessLogic/Services/CAB/CabService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DVSRegister.BusinessLogic.Models.CAB;
using DVSRegister.CommonUtility.Email;
using DVSRegister.CommonUtility.Models;
using DVSRegister.CommonUtility.Models.Enums;
using DVSRegister.Data.CAB;
using DVSRegister.Data.Entities;

Expand All @@ -11,13 +12,12 @@ public class CabService : ICabService
{
private readonly ICabRepository cabRepository;
private readonly IMapper automapper;
private readonly IEmailSender emailSender;


public CabService(ICabRepository cabRepository, IMapper automapper, IEmailSender emailSender)
public CabService(ICabRepository cabRepository, IMapper automapper)
{
this.cabRepository = cabRepository;
this.automapper = automapper;
this.emailSender = emailSender;
this.automapper = automapper;
}

public async Task<List<RoleDto>> GetRoles()
Expand Down Expand Up @@ -47,14 +47,46 @@ public async Task<GenericResponse> SaveProviderProfile(ProviderProfileDto provid
return genericResponse;
}

public async Task<GenericResponse> UpdateProviderProfile(ProviderProfileDto providerProfileDto)
public async Task<GenericResponse> UpdateCompanyInfo(ProviderProfileDto providerProfileDto)
{
ProviderProfile providerProfile = new();
automapper.Map(providerProfileDto, providerProfile);
GenericResponse genericResponse = await cabRepository.UpdateProviderProfile(providerProfile);
GenericResponse genericResponse = await cabRepository.UpdateCompanyInfo(providerProfile);
return genericResponse;
}

public async Task<GenericResponse> UpdatePrimaryContact(ProviderProfileDto providerProfileDto)
{
ProviderProfile providerProfile = new();
automapper.Map(providerProfileDto, providerProfile);
GenericResponse genericResponse = await cabRepository.UpdatePrimaryContact(providerProfile);
return genericResponse;
}

public async Task<GenericResponse> UpdateSecondaryContact(ProviderProfileDto providerProfileDto)
{
ProviderProfile providerProfile = new();
automapper.Map(providerProfileDto, providerProfile);
GenericResponse genericResponse = await cabRepository.UpdateSecondaryContact(providerProfile);
return genericResponse;
}

public async Task<GenericResponse> UpdatePublicProviderInformation(ProviderProfileDto providerProfileDto)
{
ProviderProfile providerProfile = new();
automapper.Map(providerProfileDto, providerProfile);
GenericResponse genericResponse = await cabRepository.UpdatePublicProviderInformation(providerProfile);
return genericResponse;
}

public bool CheckCompanyInfoEditable(ProviderProfileDto providerProfileDto)
{
return providerProfileDto.Services == null || providerProfileDto.Services.Count==0 || // services not added ie certificate info not submitted yet
providerProfileDto.Services.All(service => service.CertificateReview == null && service.ServiceStatus == ServiceStatusEnum.Submitted) || //certificate info submitted but review not started
providerProfileDto.Services.All(service => service.CertificateReview == null
|| service.CertificateReview.CertificateReviewStatus != CertificateReviewEnum.Approved); //none of the services has an Approved status;
}

public async Task<GenericResponse> SaveService(ServiceDto serviceDto)
{
Service service = new Service();
Expand Down
6 changes: 5 additions & 1 deletion DVSRegister.BusinessLogic/Services/CAB/ICabService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ public interface ICabService
public Task<List<SupplementarySchemeDto>> GetSupplementarySchemes();
public Task<bool> CheckProviderRegisteredNameExists(string registeredName, int providerId = 0);
public Task<GenericResponse> SaveProviderProfile(ProviderProfileDto providerProfile);
public Task<GenericResponse> UpdateProviderProfile(ProviderProfileDto providerProfileDto);
public Task<GenericResponse> UpdateCompanyInfo(ProviderProfileDto providerProfileDto);
public Task<GenericResponse> UpdatePrimaryContact(ProviderProfileDto providerProfileDto);
public Task<GenericResponse> UpdateSecondaryContact(ProviderProfileDto providerProfileDto);
public Task<GenericResponse> UpdatePublicProviderInformation(ProviderProfileDto providerProfileDto);
public bool CheckCompanyInfoEditable(ProviderProfileDto providerProfileDto);
public Task<GenericResponse> SaveService(ServiceDto serviceDto);
public Task<List<ProviderProfileDto>> GetProviders(int cabId, string searchText = "");
public Task<ProviderProfileDto> GetProvider(int providerId, int cabId);
Expand Down
103 changes: 92 additions & 11 deletions DVSRegister.Data/CAB/CabRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task<bool> CheckProviderRegisteredNameExists(string registeredName,
}
}

public async Task<GenericResponse> UpdateProviderProfile(ProviderProfile providerProfile)
public async Task<GenericResponse> UpdateCompanyInfo(ProviderProfile providerProfile)
{
GenericResponse genericResponse = new();
using var transaction = context.Database.BeginTransaction();
Expand All @@ -100,35 +100,116 @@ public async Task<GenericResponse> UpdateProviderProfile(ProviderProfile provide
if (existingProvider !=null)
{
existingProvider.RegisteredName = providerProfile.RegisteredName;
existingProvider.TradingName = providerProfile.TradingName;
existingProvider.HasRegistrationNumber = providerProfile.HasRegistrationNumber;
if (providerProfile.HasParentCompany)
existingProvider.TradingName = providerProfile.TradingName;
if (existingProvider.HasParentCompany && !string.IsNullOrEmpty(providerProfile.ParentCompanyLocation))
{
existingProvider.HasParentCompany = providerProfile.HasParentCompany;
existingProvider.ParentCompanyLocation = providerProfile.ParentCompanyLocation;
}
if (existingProvider.HasRegistrationNumber)
if (existingProvider.HasParentCompany && !string.IsNullOrEmpty(providerProfile.ParentCompanyRegisteredName))
{
existingProvider.ParentCompanyRegisteredName = providerProfile.ParentCompanyRegisteredName;
}
if (existingProvider.HasRegistrationNumber && !string.IsNullOrEmpty(providerProfile.CompanyRegistrationNumber))
{
existingProvider.CompanyRegistrationNumber = providerProfile.CompanyRegistrationNumber;
}
else
{
existingProvider.DUNSNumber = providerProfile.DUNSNumber;
}
existingProvider.ParentCompanyRegisteredName = providerProfile.ParentCompanyRegisteredName;

existingProvider.CabEditedTime = DateTime.UtcNow;
await context.SaveChangesAsync();
transaction.Commit();
genericResponse.Success = true;

}

}
catch (Exception ex)
{
genericResponse.Success = false;
transaction.Rollback();
logger.LogError(ex, "Error in UpdateCompanyInfo");
}
return genericResponse;
}


public async Task<GenericResponse> UpdatePrimaryContact(ProviderProfile providerProfile)
{
GenericResponse genericResponse = new();
using var transaction = context.Database.BeginTransaction();
try
{
var existingProvider = await context.ProviderProfile.FirstOrDefaultAsync(p => p.Id == providerProfile.Id);
if (existingProvider !=null)
{
existingProvider.PrimaryContactFullName= providerProfile.PrimaryContactFullName;
existingProvider.PrimaryContactJobTitle= providerProfile.PrimaryContactJobTitle;
existingProvider.PrimaryContactEmail = providerProfile.PrimaryContactEmail;
existingProvider.PrimaryContactTelephoneNumber = providerProfile.PrimaryContactTelephoneNumber;
existingProvider.SecondaryContactFullName = providerProfile.SecondaryContactFullName;
existingProvider.SecondaryContactJobTitle = providerProfile.SecondaryContactJobTitle;
existingProvider.CabEditedTime = DateTime.UtcNow;
await context.SaveChangesAsync();
transaction.Commit();
genericResponse.Success = true;

}

}
catch (Exception ex)
{
genericResponse.Success = false;
transaction.Rollback();
logger.LogError(ex, "Error in UpdatePrimaryContact");
}
return genericResponse;
}


public async Task<GenericResponse> UpdateSecondaryContact(ProviderProfile providerProfile)
{
GenericResponse genericResponse = new();
using var transaction = context.Database.BeginTransaction();
try
{
var existingProvider = await context.ProviderProfile.FirstOrDefaultAsync(p => p.Id == providerProfile.Id);
if (existingProvider !=null)
{
existingProvider.SecondaryContactFullName= providerProfile.SecondaryContactFullName;
existingProvider.SecondaryContactJobTitle= providerProfile.SecondaryContactJobTitle;
existingProvider.SecondaryContactEmail = providerProfile.SecondaryContactEmail;
existingProvider.SecondaryContactTelephoneNumber = providerProfile.SecondaryContactTelephoneNumber;
existingProvider.CabEditedTime = DateTime.UtcNow;
await context.SaveChangesAsync();
transaction.Commit();
genericResponse.Success = true;

}

}
catch (Exception ex)
{
genericResponse.Success = false;
transaction.Rollback();
logger.LogError(ex, "Error in UpdateSecondaryContact");
}
return genericResponse;
}
public async Task<GenericResponse> UpdatePublicProviderInformation(ProviderProfile providerProfile)
{
GenericResponse genericResponse = new();
using var transaction = context.Database.BeginTransaction();
try
{
var existingProvider = await context.ProviderProfile.FirstOrDefaultAsync(p => p.Id == providerProfile.Id);
if (existingProvider !=null)
{
existingProvider.PublicContactEmail= providerProfile.PublicContactEmail;
existingProvider.ProviderTelephoneNumber = providerProfile.ProviderTelephoneNumber;
existingProvider.ProviderWebsiteAddress = providerProfile.ProviderWebsiteAddress;
existingProvider.ProviderStatus = providerProfile.ProviderStatus;
existingProvider.ModifiedTime = DateTime.UtcNow;
existingProvider.CabEditedTime = DateTime.UtcNow;
await context.SaveChangesAsync();
transaction.Commit();
genericResponse.Success = true;
Expand All @@ -140,7 +221,7 @@ public async Task<GenericResponse> UpdateProviderProfile(ProviderProfile provide
{
genericResponse.Success = false;
transaction.Rollback();
logger.LogError(ex, "Error in UpdateProviderProfile");
logger.LogError(ex, "Error in UpdatePublicProviderInformation");
}
return genericResponse;
}
Expand Down
5 changes: 4 additions & 1 deletion DVSRegister.Data/CAB/ICabRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ public interface ICabRepository
public Task<List<IdentityProfile>> GetIdentityProfiles();
public Task<List<SupplementaryScheme>> GetSupplementarySchemes();
public Task<GenericResponse> SaveProviderProfile(ProviderProfile providerProfile);
public Task<GenericResponse> UpdateProviderProfile(ProviderProfile providerProfile);
public Task<GenericResponse> UpdateCompanyInfo(ProviderProfile providerProfile);
public Task<GenericResponse> UpdatePrimaryContact(ProviderProfile providerProfile);
public Task<GenericResponse> UpdateSecondaryContact(ProviderProfile providerProfile);
public Task<GenericResponse> UpdatePublicProviderInformation(ProviderProfile providerProfile);
public Task<bool> CheckProviderRegisteredNameExists(string registeredName);
public Task<bool> CheckProviderRegisteredNameExists(string registeredName, int providerId);
public Task<GenericResponse> SaveService(Service service);
Expand Down
1 change: 1 addition & 0 deletions DVSRegister.Data/Entities/ProviderProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public class ProviderProfile
public DateTime? CreatedTime { get; set; }
public DateTime? ModifiedTime { get; set; }
public DateTime? PublishedTime { get; set; }
public DateTime? CabEditedTime { get; set; }
}
}
Loading

0 comments on commit dedd145

Please sign in to comment.