Renamed the CacheHelper To Helpers
This commit is contained in:
parent
5be154a9f1
commit
cfbfbf2e2b
@ -1,9 +1,9 @@
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Employees;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Marco.Pms.CacheHelper
|
||||
namespace Marco.Pms.Helpers.CacheHelper
|
||||
{
|
||||
public class EmployeeCache
|
||||
{
|
24
Marco.Pms.Helpers/CacheHelper/ExpenseCache.cs
Normal file
24
Marco.Pms.Helpers/CacheHelper/ExpenseCache.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using Marco.Pms.Model.MongoDBModels.Employees;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Marco.Pms.Helpers.CacheHelper
|
||||
{
|
||||
public class ExpenseCache
|
||||
{
|
||||
private readonly IMongoCollection<EmployeePermissionMongoDB> _collection;
|
||||
public ExpenseCache(IConfiguration configuration)
|
||||
{
|
||||
|
||||
var connectionString = configuration["MongoDB:ConnectionString"];
|
||||
var mongoUrl = new MongoUrl(connectionString);
|
||||
var client = new MongoClient(mongoUrl); // Your MongoDB connection string
|
||||
var mongoDB = client.GetDatabase(mongoUrl.DatabaseName); // Your MongoDB Database name
|
||||
_collection = mongoDB.GetCollection<EmployeePermissionMongoDB>("Expenses");
|
||||
}
|
||||
public async Task AddExpenseToCacheAsync()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,14 @@
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Master;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Masters;
|
||||
using Marco.Pms.Model.MongoDBModels.Project;
|
||||
using Marco.Pms.Model.Projects;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Marco.Pms.CacheHelper
|
||||
namespace Marco.Pms.Helpers
|
||||
{
|
||||
public class ProjectCache
|
||||
{
|
@ -1,8 +1,8 @@
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Utility;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Marco.Pms.CacheHelper
|
||||
namespace Marco.Pms.Helpers.CacheHelper
|
||||
{
|
||||
public class ReportCache
|
||||
{
|
@ -1,10 +1,10 @@
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Utility;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using System.Collections;
|
||||
|
||||
namespace Marco.Pms.CacheHelper
|
||||
namespace Marco.Pms.Helpers
|
||||
{
|
||||
public class UpdateLogHelper
|
||||
{
|
@ -1,20 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.20" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
|
||||
<PackageReference Include="MongoDB.Bson" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.20" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0" />
|
||||
<PackageReference Include="MongoDB.Bson" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Marco.Pms.Utility\Marco.Pms.Utility.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Marco.Pms.Utility\Marco.Pms.Utility.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,6 +1,6 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Employees
|
||||
{
|
||||
[BsonIgnoreExtraElements]
|
||||
public class EmployeePermissionMongoDB
|
@ -0,0 +1,6 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels.Expenses
|
||||
{
|
||||
public class ExpenseDetailsMongoDB
|
||||
{
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Masters
|
||||
{
|
||||
public class StatusMasterMongoDB
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Masters
|
||||
{
|
||||
public class WorkCategoryMasterMongoDB
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Project
|
||||
{
|
||||
public class ActivityMasterMongoDB
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Project
|
||||
{
|
||||
public class BuildingMongoDB
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Project
|
||||
{
|
||||
public class FloorMongoDB
|
||||
{
|
@ -1,4 +1,6 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
using Marco.Pms.Model.MongoDBModels.Masters;
|
||||
|
||||
namespace Marco.Pms.Model.MongoDBModels.Project
|
||||
{
|
||||
public class ProjectMongoDB
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Project
|
||||
{
|
||||
public class WorkAreaInfoMongoDB
|
||||
{
|
@ -1,4 +1,4 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Project
|
||||
{
|
||||
public class WorkAreaMongoDB
|
||||
{
|
@ -1,4 +1,6 @@
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
using Marco.Pms.Model.MongoDBModels.Masters;
|
||||
|
||||
namespace Marco.Pms.Model.MongoDBModels.Project
|
||||
{
|
||||
public class WorkItemMongoDB
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Utility
|
||||
{
|
||||
public class ProjectReportEmailMongoDB
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
|
||||
namespace Marco.Pms.Model.MongoDBModels
|
||||
namespace Marco.Pms.Model.MongoDBModels.Utility
|
||||
{
|
||||
public class UpdateLogsObject
|
||||
{
|
@ -19,7 +19,7 @@ COPY ["Marco.Pms.Services/Marco.Pms.Services.csproj", "Marco.Pms.Services/"]
|
||||
COPY ["Marco.Pms.DataAccess/Marco.Pms.DataAccess.csproj", "Marco.Pms.DataAccess/"]
|
||||
COPY ["Marco.Pms.Model/Marco.Pms.Model.csproj", "Marco.Pms.Model/"]
|
||||
COPY ["Marco.Pms.Utility/Marco.Pms.Utility.csproj", "Marco.Pms.Utility/"]
|
||||
COPY ["Marco.Pms.CacheHelper/Marco.Pms.CacheHelper.csproj", "Marco.Pms.CacheHelper/"]
|
||||
COPY ["Marco.Pms.Helpers/Marco.Pms.Helpers.csproj", "Marco.Pms.Helpers/"]
|
||||
RUN dotnet restore "./Marco.Pms.Services/Marco.Pms.Services.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Marco.Pms.Services"
|
||||
|
@ -1,7 +1,10 @@
|
||||
using Marco.Pms.CacheHelper;
|
||||
using Marco.Pms.Helpers;
|
||||
using Marco.Pms.Helpers.CacheHelper;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Master;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Masters;
|
||||
using Marco.Pms.Model.MongoDBModels.Project;
|
||||
using Marco.Pms.Model.MongoDBModels.Utility;
|
||||
using Marco.Pms.Model.Projects;
|
||||
using MarcoBMS.Services.Service;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Project;
|
||||
using MarcoBMS.Services.Service;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
using Marco.Pms.Model.Dtos.Attendance;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Mail;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Project;
|
||||
using Marco.Pms.Model.Utilities;
|
||||
using Marco.Pms.Model.ViewModels.Report;
|
||||
using MarcoBMS.Services.Service;
|
||||
|
@ -5,7 +5,8 @@ using Marco.Pms.Model.Dtos.Project;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Expenses;
|
||||
using Marco.Pms.Model.Master;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Masters;
|
||||
using Marco.Pms.Model.MongoDBModels.Project;
|
||||
using Marco.Pms.Model.Projects;
|
||||
using Marco.Pms.Model.ViewModels.Activities;
|
||||
using Marco.Pms.Model.ViewModels.Employee;
|
||||
|
@ -1,52 +1,52 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<GenerateDocumentationFile>False</GenerateDocumentationFile>
|
||||
<UserSecretsId>55935cea-fc40-40f8-be42-da094f06b11f</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
|
||||
<GenerateDocumentationFile>False</GenerateDocumentationFile>
|
||||
<UserSecretsId>55935cea-fc40-40f8-be42-da094f06b11f</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="AWSSDK.S3" Version="3.7.416.13" />
|
||||
<PackageReference Include="MailKit" Version="4.9.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.20" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.12">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.12">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
|
||||
<PackageReference Include="Mime-Detective" Version="24.12.2" />
|
||||
<PackageReference Include="Mime-Detective.Definitions.Exhaustive" Version="24.12.2" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.MongoDB" Version="7.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="AWSSDK.S3" Version="3.7.416.13" />
|
||||
<PackageReference Include="MailKit" Version="4.9.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.20" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.12">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.12">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
|
||||
<PackageReference Include="Mime-Detective" Version="24.12.2" />
|
||||
<PackageReference Include="Mime-Detective.Definitions.Exhaustive" Version="24.12.2" />
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.MongoDB" Version="7.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Marco.Pms.DataAccess\Marco.Pms.DataAccess.csproj" />
|
||||
<ProjectReference Include="..\Marco.Pms.Model\Marco.Pms.Model.csproj" />
|
||||
<ProjectReference Include="..\Marco.Pms.Utility\Marco.Pms.Utility.csproj" />
|
||||
<ProjectReference Include="..\Marco.Pms.CacheHelper\Marco.Pms.CacheHelper.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Marco.Pms.DataAccess\Marco.Pms.DataAccess.csproj" />
|
||||
<ProjectReference Include="..\Marco.Pms.Model\Marco.Pms.Model.csproj" />
|
||||
<ProjectReference Include="..\Marco.Pms.Utility\Marco.Pms.Utility.csproj" />
|
||||
<ProjectReference Include="..\Marco.Pms.Helpers\Marco.Pms.Helpers.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="EmailTemplates\**\*.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Marco.Pms.CacheHelper;
|
||||
using Marco.Pms.Helpers;
|
||||
using Marco.Pms.Helpers.CacheHelper;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.Authentication;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
|
@ -1,12 +1,12 @@
|
||||
using AutoMapper;
|
||||
using Marco.Pms.CacheHelper;
|
||||
using Marco.Pms.Helpers;
|
||||
using Marco.Pms.DataAccess.Data;
|
||||
using Marco.Pms.Model.DocumentManager;
|
||||
using Marco.Pms.Model.Dtos.Expenses;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
using Marco.Pms.Model.Expenses;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Utility;
|
||||
using Marco.Pms.Model.Utilities;
|
||||
using Marco.Pms.Model.ViewModels.Activities;
|
||||
using Marco.Pms.Model.ViewModels.Expanses;
|
||||
@ -29,6 +29,7 @@ namespace Marco.Pms.Services.Service
|
||||
private readonly UpdateLogHelper _updateLogHelper;
|
||||
private readonly IMapper _mapper;
|
||||
private static readonly Guid Draft = Guid.Parse("297e0d8f-f668-41b5-bfea-e03b354251c8");
|
||||
private static readonly Guid Rejected = Guid.Parse("d1ee5eec-24b6-4364-8673-a8f859c60729");
|
||||
private static readonly string Collection = "ExpensesModificationLog";
|
||||
public ExpensesService(
|
||||
IDbContextFactory<ApplicationDbContext> dbContextFactory,
|
||||
@ -391,9 +392,25 @@ namespace Marco.Pms.Services.Service
|
||||
_logger.LogInfo("Successfully created Expense {ExpenseId} for Project {ProjectId}.", expense.Id, expense.ProjectId);
|
||||
return ApiResponse<object>.SuccessResponse(response, "Expense created successfully.", 201);
|
||||
}
|
||||
catch (ArgumentException ex) // Catches bad Base64 from attachment pre-validation
|
||||
catch (DbUpdateException dbEx)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
_logger.LogError(dbEx, "Databsae Exception occured while adding expense");
|
||||
return ApiResponse<object>.ErrorResponse("Databsae Exception", new
|
||||
{
|
||||
Message = dbEx.Message,
|
||||
StackTrace = dbEx.StackTrace,
|
||||
Source = dbEx.Source,
|
||||
innerexcption = new
|
||||
{
|
||||
Message = dbEx.InnerException?.Message,
|
||||
StackTrace = dbEx.InnerException?.StackTrace,
|
||||
Source = dbEx.InnerException?.Source,
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
catch (ArgumentException ex) // Catches bad Base64 from attachment pre-validation
|
||||
{
|
||||
_logger.LogError(ex, "Invalid argument during expense creation for project {ProjectId}.", dto.ProjectId);
|
||||
return ApiResponse<object>.ErrorResponse("Invalid Request Data.", new
|
||||
{
|
||||
@ -410,7 +427,6 @@ namespace Marco.Pms.Services.Service
|
||||
}
|
||||
catch (Exception ex) // General-purpose catch for unexpected errors (e.g., S3 or DB connection failure)
|
||||
{
|
||||
await transaction.RollbackAsync();
|
||||
_logger.LogError(ex, "An unhandled exception occurred while creating an expense for project {ProjectId}.", dto.ProjectId);
|
||||
return ApiResponse<object>.ErrorResponse("An internal server error occurred.", new
|
||||
{
|
||||
@ -615,15 +631,29 @@ namespace Marco.Pms.Services.Service
|
||||
}
|
||||
public async Task<ApiResponse<object>> UpdateExpanseAsync(Guid id, UpdateExpensesDto model, Employee loggedInEmployee, Guid tenantId)
|
||||
{
|
||||
var exsitingExpense = await _context.Expenses.FirstOrDefaultAsync(e => e.Id == model.Id && e.TenantId == tenantId);
|
||||
var existingExpense = await _context.Expenses
|
||||
.Include(e => e.ExpensesType)
|
||||
.Include(e => e.Project)
|
||||
.Include(e => e.PaidBy)
|
||||
.ThenInclude(e => e!.JobRole)
|
||||
.Include(e => e.PaymentMode)
|
||||
.Include(e => e.Status)
|
||||
.Include(e => e.CreatedBy)
|
||||
.FirstOrDefaultAsync(e =>
|
||||
e.Id == model.Id &&
|
||||
e.CreatedById == loggedInEmployee.Id &&
|
||||
(e.StatusId == Draft || e.StatusId == Rejected) &&
|
||||
e.TenantId == tenantId);
|
||||
|
||||
|
||||
if (exsitingExpense == null)
|
||||
if (existingExpense == null)
|
||||
{
|
||||
return ApiResponse<object>.ErrorResponse("Expense not found", "Expense not found", 404);
|
||||
}
|
||||
_mapper.Map(model, exsitingExpense);
|
||||
_context.Entry(exsitingExpense).State = EntityState.Modified;
|
||||
|
||||
var existingEntityBson = _updateLogHelper.EntityToBsonDocument(existingExpense); // Capture state for audit log BEFORE changes
|
||||
_mapper.Map(model, existingExpense);
|
||||
_context.Entry(existingExpense).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
@ -637,8 +667,60 @@ namespace Marco.Pms.Services.Service
|
||||
_logger.LogError(ex, "Concurrency conflict while updating project {ProjectId} ", id);
|
||||
return ApiResponse<object>.ErrorResponse("Conflict occurred.", "This project has been modified by someone else. Please refresh and try again.", 409);
|
||||
}
|
||||
var response = _mapper.Map<ExpenseList>(exsitingExpense);
|
||||
return ApiResponse<object>.SuccessResponse(response);
|
||||
try
|
||||
{
|
||||
// Task to save the detailed audit log to a separate system (e.g., MongoDB).
|
||||
var mongoDBTask = _updateLogHelper.PushToUpdateLogsAsync(new UpdateLogsObject
|
||||
{
|
||||
EntityId = existingExpense.Id.ToString(),
|
||||
UpdatedById = loggedInEmployee.Id.ToString(),
|
||||
OldObject = existingEntityBson,
|
||||
UpdatedAt = DateTime.UtcNow
|
||||
}, Collection);
|
||||
|
||||
// Task to get all possible next statuses from the *new* current state to help the UI.
|
||||
// NOTE: This now fetches a list of all possible next states, which is more useful for a UI.
|
||||
var getNextStatusesTask = _dbContextFactory.CreateDbContextAsync().ContinueWith(t =>
|
||||
{
|
||||
var dbContext = t.Result;
|
||||
return dbContext.ExpensesStatusMapping
|
||||
.Include(s => s.NextStatus)
|
||||
.Where(s => s.StatusId == existingExpense.StatusId && s.NextStatus != null && s.TenantId == tenantId)
|
||||
.Select(s => s.NextStatus) // Select only the status object
|
||||
.ToListAsync()
|
||||
.ContinueWith(res =>
|
||||
{
|
||||
dbContext.Dispose(); // Ensure the context is disposed
|
||||
return res.Result;
|
||||
});
|
||||
}).Unwrap();
|
||||
|
||||
await Task.WhenAll(mongoDBTask, getNextStatusesTask);
|
||||
|
||||
var nextPossibleStatuses = await getNextStatusesTask;
|
||||
|
||||
var response = _mapper.Map<ExpenseList>(existingExpense);
|
||||
if (nextPossibleStatuses != null)
|
||||
{
|
||||
// The response DTO should have a property like: public List<ExpensesStatusMasterVM> NextAvailableStatuses { get; set; }
|
||||
response.NextStatus = _mapper.Map<List<ExpensesStatusMasterVM>>(nextPossibleStatuses);
|
||||
}
|
||||
|
||||
return ApiResponse<object>.SuccessResponse(response);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// This catch block handles errors from post-save operations like MongoDB logging.
|
||||
// The primary update was successful, but we must log this failure.
|
||||
_logger.LogError(ex, "Error occurred during post-save operations for ExpenseId: {ExpenseId} (e.g., audit logging). The primary status change was successful.", existingExpense.Id);
|
||||
|
||||
// We can still return a success response because the main operation succeeded,
|
||||
// but we should not block the user for a failed audit log.
|
||||
// Alternatively, if audit logging is critical, you could return an error.
|
||||
// Here, we choose to return success but log the ancillary failure.
|
||||
var response = _mapper.Map<ExpenseList>(existingExpense);
|
||||
return ApiResponse<object>.SuccessResponse(response, "Status updated, but a post-processing error occurred.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
|
@ -5,7 +5,7 @@ using Marco.Pms.Model.Activities;
|
||||
using Marco.Pms.Model.Dtos.Project;
|
||||
using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
using Marco.Pms.Model.MongoDBModels;
|
||||
using Marco.Pms.Model.MongoDBModels.Project;
|
||||
using Marco.Pms.Model.Projects;
|
||||
using Marco.Pms.Model.Utilities;
|
||||
using Marco.Pms.Model.ViewModels.Employee;
|
||||
|
@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Marco.Pms.Utility", "Marco.
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marco.Pms.Services", "Marco.Pms.Services\Marco.Pms.Services.csproj", "{27A83653-5B7F-4135-9886-01594D54AFAE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marco.Pms.CacheHelper", "Marco.Pms.CacheHelper\Marco.Pms.CacheHelper.csproj", "{1A105C22-4ED7-4F54-8834-6923DDD96852}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Marco.Pms.Helpers", "Marco.Pms.Helpers\Marco.Pms.Helpers.csproj", "{1A105C22-4ED7-4F54-8834-6923DDD96852}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
Loading…
x
Reference in New Issue
Block a user