Merge pull request 'Added the list document API' (#119) from Ashutosh_Task#1011 into Document_Manager
Reviewed-on: #119
This commit is contained in:
commit
6d207e8f7d
File diff suppressed because one or more lines are too long
@ -0,0 +1,212 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Added_IsCurrentVersion_Field_In_Document_Attachment : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "IsCurrentVersion",
|
||||
table: "DocumentAttachments",
|
||||
type: "tinyint(1)",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1227));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1217));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("07ca7182-9ac0-4407-b988-59901170cb86"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1308));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("16c40b80-c207-4a0c-a4d3-381414afe35a"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1293));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("260abd7e-c96d-4ae4-a29b-9b5bb5d24ebd"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1300));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d1d7441-46a8-425e-9395-94d0956f8e91"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1289));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("336225ac-67f3-4e14-ba7a-8fad03cf2832"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1275));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("5668de00-5d84-47f7-b9b5-7fefd1219f05"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1391));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("6344393b-9bb1-45f8-b620-9f6e279d012c"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1284));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("7cc41c91-23cb-442b-badd-f932138d149f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1388));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("846e89a9-5735-45ec-a21d-c97f85a94ada"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1384));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("a1a190ba-c4a8-432f-b26d-1231ca1d44bc"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1305));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("f76d8215-d399-4f0e-b414-12e427f50be3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1297));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "IsCurrentVersion",
|
||||
table: "DocumentAttachments");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7895));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7887));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("07ca7182-9ac0-4407-b988-59901170cb86"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7995));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("16c40b80-c207-4a0c-a4d3-381414afe35a"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7975));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("260abd7e-c96d-4ae4-a29b-9b5bb5d24ebd"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7984));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d1d7441-46a8-425e-9395-94d0956f8e91"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7971));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("336225ac-67f3-4e14-ba7a-8fad03cf2832"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7958));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("5668de00-5d84-47f7-b9b5-7fefd1219f05"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(8008));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("6344393b-9bb1-45f8-b620-9f6e279d012c"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7966));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("7cc41c91-23cb-442b-badd-f932138d149f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(8004));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("846e89a9-5735-45ec-a21d-c97f85a94ada"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(8000));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("a1a190ba-c4a8-432f-b26d-1231ca1d44bc"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7991));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("f76d8215-d399-4f0e-b414-12e427f50be3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7980));
|
||||
}
|
||||
}
|
||||
}
|
5447
Marco.Pms.DataAccess/Migrations/20250828111857_Modified_UpdatedAt_And_VerifiedAt_To_Nullable.Designer.cs
generated
Normal file
5447
Marco.Pms.DataAccess/Migrations/20250828111857_Modified_UpdatedAt_And_VerifiedAt_To_Nullable.Designer.cs
generated
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,237 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class Modified_UpdatedAt_And_VerifiedAt_To_Nullable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "VerifiedAt",
|
||||
table: "DocumentAttachments",
|
||||
type: "datetime(6)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "datetime(6)");
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedAt",
|
||||
table: "DocumentAttachments",
|
||||
type: "datetime(6)",
|
||||
nullable: true,
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "datetime(6)");
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(8988));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(8981));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("07ca7182-9ac0-4407-b988-59901170cb86"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9059));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("16c40b80-c207-4a0c-a4d3-381414afe35a"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9042));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("260abd7e-c96d-4ae4-a29b-9b5bb5d24ebd"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9051));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d1d7441-46a8-425e-9395-94d0956f8e91"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9038));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("336225ac-67f3-4e14-ba7a-8fad03cf2832"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9028));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("5668de00-5d84-47f7-b9b5-7fefd1219f05"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9072));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("6344393b-9bb1-45f8-b620-9f6e279d012c"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9034));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("7cc41c91-23cb-442b-badd-f932138d149f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9068));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("846e89a9-5735-45ec-a21d-c97f85a94ada"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9063));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("a1a190ba-c4a8-432f-b26d-1231ca1d44bc"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9055));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("f76d8215-d399-4f0e-b414-12e427f50be3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9046));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "VerifiedAt",
|
||||
table: "DocumentAttachments",
|
||||
type: "datetime(6)",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "datetime(6)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.AlterColumn<DateTime>(
|
||||
name: "UpdatedAt",
|
||||
table: "DocumentAttachments",
|
||||
type: "datetime(6)",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
||||
oldClrType: typeof(DateTime),
|
||||
oldType: "datetime(6)",
|
||||
oldNullable: true);
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1227));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentCategoryMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1217));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("07ca7182-9ac0-4407-b988-59901170cb86"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1308));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("16c40b80-c207-4a0c-a4d3-381414afe35a"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1293));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("260abd7e-c96d-4ae4-a29b-9b5bb5d24ebd"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1300));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("2d1d7441-46a8-425e-9395-94d0956f8e91"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1289));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("336225ac-67f3-4e14-ba7a-8fad03cf2832"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1275));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("5668de00-5d84-47f7-b9b5-7fefd1219f05"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1391));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("6344393b-9bb1-45f8-b620-9f6e279d012c"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1284));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("7cc41c91-23cb-442b-badd-f932138d149f"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1388));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("846e89a9-5735-45ec-a21d-c97f85a94ada"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1384));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("a1a190ba-c4a8-432f-b26d-1231ca1d44bc"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1305));
|
||||
|
||||
migrationBuilder.UpdateData(
|
||||
table: "DocumentTypeMasters",
|
||||
keyColumn: "Id",
|
||||
keyValue: new Guid("f76d8215-d399-4f0e-b414-12e427f50be3"),
|
||||
column: "CreatedAt",
|
||||
value: new DateTime(2025, 8, 28, 11, 11, 44, 468, DateTimeKind.Utc).AddTicks(1297));
|
||||
}
|
||||
}
|
||||
}
|
@ -848,6 +848,9 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
b.Property<bool>("IsActive")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<bool>("IsCurrentVersion")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
b.Property<bool?>("IsVerified")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
@ -858,7 +861,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
b.Property<Guid>("TenantId")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime>("UpdatedAt")
|
||||
b.Property<DateTime?>("UpdatedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<Guid?>("UpdatedById")
|
||||
@ -870,7 +873,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
b.Property<Guid>("UploadedById")
|
||||
.HasColumnType("char(36)");
|
||||
|
||||
b.Property<DateTime>("VerifiedAt")
|
||||
b.Property<DateTime?>("VerifiedAt")
|
||||
.HasColumnType("datetime(6)");
|
||||
|
||||
b.Property<Guid?>("VerifiedById")
|
||||
@ -928,7 +931,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
new
|
||||
{
|
||||
Id = new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7887),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(8981),
|
||||
Description = "Project documents are formal records that outline the plans, progress, and details necessary to execute and manage a project effectively.",
|
||||
EntityTypeId = new Guid("c8fe7115-aa27-43bc-99f4-7b05fabe436e"),
|
||||
Name = "Project Documents",
|
||||
@ -937,7 +940,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
new
|
||||
{
|
||||
Id = new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7895),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(8988),
|
||||
Description = "Employment details along with legal IDs like passports or driver’s licenses to verify identity and work authorization.",
|
||||
EntityTypeId = new Guid("dbb9555a-7a0c-40f2-a9ed-f0463f1ceed7"),
|
||||
Name = "Employee Documents",
|
||||
@ -1023,7 +1026,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("336225ac-67f3-4e14-ba7a-8fad03cf2832"),
|
||||
AllowedContentType = "application/pdf,image/jpeg",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7958),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9028),
|
||||
DocumentCategoryId = new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
IsActive = true,
|
||||
IsMandatory = true,
|
||||
@ -1038,7 +1041,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("6344393b-9bb1-45f8-b620-9f6e279d012c"),
|
||||
AllowedContentType = "application/pdf,image/jpeg",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7966),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9034),
|
||||
DocumentCategoryId = new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
IsActive = true,
|
||||
IsMandatory = true,
|
||||
@ -1053,7 +1056,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("2d1d7441-46a8-425e-9395-94d0956f8e91"),
|
||||
AllowedContentType = "application/pdf,image/jpeg",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7971),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9038),
|
||||
DocumentCategoryId = new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
IsActive = true,
|
||||
IsMandatory = true,
|
||||
@ -1068,7 +1071,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("16c40b80-c207-4a0c-a4d3-381414afe35a"),
|
||||
AllowedContentType = "application/pdf,image/jpeg",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7975),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9042),
|
||||
DocumentCategoryId = new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
IsActive = true,
|
||||
IsMandatory = true,
|
||||
@ -1083,7 +1086,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("f76d8215-d399-4f0e-b414-12e427f50be3"),
|
||||
AllowedContentType = "application/pdf,image/jpeg",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7980),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9046),
|
||||
DocumentCategoryId = new Guid("2d9fb9cf-db53-476b-a452-492e88e2b51f"),
|
||||
IsActive = true,
|
||||
IsMandatory = true,
|
||||
@ -1098,7 +1101,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("260abd7e-c96d-4ae4-a29b-9b5bb5d24ebd"),
|
||||
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7984),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9051),
|
||||
DocumentCategoryId = new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
IsActive = true,
|
||||
IsMandatory = false,
|
||||
@ -1112,7 +1115,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("a1a190ba-c4a8-432f-b26d-1231ca1d44bc"),
|
||||
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7991),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9055),
|
||||
DocumentCategoryId = new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
IsActive = true,
|
||||
IsMandatory = false,
|
||||
@ -1126,7 +1129,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("07ca7182-9ac0-4407-b988-59901170cb86"),
|
||||
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(7995),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9059),
|
||||
DocumentCategoryId = new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
IsActive = true,
|
||||
IsMandatory = false,
|
||||
@ -1140,7 +1143,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("846e89a9-5735-45ec-a21d-c97f85a94ada"),
|
||||
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(8000),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9063),
|
||||
DocumentCategoryId = new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
IsActive = true,
|
||||
IsMandatory = false,
|
||||
@ -1154,7 +1157,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("7cc41c91-23cb-442b-badd-f932138d149f"),
|
||||
AllowedContentType = "application/pdf,application/msword,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(8004),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9068),
|
||||
DocumentCategoryId = new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
IsActive = true,
|
||||
IsMandatory = false,
|
||||
@ -1168,7 +1171,7 @@ namespace Marco.Pms.DataAccess.Migrations
|
||||
{
|
||||
Id = new Guid("5668de00-5d84-47f7-b9b5-7fefd1219f05"),
|
||||
AllowedContentType = "application/pdf,image/vnd.dwg,application/acad",
|
||||
CreatedAt = new DateTime(2025, 8, 28, 9, 22, 46, 902, DateTimeKind.Utc).AddTicks(8008),
|
||||
CreatedAt = new DateTime(2025, 8, 28, 11, 18, 55, 873, DateTimeKind.Utc).AddTicks(9072),
|
||||
DocumentCategoryId = new Guid("cfbff269-072b-477a-b48b-72cdc57dd1d3"),
|
||||
IsActive = true,
|
||||
IsMandatory = false,
|
||||
|
@ -11,19 +11,20 @@ namespace Marco.Pms.Model.DocumentManager
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? DocumentId { get; set; }
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public bool IsCurrentVersion { get; set; } = true;
|
||||
public DateTime UploadedAt { get; set; }
|
||||
public Guid UploadedById { get; set; } // References the employee who uploaded the document
|
||||
|
||||
[ValidateNever]
|
||||
[ForeignKey("UploadedById")]
|
||||
public Employee? UploadedBy { get; set; }
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
public Guid? UpdatedById { get; set; } // References the employee who updates the document
|
||||
|
||||
[ValidateNever]
|
||||
[ForeignKey("UpdatedById")]
|
||||
public Employee? UpdatedBy { get; set; }
|
||||
public DateTime VerifiedAt { get; set; }
|
||||
public DateTime? VerifiedAt { get; set; }
|
||||
public bool? IsVerified { get; set; }
|
||||
public Guid? VerifiedById { get; set; } // Associates the document with a specific employee, if applicable
|
||||
|
||||
|
@ -7,7 +7,7 @@ namespace Marco.Pms.Model.Dtos.DocumentManager
|
||||
public required string Name { get; set; }
|
||||
public string? DocumentId { get; set; }
|
||||
public required string Description { get; set; }
|
||||
public Guid EntityId { get; set; }
|
||||
public required Guid EntityId { get; set; }
|
||||
public required Guid DocumentTypeId { get; set; } // References the type of the document
|
||||
public required FileUploadModel Attachment { get; set; }
|
||||
public List<DocumentTagDto>? Tags { get; set; }
|
||||
|
@ -3,8 +3,9 @@
|
||||
public class DocumentFilter
|
||||
{
|
||||
public List<Guid>? UploadedByIds { get; set; }
|
||||
public List<Guid>? DocumentCategoryIds { get; set; }
|
||||
public List<Guid>? DocumentTypeIds { get; set; }
|
||||
public bool IsActive { get; set; } = true;
|
||||
public List<Guid>? DocumentTagIds { get; set; }
|
||||
public bool IsUploadedAt { get; set; } = true;
|
||||
public bool? IsVerified { get; set; }
|
||||
public DateTime? StartDate { get; set; }
|
||||
|
@ -9,9 +9,11 @@ namespace Marco.Pms.Model.ViewModels.DocumentManager
|
||||
public string? DocumentId { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public DateTime UploadedAt { get; set; }
|
||||
public Guid? ParentAttachmentId { get; set; }
|
||||
public int Version { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool? IsVerified { get; set; }
|
||||
public BasicEmployeeVM? UploadedBy { get; set; }
|
||||
public DocumentTypeVM? DocumentType { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public bool IsVerified { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -48,60 +48,181 @@ namespace Marco.Pms.Services.Controllers
|
||||
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
||||
tenantId = userHelper.GetTenantId();
|
||||
}
|
||||
// GET: api/<DocumentController>
|
||||
[HttpGet("list/{entityTypeId}")]
|
||||
public async Task<IActionResult> Get(Guid entityTypeId, [FromQuery] Guid entityId, [FromQuery] string filter,
|
||||
[FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 20)
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fetch documents for a given entity (Project/Employee) with filtering, searching, and pagination.
|
||||
/// </summary>
|
||||
[HttpGet("list/{entityTypeId}/entity/{entityId}")]
|
||||
public async Task<IActionResult> GetDocumentList(Guid entityTypeId, Guid entityId, [FromQuery] string? filter, [FromQuery] string? searchString,
|
||||
[FromQuery] bool isActive = true, [FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 20)
|
||||
{
|
||||
using var scope = _serviceScope.CreateScope();
|
||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
var _permission = scope.ServiceProvider.GetRequiredService<PermissionServices>();
|
||||
var isViewPermission = await _permission.HasPermission(PermissionsMaster.ViewDocument, loggedInEmployee.Id);
|
||||
|
||||
if (!isViewPermission)
|
||||
try
|
||||
{
|
||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("Access Denied.", "You do not have permission to upload document", 403));
|
||||
}
|
||||
if (ProjectEntity != entityTypeId && EmployeeEntity != entityTypeId)
|
||||
{
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Entity type not found", "Entity Type not found in database", 404));
|
||||
}
|
||||
if (ProjectEntity == entityTypeId)
|
||||
{
|
||||
var isHasProjectPermission = await _permission.HasProjectPermission(loggedInEmployee, entityId);
|
||||
if (!isHasProjectPermission)
|
||||
_logger.LogInfo("Fetching documents for EntityTypeId: {EntityTypeId}, EntityId: {EntityId}", entityTypeId, entityId);
|
||||
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
// Check global permission
|
||||
var hasViewPermission = await _permission.HasPermission(PermissionsMaster.ViewDocument, loggedInEmployee.Id);
|
||||
if (!hasViewPermission && loggedInEmployee.Id != entityId)
|
||||
{
|
||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("Access Denied.", "You do not have permission to upload document to this project", 403));
|
||||
_logger.LogWarning("Access Denied for Employee {EmployeeId} on EntityId {EntityId}", loggedInEmployee.Id, entityId);
|
||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("Access Denied.", "You do not have permission to view documents", 403));
|
||||
}
|
||||
}
|
||||
else if (EmployeeEntity == entityTypeId)
|
||||
{
|
||||
var isEmployeeExists = await _context.Employees.AnyAsync(e => e.Id == entityId && e.TenantId == tenantId);
|
||||
if (!isEmployeeExists)
|
||||
|
||||
// Validate entity type
|
||||
if (ProjectEntity != entityTypeId && EmployeeEntity != entityTypeId)
|
||||
{
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Employee not found", "Employee not found in database", 404));
|
||||
_logger.LogWarning("Invalid EntityTypeId: {EntityTypeId}", entityTypeId);
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Entity type not found", "Entity Type not found in database", 404));
|
||||
}
|
||||
|
||||
// Project permission check
|
||||
if (ProjectEntity == entityTypeId)
|
||||
{
|
||||
var hasProjectPermission = await _permission.HasProjectPermission(loggedInEmployee, entityId);
|
||||
if (!hasProjectPermission)
|
||||
{
|
||||
_logger.LogWarning("Employee {EmployeeId} does not have project access for ProjectId {ProjectId}", loggedInEmployee.Id, entityId);
|
||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("Access Denied.", "You do not have permission to access project documents", 403));
|
||||
}
|
||||
}
|
||||
// Employee validation
|
||||
else if (EmployeeEntity == entityTypeId)
|
||||
{
|
||||
var isEmployeeExists = await _context.Employees
|
||||
.AnyAsync(e => e.Id == entityId && e.TenantId == tenantId);
|
||||
|
||||
if (!isEmployeeExists)
|
||||
{
|
||||
_logger.LogWarning("Employee {EmployeeId} not found for Tenant {TenantId}", entityId, tenantId);
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Employee not found", "Employee not found in database", 404));
|
||||
}
|
||||
}
|
||||
|
||||
// Base Query (with includes to avoid lazy loading)
|
||||
IQueryable<DocumentAttachment> documentQuery = _context.DocumentAttachments
|
||||
.AsNoTracking() // Optimization: Read-only query
|
||||
.Include(da => da.UploadedBy)
|
||||
.ThenInclude(e => e!.JobRole)
|
||||
.Include(da => da.DocumentType!)
|
||||
.ThenInclude(dt => dt.DocumentCategory)
|
||||
.Where(da => da.DocumentType != null &&
|
||||
da.DocumentType.DocumentCategory != null &&
|
||||
da.DocumentType.DocumentCategory.EntityTypeId == entityTypeId &&
|
||||
da.IsActive == isActive &&
|
||||
da.TenantId == tenantId);
|
||||
|
||||
// Apply filter if provided
|
||||
var documentFilter = TryDeserializeFilter(filter);
|
||||
if (documentFilter != null)
|
||||
{
|
||||
_logger.LogInfo("Applying document filters for EntityId {EntityId}", entityId);
|
||||
|
||||
if (documentFilter.IsVerified != null)
|
||||
documentQuery = documentQuery.Where(da => da.IsVerified == documentFilter.IsVerified);
|
||||
|
||||
if (documentFilter.DocumentCategoryIds?.Any() ?? false)
|
||||
documentQuery = documentQuery.Where(da => documentFilter.DocumentCategoryIds.Contains(da.DocumentType!.DocumentCategoryId));
|
||||
|
||||
if (documentFilter.DocumentTypeIds?.Any() ?? false)
|
||||
documentQuery = documentQuery.Where(da => documentFilter.DocumentTypeIds.Contains(da.DocumentTypeId));
|
||||
|
||||
if (documentFilter.DocumentTagIds?.Any() ?? false)
|
||||
{
|
||||
var filteredIds = await _context.AttachmentTagMappings
|
||||
.AsNoTracking()
|
||||
.Where(at => at.DocumentTag != null && documentFilter.DocumentTagIds.Contains(at.DocumentTag.Id) && at.TenantId == tenantId)
|
||||
.Select(at => at.AttachmentId)
|
||||
.ToListAsync();
|
||||
|
||||
documentQuery = documentQuery.Where(da => filteredIds.Contains(da.Id));
|
||||
}
|
||||
|
||||
if (documentFilter.UploadedByIds?.Any() ?? false)
|
||||
documentQuery = documentQuery.Where(da => documentFilter.UploadedByIds.Contains(da.UploadedById));
|
||||
|
||||
// Date Range Filtering (Uploaded vs Verified date)
|
||||
if (documentFilter.StartDate != null && documentFilter.EndDate != null)
|
||||
{
|
||||
if (documentFilter.IsUploadedAt)
|
||||
{
|
||||
documentQuery = documentQuery.Where(da =>
|
||||
da.UpdatedAt.HasValue &&
|
||||
da.UpdatedAt.Value.Date >= documentFilter.StartDate.Value.Date &&
|
||||
da.UpdatedAt.Value.Date <= documentFilter.EndDate.Value.Date);
|
||||
}
|
||||
else
|
||||
{
|
||||
documentQuery = documentQuery.Where(da =>
|
||||
da.VerifiedAt.HasValue &&
|
||||
da.VerifiedAt.Value.Date >= documentFilter.StartDate.Value.Date &&
|
||||
da.VerifiedAt.Value.Date <= documentFilter.EndDate.Value.Date);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
documentQuery = documentQuery.Where(da => da.IsCurrentVersion);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default: only latest version
|
||||
documentQuery = documentQuery.Where(da => da.IsCurrentVersion);
|
||||
}
|
||||
|
||||
// Apply search filter
|
||||
if (!string.IsNullOrWhiteSpace(searchString))
|
||||
{
|
||||
documentQuery = documentQuery.Where(da =>
|
||||
da.Name.Contains(searchString) ||
|
||||
(da.DocumentId != null && da.DocumentId.Contains(searchString))
|
||||
);
|
||||
}
|
||||
|
||||
// Apply pagination & ordering
|
||||
var documents = await documentQuery
|
||||
.OrderByDescending(t => t.UploadedAt)
|
||||
.Skip((pageNumber - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
|
||||
var documentIds = documents.Select(da => da.Id).ToList();
|
||||
|
||||
// Get versions for the selected documents
|
||||
var versions = await _context.AttachmentVersionMappings
|
||||
.AsNoTracking()
|
||||
.Where(av => documentIds.Contains(av.ChildAttachmentId) && av.TenantId == tenantId)
|
||||
.ToListAsync();
|
||||
|
||||
// Map to ViewModel
|
||||
var response = documents.Select(doc =>
|
||||
{
|
||||
var version = versions.FirstOrDefault(v => v.ChildAttachmentId == doc.Id);
|
||||
var vm = _mapper.Map<DocumentListVM>(doc);
|
||||
vm.ParentAttachmentId = version?.ParentAttachmentId;
|
||||
vm.Version = version?.Version ?? 1;
|
||||
return vm;
|
||||
}).ToList();
|
||||
|
||||
_logger.LogInfo("Fetched {Count} documents for EntityId {EntityId}", response.Count, entityId);
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(response, "Document list fetched successfully", 200));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error fetching documents for EntityId {EntityId}", entityId);
|
||||
return StatusCode(500, ApiResponse<object>.ErrorResponse("Internal Server Error", ex.Message, 500));
|
||||
}
|
||||
|
||||
var documentQuery = _context.DocumentAttachments
|
||||
.Include(da => da.DocumentType)
|
||||
.ThenInclude(dt => dt!.DocumentCategory)
|
||||
.Where(da => da.DocumentType != null &&
|
||||
da.DocumentType.DocumentCategory != null &&
|
||||
da.DocumentType.DocumentCategory.EntityTypeId == entityTypeId);
|
||||
|
||||
var documents = await documentQuery
|
||||
.OrderByDescending(t => t.UploadedAt)
|
||||
.Skip((pageNumber - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(documents, "Document list fetched successfully", 200));
|
||||
}
|
||||
|
||||
|
||||
// GET api/<DocumentController>/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task Get(int id)
|
||||
@ -111,194 +232,6 @@ namespace Marco.Pms.Services.Controllers
|
||||
//string preSignedUrl = _s3Service.GeneratePreSignedUrl(objectKey);
|
||||
}
|
||||
|
||||
// POST api/<DocumentController>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody] DocumentAttachmentDto model)
|
||||
{
|
||||
using var scope = _serviceScope.CreateScope();
|
||||
await using var _context = await _dbContextFactory.CreateDbContextAsync();
|
||||
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
var _permission = scope.ServiceProvider.GetRequiredService<PermissionServices>();
|
||||
var isUploadPermission = await _permission.HasPermission(PermissionsMaster.UploadDocument, loggedInEmployee.Id);
|
||||
|
||||
if (!isUploadPermission || loggedInEmployee.Id != model.EntityId)
|
||||
{
|
||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("Access Denied.", "You do not have permission to upload document", 403));
|
||||
}
|
||||
|
||||
var documentType = await _context.DocumentTypeMasters
|
||||
.Include(dt => dt.DocumentCategory)
|
||||
.FirstOrDefaultAsync(dt => dt.Id == model.DocumentTypeId && dt.TenantId == tenantId && dt.DocumentCategory != null);
|
||||
|
||||
if (documentType == null)
|
||||
{
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Document Type not found in database", "Document Type not found in database", 404));
|
||||
}
|
||||
if (documentType.IsMandatory && string.IsNullOrWhiteSpace(model.DocumentId))
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Document ID is missing", "User must provide the document ID fro this document", 400));
|
||||
}
|
||||
if (documentType.IsValidationRequired && !string.IsNullOrWhiteSpace(model.DocumentId))
|
||||
{
|
||||
bool isValid = Regex.IsMatch(model.DocumentId, documentType.RegexExpression ?? "");
|
||||
if (!isValid)
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invaid Document ID", "Provided document ID is not valid", 400));
|
||||
}
|
||||
}
|
||||
|
||||
var employeeExistTask = Task.Run(async () =>
|
||||
{
|
||||
if (documentType.DocumentCategory!.EntityTypeId == EmployeeEntity)
|
||||
{
|
||||
await using var _dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await _dbContext.Employees.AnyAsync(e => e.Id == model.EntityId && e.TenantId == tenantId);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
var projectExistTask = Task.Run(async () =>
|
||||
{
|
||||
if (documentType.DocumentCategory!.EntityTypeId == ProjectEntity)
|
||||
{
|
||||
await using var _dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await _dbContext.Projects.AnyAsync(p => p.Id == model.EntityId && p.TenantId == tenantId);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
await Task.WhenAll(employeeExistTask, projectExistTask);
|
||||
|
||||
var employeeExist = employeeExistTask.Result;
|
||||
var projectExist = projectExistTask.Result;
|
||||
if (documentType.DocumentCategory!.EntityTypeId == EmployeeEntity && !employeeExist)
|
||||
{
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Employee Not Found", "Employee not found in database", 404));
|
||||
}
|
||||
if (documentType.DocumentCategory.EntityTypeId == ProjectEntity && !projectExist)
|
||||
{
|
||||
return NotFound(ApiResponse<object>.ErrorResponse("Project Not Found", "Project not found in database", 404));
|
||||
}
|
||||
|
||||
var documentDetails = _mapper.Map<DocumentAttachment>(model);
|
||||
documentDetails.UploadedAt = DateTime.UtcNow;
|
||||
documentDetails.UploadedById = loggedInEmployee.Id;
|
||||
documentDetails.TenantId = tenantId;
|
||||
|
||||
var _s3Service = scope.ServiceProvider.GetRequiredService<S3UploadService>();
|
||||
var batchId = Guid.NewGuid();
|
||||
List<Document> documents = new List<Document>();
|
||||
if (model.Attachment.FileSize > documentType.MaxSizeAllowedInMB)
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("File size limit exceeded",
|
||||
$"File size exceeded. Maximum allowed is {documentType.MaxSizeAllowedInMB} MB.", 400));
|
||||
}
|
||||
|
||||
|
||||
string base64 = model.Attachment.Base64Data?.Split(',').LastOrDefault() ?? "";
|
||||
if (string.IsNullOrWhiteSpace(base64))
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Base64 data is missing", "Image data missing", 400));
|
||||
|
||||
var fileType = _s3Service.GetContentTypeFromBase64(base64);
|
||||
|
||||
var validContentType = documentType.AllowedContentType.Split(',').ToList();
|
||||
if (!validContentType.Contains(fileType))
|
||||
{
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Unsupported file type.",
|
||||
$"Unsupported file type. {fileType}", 400));
|
||||
}
|
||||
|
||||
string? fileName = null;
|
||||
string? objectKey = null;
|
||||
if (documentType.DocumentCategory!.EntityTypeId == EmployeeEntity)
|
||||
{
|
||||
fileName = _s3Service.GenerateFileName(fileType, tenantId, "EmployeeDocuments");
|
||||
objectKey = $"tenant-{tenantId}/Employee/{model.EntityId}/EmployeeDocuments/{fileName}";
|
||||
}
|
||||
else if (documentType.DocumentCategory!.EntityTypeId == ProjectEntity)
|
||||
{
|
||||
fileName = _s3Service.GenerateFileName(fileType, tenantId, "ProjectDocuments");
|
||||
objectKey = $"tenant-{tenantId}/project-{model.EntityId}/ProjectDocuments/{fileName}";
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(objectKey) && !string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
var _s3UploadService = scope.ServiceProvider.GetRequiredService<S3UploadService>();
|
||||
var _threadLogger = scope.ServiceProvider.GetRequiredService<ILoggingService>();
|
||||
|
||||
await _s3UploadService.UploadFileAsync(base64, fileType, objectKey!);
|
||||
|
||||
_threadLogger.LogInfo("File stored successfully {ObjectKey}", objectKey!);
|
||||
});
|
||||
|
||||
Document document = new Document
|
||||
{
|
||||
BatchId = batchId,
|
||||
UploadedById = loggedInEmployee.Id,
|
||||
FileName = model.Attachment.FileName ?? fileName,
|
||||
ContentType = model.Attachment.ContentType,
|
||||
S3Key = objectKey,
|
||||
FileSize = model.Attachment.FileSize,
|
||||
UploadedAt = DateTime.UtcNow,
|
||||
TenantId = tenantId
|
||||
};
|
||||
_context.Documents.Add(document);
|
||||
|
||||
documentDetails.DocumentDataId = document.Id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
_context.DocumentAttachments.Add(documentDetails);
|
||||
|
||||
if (model.Tags != null && model.Tags.Any())
|
||||
{
|
||||
var names = model.Tags.Select(t => t.Name).ToList();
|
||||
var existingTags = await _context.DocumentTagMasters.Where(t => names.Contains(t.Name) && t.TenantId == tenantId).ToListAsync();
|
||||
List<AttachmentTagMapping> attachmentTagMappings = new List<AttachmentTagMapping>();
|
||||
foreach (var tag in model.Tags)
|
||||
{
|
||||
var existingTag = existingTags.FirstOrDefault(t => t.Name == tag.Name);
|
||||
if (existingTag != null && tag.IsActive)
|
||||
{
|
||||
AttachmentTagMapping attachmentTagMapping = new AttachmentTagMapping
|
||||
{
|
||||
DocumentTagId = existingTag.Id,
|
||||
AttachmentId = documentDetails.Id,
|
||||
TenantId = tenantId
|
||||
};
|
||||
attachmentTagMappings.Add(attachmentTagMapping);
|
||||
}
|
||||
else if (existingTag == null && tag.IsActive)
|
||||
{
|
||||
var newTag = new DocumentTagMaster
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = tag.Name,
|
||||
Description = tag.Name,
|
||||
TenantId = tenantId
|
||||
};
|
||||
_context.DocumentTagMasters.Add(newTag);
|
||||
AttachmentTagMapping attachmentTagMapping = new AttachmentTagMapping
|
||||
{
|
||||
DocumentTagId = newTag.Id,
|
||||
AttachmentId = documentDetails.Id,
|
||||
TenantId = tenantId
|
||||
};
|
||||
attachmentTagMappings.Add(attachmentTagMapping);
|
||||
}
|
||||
}
|
||||
_context.AttachmentTagMappings.AddRange(attachmentTagMappings);
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
var response = _mapper.Map<DocumentListVM>(documentDetails);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(response, "Document Added Successfully", 200));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uploads a document attachment for an Employee or Project.
|
||||
/// Validates permissions, document type, entity existence, tags, and uploads to S3.
|
||||
@ -345,9 +278,9 @@ namespace Marco.Pms.Services.Controllers
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Document ID missing", "User must provide the document ID for this document", 400));
|
||||
}
|
||||
|
||||
if (documentType.IsValidationRequired && !string.IsNullOrWhiteSpace(model.DocumentId))
|
||||
if (documentType.IsValidationRequired && !string.IsNullOrWhiteSpace(model.DocumentId) && !string.IsNullOrWhiteSpace(documentType.RegexExpression))
|
||||
{
|
||||
if (!Regex.IsMatch(model.DocumentId, documentType.RegexExpression ?? ""))
|
||||
if (!Regex.IsMatch(model.DocumentId, documentType.RegexExpression))
|
||||
{
|
||||
logger.LogWarning("Invalid DocumentId format for DocumentTypeId: {DocumentTypeId}, Provided: {DocumentId}", documentType.Id, model.DocumentId);
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Document ID", "Provided document ID is not valid", 400));
|
||||
@ -443,6 +376,17 @@ namespace Marco.Pms.Services.Controllers
|
||||
|
||||
dbContext.DocumentAttachments.Add(attachment);
|
||||
|
||||
//Process Versioning
|
||||
|
||||
var versionMapping = new AttachmentVersionMapping
|
||||
{
|
||||
ParentAttachmentId = attachment.Id,
|
||||
ChildAttachmentId = attachment.Id,
|
||||
Version = 1,
|
||||
TenantId = tenantId
|
||||
};
|
||||
dbContext.AttachmentVersionMappings.Add(versionMapping);
|
||||
|
||||
// Process Tags
|
||||
if (model.Tags?.Any() == true)
|
||||
{
|
||||
@ -487,6 +431,9 @@ namespace Marco.Pms.Services.Controllers
|
||||
|
||||
var response = _mapper.Map<DocumentListVM>(attachment);
|
||||
response.UploadedBy = _mapper.Map<BasicEmployeeVM>(loggedInEmployee);
|
||||
response.ParentAttachmentId = versionMapping.ParentAttachmentId;
|
||||
response.Version = versionMapping.Version;
|
||||
|
||||
return Ok(ApiResponse<object>.SuccessResponse(response, "Document added successfully", 200));
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
x
Reference in New Issue
Block a user