pramod_Task#474 #88
@ -72,6 +72,7 @@ namespace Marco.Pms.DataAccess.Data
|
|||||||
public DbSet<MailLog> MailLogs { get; set; }
|
public DbSet<MailLog> MailLogs { get; set; }
|
||||||
public DbSet<OTPDetails> OTPDetails { get; set; }
|
public DbSet<OTPDetails> OTPDetails { get; set; }
|
||||||
public DbSet<MPINDetails> MPINDetails { get; set; }
|
public DbSet<MPINDetails> MPINDetails { get; set; }
|
||||||
|
public DbSet<DocumentMaster> DocumentMasters { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
2716
Marco.Pms.DataAccess/Migrations/20250606172106_Added_DocumentMaster.Designer.cs
generated
Normal file
2716
Marco.Pms.DataAccess/Migrations/20250606172106_Added_DocumentMaster.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Marco.Pms.DataAccess.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class Added_DocumentMaster : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "DocumentMasters",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||||
|
Name = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
Description = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
Type = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
ValidationException = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
IsRequired = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||||
|
TenantId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_DocumentMasters", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_DocumentMasters_Tenants_TenantId",
|
||||||
|
column: x => x.TenantId,
|
||||||
|
principalTable: "Tenants",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_DocumentMasters_TenantId",
|
||||||
|
table: "DocumentMasters",
|
||||||
|
column: "TenantId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "DocumentMasters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1065,6 +1065,41 @@ namespace Marco.Pms.DataAccess.Migrations
|
|||||||
b.ToTable("ActivityMasters");
|
b.ToTable("ActivityMasters");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Marco.Pms.Model.Master.DocumentMaster", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<bool>("IsRequired")
|
||||||
|
.HasColumnType("tinyint(1)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<Guid>("TenantId")
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
|
b.Property<string>("Type")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("ValidationException")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("TenantId");
|
||||||
|
|
||||||
|
b.ToTable("DocumentMasters");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Marco.Pms.Model.Master.Feature", b =>
|
modelBuilder.Entity("Marco.Pms.Model.Master.Feature", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@ -2420,6 +2455,17 @@ namespace Marco.Pms.DataAccess.Migrations
|
|||||||
b.Navigation("Tenant");
|
b.Navigation("Tenant");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Marco.Pms.Model.Master.DocumentMaster", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Marco.Pms.Model.Entitlements.Tenant", "Tenant")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("TenantId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Tenant");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Marco.Pms.Model.Master.Feature", b =>
|
modelBuilder.Entity("Marco.Pms.Model.Master.Feature", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Marco.Pms.Model.Master.Module", "Module")
|
b.HasOne("Marco.Pms.Model.Master.Module", "Module")
|
||||||
|
16
Marco.Pms.Model/Dtos/Master/DocumentMasterDto.cs
Normal file
16
Marco.Pms.Model/Dtos/Master/DocumentMasterDto.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
namespace Marco.Pms.Model.Dtos.Master
|
||||||
|
{
|
||||||
|
public class DocumentMasterDto
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public string? Type { get; set; }
|
||||||
|
|
||||||
|
public string? ValidationException { get; set; }
|
||||||
|
|
||||||
|
public bool IsRequired { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
21
Marco.Pms.Model/Master/DocumentMaster.cs
Normal file
21
Marco.Pms.Model/Master/DocumentMaster.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using Marco.Pms.Model.Utilities;
|
||||||
|
|
||||||
|
namespace Marco.Pms.Model.Master
|
||||||
|
{
|
||||||
|
public class DocumentMaster :TenantRelation
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Description { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string ValidationException { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public bool IsRequired { get; set; } = false;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -667,5 +667,172 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return NotFound(ApiResponse<object>.ErrorResponse("Work category not found", "Work category not found", 404));
|
return NotFound(ApiResponse<object>.ErrorResponse("Work category not found", "Work category not found", 404));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------Document-------------------------------------
|
||||||
|
[HttpGet("documents")]
|
||||||
|
public async Task<IActionResult> GetDocumentMaster()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
|
||||||
|
var documentMast = await _context.DocumentMasters
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(d => d.TenantId == tenantId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(documentMast, "Document List", 200));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ApiResponse<object>.ErrorResponse("An error occurred", ex.Message, 500));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpPost("document")]
|
||||||
|
public async Task<IActionResult> CreateDocument([FromBody] DocumentMasterDto documentMaster)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (documentMaster == null)
|
||||||
|
{
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("User sent empty payload", "User sent empty payload", 400));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(documentMaster.Name) ||
|
||||||
|
string.IsNullOrWhiteSpace(documentMaster.Type) ||
|
||||||
|
string.IsNullOrWhiteSpace(documentMaster.Description) ||
|
||||||
|
string.IsNullOrWhiteSpace(documentMaster.ValidationException))
|
||||||
|
{
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("One or more required fields are empty", "Invalid input", 400));
|
||||||
|
}
|
||||||
|
|
||||||
|
var tenantId = _userHelper.GetTenantId();
|
||||||
|
|
||||||
|
var existingDocument = await _context.DocumentMasters
|
||||||
|
.FirstOrDefaultAsync(u => u.Name == documentMaster.Name && u.TenantId == tenantId);
|
||||||
|
|
||||||
|
if (existingDocument != null)
|
||||||
|
{
|
||||||
|
return Conflict(ApiResponse<object>.ErrorResponse("Document already exists", "Document already exists", 409));
|
||||||
|
}
|
||||||
|
|
||||||
|
var newDocument = new DocumentMaster
|
||||||
|
{
|
||||||
|
Name = documentMaster.Name,
|
||||||
|
Type = documentMaster.Type,
|
||||||
|
Description = documentMaster.Description,
|
||||||
|
ValidationException = documentMaster.ValidationException,
|
||||||
|
IsRequired = documentMaster.IsRequired,
|
||||||
|
TenantId = tenantId
|
||||||
|
};
|
||||||
|
|
||||||
|
await _context.DocumentMasters.AddAsync(newDocument);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(newDocument,"Document created successfully", 200));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ApiResponse<object>.ErrorResponse("An unexpected error occurred", ex.Message, 500));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("document/edit/{id}")]
|
||||||
|
public async Task<IActionResult> UpdateDocument([FromBody] DocumentMasterDto documentMaster, [FromRoute] Guid id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
|
||||||
|
if (documentMaster == null)
|
||||||
|
{
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("User sent empty payload", "User sent empty payload", 400));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(documentMaster.Name) ||
|
||||||
|
string.IsNullOrWhiteSpace(documentMaster.Type) ||
|
||||||
|
string.IsNullOrWhiteSpace(documentMaster.Description) ||
|
||||||
|
string.IsNullOrWhiteSpace(documentMaster.ValidationException))
|
||||||
|
{
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("One or more required fields are empty", "Invalid input", 400));
|
||||||
|
}
|
||||||
|
var existingDocument = await _context.DocumentMasters
|
||||||
|
.FirstOrDefaultAsync(d => d.Id == id && d.TenantId == tenantId);
|
||||||
|
|
||||||
|
if (existingDocument == null)
|
||||||
|
{
|
||||||
|
return NotFound(ApiResponse<object>.ErrorResponse("Document not found", $"No document found with ID {id}", 404));
|
||||||
|
}
|
||||||
|
|
||||||
|
var nameExisten = await _context.DocumentMasters.AnyAsync(d => d.Name == documentMaster.Name && d.Id != id && d.TenantId == tenantId);
|
||||||
|
|
||||||
|
if (nameExisten)
|
||||||
|
{
|
||||||
|
return Conflict(ApiResponse<object>.ErrorResponse("Another document with the same name exists", "Duplicate name", 409));
|
||||||
|
}
|
||||||
|
|
||||||
|
existingDocument.Name = documentMaster.Name;
|
||||||
|
existingDocument.Type = documentMaster.Type;
|
||||||
|
existingDocument.Description = documentMaster.Description;
|
||||||
|
existingDocument.ValidationException = documentMaster.ValidationException;
|
||||||
|
existingDocument.IsRequired = documentMaster.IsRequired;
|
||||||
|
|
||||||
|
_context.DocumentMasters.Update(existingDocument);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
|
||||||
|
var updatedDto = new DocumentMaster
|
||||||
|
{
|
||||||
|
Id = existingDocument.Id,
|
||||||
|
Name = existingDocument.Name,
|
||||||
|
Type = existingDocument.Type,
|
||||||
|
Description = existingDocument.Description,
|
||||||
|
ValidationException = existingDocument.ValidationException,
|
||||||
|
IsRequired = existingDocument.IsRequired
|
||||||
|
// Add other fields as needed
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(updatedDto,"Document updated successfully", 200));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ApiResponse<object>.ErrorResponse("An error occurred", ex.Message, 500));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpDelete("document/{id}")]
|
||||||
|
public async Task<IActionResult> DeleteDocument([FromRoute] Guid id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Guid tenantId = _userHelper.GetTenantId();
|
||||||
|
|
||||||
|
var document = await _context.DocumentMasters
|
||||||
|
.FirstOrDefaultAsync(d => d.Id == id && d.TenantId == tenantId);
|
||||||
|
|
||||||
|
if (document == null)
|
||||||
|
{
|
||||||
|
return NotFound(ApiResponse<object>.ErrorResponse("Document not found", $"No document found with ID {id}", 404));
|
||||||
|
}
|
||||||
|
|
||||||
|
_context.DocumentMasters.Remove(document);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return Ok(ApiResponse<string>.SuccessResponse("Document deleted successfully", "Success", 200));
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ApiResponse<object>.ErrorResponse("An error occurred", ex.Message, 500));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user