Compare commits

...

113 Commits

Author SHA1 Message Date
3a37cfdf37 Resloved conflicts 2025-05-31 19:01:13 +05:30
4282966afd resloved rebase conflicts 2025-05-31 18:58:20 +05:30
03b62cd27b fixed the bug of only sending ID of logged in employee in Bucket object 2025-05-31 18:55:18 +05:30
ff2b33a66d Stopping multiple entries in employee-bucket mapping table 2025-05-31 18:55:18 +05:30
85b327d0c4 Sending last updatedBy and updatedAt when sending list of notes 2025-05-31 18:55:18 +05:30
da797b2208 Included object consist of basic infromation of employee who created the bucket in View models 2025-05-31 18:55:18 +05:30
8ef654ad2e Sending number of conacts within the bucket with it information in API Update bucket, Assign Bucket, and Get Bucket List 2025-05-31 18:55:18 +05:30
738d1e6a0a Corrected Spelling mistakes 2025-05-31 18:55:18 +05:30
56645ff40f Implemented an API to delete a Bucket 2025-05-31 18:55:18 +05:30
193add07e1 Implement API to Assign Bucket to Employees 2025-05-31 18:55:18 +05:30
bd969616ad Enhancement #381: Update "Update Bucket" API to Enforce Feature 2025-05-31 18:55:18 +05:30
c2ddd6097c Enhancement #380: Update "Create Bucket" API to Enforce Feature 2025-05-31 18:55:18 +05:30
b5707ba133 Enhancement #378: Update "Get Bucket List" API to Enforce Feature 2025-05-31 18:55:18 +05:30
a0cc285d6f Enhancement #377: Update "Update Contact" API to Enforce Feature 2025-05-31 18:55:18 +05:30
10df95c481 Enhancement #376: Update "Get Contact by Bucket ID" API to Enforce Feature Permissions 2025-05-31 18:55:18 +05:30
5908b54312 Enhancement #375: Update "Get Contact" API to Enforce Feature Permissions 2025-05-31 18:55:18 +05:30
6b80c3bfeb Add Directory Management Feature with Permission Handling 2025-05-31 18:55:14 +05:30
8820483584 Created an API to get contact profile by its Id 2025-05-31 18:49:45 +05:30
93e1b13f54 Added an API to suspend a n existing Contact-note 2025-05-31 18:44:09 +05:30
dff77aa22f Added an API to Update existing Contact-note 2025-05-31 18:44:09 +05:30
75cb4557e4 Added functionality to stop recreating tas of same name 2025-05-31 18:42:26 +05:30
e9157d7985 properly mapped the updated Dto to contact table 2025-05-31 18:40:33 +05:30
86ebc95ada added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 18:39:54 +05:30
b0aefdc93a Revert "added an API to get list of contacts by bucket id and added project- contact mapping table"
This reverts commit 22f777ca87053d2c79db610a27b8d7a5169e57bc.
2025-05-31 18:37:43 +05:30
f6685a1ca5 added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 18:35:39 +05:30
fd14670914 Added an API to Get a list of buckets Assigned to that employee 2025-05-31 18:32:44 +05:30
b161ed7c15 Created an endpoint to fetch list of all contact category in that tenant 2025-05-31 18:31:10 +05:30
Pramod Mahajan
e4a611ccc2 created GetListOfContact custome function 2025-05-31 18:27:27 +05:30
cc06c2dfc4 Added an API to suspend a n existing Contact-note 2025-05-31 18:00:09 +05:30
29fa0e87d1 Added an API to Update existing Contact-note 2025-05-31 18:00:09 +05:30
852124d971 added an API to get a list of contact-notes by contact ID 2025-05-31 17:58:51 +05:30
45897b99cb Added functionality to stop recreating tas of same name 2025-05-31 17:53:35 +05:30
7ae001e277 properly mapped the updated Dto to contact table 2025-05-31 17:50:04 +05:30
b7a9d6148d added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 17:49:27 +05:30
244a6cc547 Revert "added an API to get list of contacts by bucket id and added project- contact mapping table"
This reverts commit 22f777ca87053d2c79db610a27b8d7a5169e57bc.
2025-05-31 17:46:15 +05:30
4cebaba540 added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 17:44:59 +05:30
Pramod Mahajan
040e9c311b added api to get list of contact tag 2025-05-31 17:37:45 +05:30
62734fc583 Created an endpoint to fetch list of all contact category in that tenant 2025-05-31 17:28:05 +05:30
20efab871a Added an API to create contact and populate related tables as well 2025-05-31 17:23:01 +05:30
39224c7ed7 Added Migration for contact related tables 2025-05-31 17:12:15 +05:30
2119171291 Models, DTOs (Data Transfer Objects), and view models have been created for the directory. 2025-05-31 17:02:10 +05:30
2339384b5e Add Directory Management Feature with Permission Handling 2025-05-31 16:57:54 +05:30
02a7791041 Implemented an API to update Contact Category Master 2025-05-31 16:57:54 +05:30
c00d1a5451 Implemented an API to update Buckets for grouping contacts. 2025-05-31 16:57:54 +05:30
e917ff3e9c Accepting List of buckets and categories Ids rather than as payload 2025-05-31 16:57:53 +05:30
cd091eda56 Implemented filtering functionality for Get Contact List API 2025-05-31 16:57:53 +05:30
aa6df0f803 Update Marco.Pms.Services/Helpers/DirectoryHelper.cs
Added entrie to DirectoryUpdateLog Table
2025-05-31 16:57:53 +05:30
2e64f4de32 Implemented an API to suspend a Contact 2025-05-31 16:57:53 +05:30
Pramod Mahajan
8c9ce52ec2 created api for contact Tag Update 2025-05-31 16:57:53 +05:30
635654890e Implemented an API to retrieve a list of organizations provided in the contacts. 2025-05-31 16:57:53 +05:30
fbfd04c898 changed all list in contact profile view model to non-nullable and set default value to empty list 2025-05-31 16:57:53 +05:30
92e6942437 Created an API to get contact profile by its Id 2025-05-31 16:57:53 +05:30
04216791f7 Changed tag validation 2025-05-31 16:57:53 +05:30
0b308c776b Addd migrations fro Typo 2025-05-31 16:57:53 +05:30
6704e168c3 Corrected the typo of ContactTagtId to ContactTagId 2025-05-31 16:57:52 +05:30
70c9d4bb3d Added an API to suspend a n existing Contact-note 2025-05-31 16:57:52 +05:30
3b1b6e9d89 Added an API to Update existing Contact-note 2025-05-31 16:57:52 +05:30
a31b4b73ab Added an API to get contact category by its size 2025-05-31 16:57:52 +05:30
0973e722fb Added functionality to stop recreating tas of same name 2025-05-31 16:57:52 +05:30
f1e3febfb0 properly mapped the updated Dto to contact table 2025-05-31 16:57:52 +05:30
3ab215b401 added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 16:57:52 +05:30
e6f8cc626b Added an API to delete existing contact category 2025-05-31 16:57:52 +05:30
cedf3d19b5 Revert "added an API to get list of contacts by bucket id and added project- contact mapping table"
This reverts commit 22f777ca87053d2c79db610a27b8d7a5169e57bc.
2025-05-31 16:57:52 +05:30
b4cffbf713 added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 16:57:51 +05:30
f18b1f8dea When checking in exsiting tag change Id from mapping Id to Tag ID 2025-05-31 16:57:51 +05:30
c78c9a92b4 Added an API to create bucket 2025-05-31 16:57:51 +05:30
3f0d6f26fc Added an API to create a contact tag 2025-05-31 16:57:51 +05:30
ec72632004 Added an API to Get a list of buckets Assigned to that employee 2025-05-31 16:57:51 +05:30
Pramod Mahajan
4060d7d1f2 added api to get list of contact tag 2025-05-31 16:57:51 +05:30
12a1e1cf27 Added an API to update existing contact 2025-05-31 16:57:51 +05:30
ca561711de Created an endpoint to fetch list of all contact category in that tenant 2025-05-31 16:57:51 +05:30
acffebfb90 Added logs to the 'Get List of Contacts' endpoint. 2025-05-31 16:57:51 +05:30
f785003e9b Added an API to create contact and populate related tables as well 2025-05-31 16:57:51 +05:30
Pramod Mahajan
f7dce83629 created GetListOfContact custome function 2025-05-31 16:57:51 +05:30
df1408b63a Models, DTOs (Data Transfer Objects), and view models have been created for the directory. 2025-05-31 16:57:51 +05:30
77306c6bdb Added an API to add a note to specific contact 2025-05-31 16:57:51 +05:30
7660063ac3 Added an API to suspend a n existing Contact-note 2025-05-31 16:57:51 +05:30
ebc4a1e071 Added an API to Update existing Contact-note 2025-05-31 16:57:51 +05:30
f1c6468e47 Added an API to get contact category by its size 2025-05-31 16:57:50 +05:30
ae20e215db added an API to get a list of contact-notes by contact ID 2025-05-31 16:57:50 +05:30
b9b06ba54c Added an API to deleted ContactTag as well remove entries in contact-tag mapping table related to that tag 2025-05-31 16:57:50 +05:30
ba38c857a2 Added functionality to stop recreating tas of same name 2025-05-31 16:57:50 +05:30
f42ebe3886 properly mapped the updated Dto to contact table 2025-05-31 16:57:50 +05:30
85d7863fb2 Refetched the contact in update contact API 2025-05-31 16:57:50 +05:30
9709893603 added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 16:57:50 +05:30
922eb7bc0d Added an API to delete existing contact category 2025-05-31 16:57:50 +05:30
de324407d0 Revert "added an API to get list of contacts by bucket id and added project- contact mapping table"
This reverts commit 22f777ca87053d2c79db610a27b8d7a5169e57bc.
2025-05-31 16:57:50 +05:30
9247221a9f added an API to get list of contacts by bucket id and added project- contact mapping table 2025-05-31 16:57:50 +05:30
4b4ebee1a1 When checking in exsiting tag change Id from mapping Id to Tag ID 2025-05-31 16:57:50 +05:30
49ddd3ec45 Added an API to create bucket 2025-05-31 16:57:50 +05:30
8ab737fe8a Fixed the errorof finding tag in wrong table 2025-05-31 16:57:50 +05:30
7f5f3da5fb Added an API to create a contact tag 2025-05-31 16:57:49 +05:30
684598eb6b Added an API to Get a list of buckets Assigned to that employee 2025-05-31 16:57:49 +05:30
Pramod Mahajan
adc31a6909 added api to get list of contact tag 2025-05-31 16:57:49 +05:30
b3d4018c5f Added an API to update existing contact 2025-05-31 16:57:49 +05:30
84b1e7de0b Created an endpoint to fetch list of all contact category in that tenant 2025-05-31 16:57:49 +05:30
783c6576de Created an API to create the Contact category 2025-05-31 16:57:49 +05:30
66b8a74873 Added logs to the 'Get List of Contacts' endpoint. 2025-05-31 16:57:49 +05:30
c2bdf76957 Added an API to create contact and populate related tables as well 2025-05-31 16:57:49 +05:30
a8b935946a Added an API to create contact and populate related tables as well 2025-05-31 16:57:49 +05:30
Pramod Mahajan
40c0bcd3ca created GetListOfContact custome function 2025-05-31 16:57:49 +05:30
bba751256e Added DirectoryHelper in helper folder 2025-05-31 16:57:49 +05:30
bb8c314723 Added Migration for contact related tables 2025-05-31 16:57:44 +05:30
07bec97973 An API skeleton has been added. 2025-05-31 16:56:36 +05:30
ba486cffd8 Added Directory controller file 2025-05-31 16:56:36 +05:30
260ea2214d Models, DTOs (Data Transfer Objects), and view models have been created for the directory. 2025-05-31 16:56:36 +05:30
c85c6f4df5 revert c7e89630eb494454c1322bdf4cf29ab076af7b86
revert Models, DTOs (Data Transfer Objects), and view models have been created for the directory.
2025-05-31 16:56:36 +05:30
2cb283f1cd Models, DTOs (Data Transfer Objects), and view models have been created for the directory. 2025-05-31 16:56:36 +05:30
ba92a3b3ed Fixed the Internal error of swagger 2025-05-31 15:11:35 +05:30
2f3203c524 Added pending report and todays assigned conut in activity report view model 2025-05-31 09:46:29 +05:30
b479c7cf19 Merge pull request 'Implement an API to store employee information with a captured image and update employee information.' (#78) from Ashutosh_Enhancement#413_Manage_Employee into Issue_May_5W
Reviewed-on: #78
2025-05-30 12:29:50 +00:00
e73d3e0744 Taking emailids and email body from database rather than local or hardcoded as well logging every mail to database 2025-05-30 17:46:51 +05:30
98409f5b87 Implement an API to store employee information with a captured image and update employee information. 2025-05-30 16:57:10 +05:30
21 changed files with 3325 additions and 386 deletions

View File

@ -7,6 +7,7 @@ using Marco.Pms.Model.DocumentManager;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Entitlements;
using Marco.Pms.Model.Forum;
using Marco.Pms.Model.Mail;
using Marco.Pms.Model.Master;
using Marco.Pms.Model.Projects;
using Marco.Pms.Model.Roles;
@ -29,53 +30,30 @@ namespace Marco.Pms.DataAccess.Data
}
public DbSet<RefreshToken> RefreshTokens { get; set; }
public DbSet<Tenant> Tenants { get; set; }
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<ActivityMaster> ActivityMasters { get; set; }
public DbSet<Project> Projects { get; set; }
public DbSet<ProjectAllocation> ProjectAllocations { get; set; }
public DbSet<StatusMaster> StatusMasters { get; set; }
public DbSet<Building> Buildings { get; set; }
public DbSet<Floor> Floor { get; set; }
public DbSet<WorkArea> WorkAreas { get; set; }
public DbSet<WorkItem> WorkItems { get; set; }
//public DbSet<WorkItemMapping> WorkItemMapping { get; set; }
public DbSet<WorkShift> WorkShifts { get; set; }
public DbSet<TaskAllocation> TaskAllocations { get; set; }
public DbSet<TaskComment> TaskComments { get; set; }
public DbSet<TaskMembers> TaskMembers { get; set; }
// public DbSet<Attendance> Attendances { get; set; }
public DbSet<Attendance> Attendes { get; set; }
public DbSet<AttendanceLog> AttendanceLogs { get; set; }
// public DbSet<AttendLog> AttendLogs { get; set; }
public DbSet<Employee> Employees { get; set; }
public DbSet<EmployeeRoleMapping> EmployeeRoleMappings { get; set; }
public DbSet<Module> Modules { get; set; }
public DbSet<Feature> Features { get; set; }
public DbSet<FeaturePermission> FeaturePermissions { get; set; }
public DbSet<ApplicationRole> ApplicationRoles { get; set; }
public DbSet<JobRole> JobRoles { get; set; }
public DbSet<RolePermissionMappings> RolePermissionMappings { get; set; }
public DbSet<Industry> Industries { get; set; }
public DbSet<ActivityCheckList> ActivityCheckLists { get; set; }
public DbSet<CheckListMappings> CheckListMappings { get; set; }
@ -103,6 +81,10 @@ namespace Marco.Pms.DataAccess.Data
public DbSet<DirectoryUpdateLog> DirectoryUpdateLogs { get; set; }
public DbSet<ContactProjectMapping> ContactProjectMappings { get; set; }
public DbSet<MailingList> MailingList { get; set; }
public DbSet<MailDetails> MailDetails { get; set; }
public DbSet<MailLog> MailLogs { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,99 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Marco.Pms.DataAccess.Migrations
{
/// <inheritdoc />
public partial class Added_Mail_Related_Tables : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "MailingList",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Title = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Body = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Keywords = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
TenantId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_MailingList", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "MailLogs",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
ProjectId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Body = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
EmailId = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
TimeStamp = table.Column<DateTime>(type: "datetime(6)", nullable: false),
TenantId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
EmployeeId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_MailLogs", x => x.Id);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "MailDetails",
columns: table => new
{
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
ProjectId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
Recipient = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Subject = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
Schedule = table.Column<string>(type: "longtext", nullable: false)
.Annotation("MySql:CharSet", "utf8mb4"),
MailListId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
TenantId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci")
},
constraints: table =>
{
table.PrimaryKey("PK_MailDetails", x => x.Id);
table.ForeignKey(
name: "FK_MailDetails_MailingList_MailListId",
column: x => x.MailListId,
principalTable: "MailingList",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
})
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateIndex(
name: "IX_MailDetails_MailListId",
table: "MailDetails",
column: "MailListId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "MailDetails");
migrationBuilder.DropTable(
name: "MailLogs");
migrationBuilder.DropTable(
name: "MailingList");
}
}
}

View File

@ -1240,6 +1240,97 @@ namespace Marco.Pms.DataAccess.Migrations
});
});
modelBuilder.Entity("Marco.Pms.Model.Mail.MailDetails", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<Guid>("MailListId")
.HasColumnType("char(36)");
b.Property<Guid>("ProjectId")
.HasColumnType("char(36)");
b.Property<string>("Recipient")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Schedule")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("longtext");
b.Property<Guid>("TenantId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("MailListId");
b.ToTable("MailDetails");
});
modelBuilder.Entity("Marco.Pms.Model.Mail.MailLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("EmailId")
.IsRequired()
.HasColumnType("longtext");
b.Property<Guid?>("EmployeeId")
.HasColumnType("char(36)");
b.Property<Guid>("ProjectId")
.HasColumnType("char(36)");
b.Property<Guid>("TenantId")
.HasColumnType("char(36)");
b.Property<DateTime>("TimeStamp")
.HasColumnType("datetime(6)");
b.HasKey("Id");
b.ToTable("MailLogs");
});
modelBuilder.Entity("Marco.Pms.Model.Mail.MailingList", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("longtext");
b.Property<string>("Keywords")
.IsRequired()
.HasColumnType("longtext");
b.Property<Guid>("TenantId")
.HasColumnType("char(36)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("longtext");
b.HasKey("Id");
b.ToTable("MailingList");
});
modelBuilder.Entity("Marco.Pms.Model.Master.ActivityMaster", b =>
{
b.Property<Guid>("Id")
@ -2794,6 +2885,17 @@ namespace Marco.Pms.DataAccess.Migrations
b.Navigation("Ticket");
});
modelBuilder.Entity("Marco.Pms.Model.Mail.MailDetails", b =>
{
b.HasOne("Marco.Pms.Model.Mail.MailingList", "MailBody")
.WithMany()
.HasForeignKey("MailListId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("MailBody");
});
modelBuilder.Entity("Marco.Pms.Model.Master.ActivityMaster", b =>
{
b.HasOne("Marco.Pms.Model.Entitlements.Tenant", "Tenant")

View File

@ -30,21 +30,15 @@
// public int TenantId { get; set; }
}
public class CreateQuickUserDto
public class MobileUserManageDto
{
public Guid Id { get; set; }
public string? FirstName { get; set; }
public Guid? Id { get; set; }
public string FirstName { get; set; } = string.Empty;
public string? LastName { get; set; }
public string PhoneNumber { get; set; } = string.Empty;
public string? Gender { get; set; }
public string? CurrentAddress { get; set; }
public string? PhoneNumber { get; set; }
public string? EmergencyPhoneNumber { get; set; }
public string? EmergencyContactPerson { get; set; }
public Guid? JobRoleId { get; set; }
public Guid JobRoleId { get; set; }
public string? ProfileImage { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace Marco.Pms.Model.Dtos.Mail
{
public class MailDetailsDto
{
public Guid ProjectId { get; set; }
public string Recipient { get; set; } = string.Empty; // Eamil Address of recipient
public string Subject { get; set; } = string.Empty;
public string Schedule { get; set; } = string.Empty; // json object which includes when to send mail and at what interval
public Guid MailListId { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace Marco.Pms.Model.Dtos.Mail
{
public class MailTemeplateDto
{
public string Title { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public string Keywords { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
namespace Marco.Pms.Model.Mail
{
public class MailDetails
{
public Guid Id { get; set; }
public Guid ProjectId { get; set; }
public string Recipient { get; set; } = string.Empty; // Eamil Address of recipient
public string Subject { get; set; } = string.Empty; // Eamil Address of recipient
public string Schedule { get; set; } = string.Empty; // json object which includes when to send mail and at what interval
public Guid MailListId { get; set; }
[ValidateNever]
[ForeignKey(nameof(MailListId))]
public MailingList? MailBody { get; set; }
public Guid TenantId { get; set; }
}
}

View File

@ -0,0 +1,13 @@
namespace Marco.Pms.Model.Mail
{
public class MailLog
{
public Guid Id { get; set; }
public Guid ProjectId { get; set; }
public string Body { get; set; } = string.Empty;
public string EmailId { get; set; } = string.Empty;
public DateTime TimeStamp { get; set; }
public Guid TenantId { get; set; }
public Guid? EmployeeId { get; set; }
}
}

View File

@ -0,0 +1,11 @@
namespace Marco.Pms.Model.Mail
{
public class MailingList
{
public Guid Id { get; set; }
public string Title { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public string Keywords { get; set; } = string.Empty; // Comma seprated list of variables in mail body
public Guid TenantId { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Dtos.Employees;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.ViewModels.Activities;
using Marco.Pms.Model.ViewModels.Employee;
@ -8,6 +9,11 @@ namespace Marco.Pms.Model.Mapper
{
public static EmployeeVM ToEmployeeVMFromEmployee(this Employee model)
{
string? base64String = null;
if ((model.Photo != null))
{
base64String = Convert.ToBase64String(model.Photo);
}
return new EmployeeVM
{
Id = model.Id,
@ -27,7 +33,7 @@ namespace Marco.Pms.Model.Mapper
PanNumber = model.PanNumber,
PermanentAddress = model.PermanentAddress,
PhoneNumber = model.PhoneNumber,
Photo = model.Photo,
Photo = base64String,
IsActive = model.IsActive,
IsSystem = model.IsSystem,
JoiningDate = model.JoiningDate
@ -45,5 +51,30 @@ namespace Marco.Pms.Model.Mapper
JobRoleName = employee.JobRole != null ? employee.JobRole.Name : ""
};
}
public static Employee ToEmployeeFromMobileUserManageDto(this MobileUserManageDto model, Guid TenantId, byte[]? image)
{
return new Employee
{
ApplicationUserId = null,
FirstName = model.FirstName,
LastName = model.LastName,
Email = string.Empty,
TenantId = TenantId,
CurrentAddress = string.Empty,
BirthDate = null,
EmergencyPhoneNumber = string.Empty,
EmergencyContactPerson = string.Empty,
AadharNumber = string.Empty,
Gender = model.Gender,
MiddleName = string.Empty,
PanNumber = string.Empty,
PermanentAddress = string.Empty,
PhoneNumber = model.PhoneNumber,
Photo = image,
JobRoleId = model.JobRoleId,
JoiningDate = null,
};
}
}
}

View File

@ -5,5 +5,7 @@
public List<PerformedActivites>? PerformedActivites { get; set; }
public double TotalPlannedWork { get; set; }
public double TotalCompletedWork { get; set; }
public int ReportPending { get; set; }
public int TodaysAssigned { get; set; }
}
}

View File

@ -6,8 +6,6 @@
public string? FloorName { get; set; }
public string? WorkAreaName { get; set; }
public string? ActivityName { get; set; }
public string? Comment { get; set; }
public double Pending { get; set; }
public double AssignedToday { get; set; }
public double CompletedToday { get; set; }

View File

@ -23,7 +23,7 @@
public bool IsActive { get; set; } = true;
public string? PanNumber { get; set; }
public byte[]? Photo { get; set; } // To store the captured photo
public string? Photo { get; set; } // To store the captured photo
public string? ApplicationUserId { get; set; }

View File

@ -159,7 +159,6 @@ namespace Marco.Pms.Services.Controllers
return Ok(ApiResponse<object>.SuccessResponse(projectDashboardVM, "Success", 200));
}
[HttpGet("teams")]
public async Task<IActionResult> GetTotalEmployees()
{
@ -223,7 +222,7 @@ namespace Marco.Pms.Services.Controllers
return NotFound(ApiResponse<object>.ErrorResponse("No attendance entry was found for this employee", "No attendance entry was found for this employee", 404));
}
[HttpGet("project-attdendance/{projectId}")]
[HttpGet("project-attendance/{projectId}")]
public async Task<IActionResult> GetProjectAttendance(Guid projectId, [FromQuery] string? date)
{
Guid tenantId = _userHelper.GetTenantId();
@ -277,7 +276,6 @@ namespace Marco.Pms.Services.Controllers
return Ok(ApiResponse<object>.SuccessResponse(projectAttendanceVM, $"Attendance record for project {project.Name} for date {currentDate.Date}", 200));
}
[HttpGet("activities/{projectId}")]
public async Task<IActionResult> GetActivities(Guid projectId, [FromQuery] string? date)
{
@ -285,7 +283,6 @@ namespace Marco.Pms.Services.Controllers
var LoggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
DateTime currentDate = DateTime.UtcNow;
List<ProjectProgressionVM>? projectProgressionVMs = new List<ProjectProgressionVM>();
if (date != null && DateTime.TryParse(date, out currentDate) == false)
{
_logger.LogError($"user send invalid date");
@ -333,8 +330,6 @@ namespace Marco.Pms.Services.Controllers
Building building = buildings.FirstOrDefault(b => b.Id == floor.BuildingId) ?? new Building();
string buildingName = building.Name ?? "";
double pending = workItem.PlannedWork - workItem.CompletedWork;
PerformedActivites performedTask = new PerformedActivites
{
ActivityName = activityName,
@ -342,17 +337,19 @@ namespace Marco.Pms.Services.Controllers
FloorName = floorName,
WorkAreaName = areaName,
AssignedToday = task.PlannedTask,
Pending = pending,
CompletedToday = task.CompletedTask,
Comment = task.Description
};
performedActivites.Add(performedTask);
}
var pendingReport = tasks.Where(t => t.ReportedDate == null).ToList().Count;
ActivityReport report = new ActivityReport
{
PerformedActivites = performedActivites,
TotalCompletedWork = totalCompletedTask,
TotalPlannedWork = totalPlannedTask
TotalPlannedWork = totalPlannedTask,
ReportPending = pendingReport,
TodaysAssigned = tasks.Count
};
_logger.LogInfo($"Record of performed activities for project {projectId} for date {currentDate.Date} by employee {LoggedInEmployee.Id}");
return Ok(ApiResponse<object>.SuccessResponse(report, $"Record of performed activities for project {project.Name} for date {currentDate.Date}", 200));

View File

@ -84,8 +84,6 @@ namespace MarcoBMS.Services.Controllers
}
}
[HttpGet]
[Route("list/{projectid?}")]
public async Task<IActionResult> GetEmployeesByProject(Guid? projectid, [FromQuery] bool ShowInactive)
@ -103,6 +101,7 @@ namespace MarcoBMS.Services.Controllers
return Ok(ApiResponse<object>.SuccessResponse(result, "Filter applied.", 200));
}
[HttpGet]
[Route("search/{name}/{projectid?}")]
public async Task<IActionResult> SearchEmployee(string name, Guid? projectid)
@ -264,145 +263,90 @@ namespace MarcoBMS.Services.Controllers
Employee newEmployee = GetNewEmployeeModel(model, tenantId, string.Empty);
_context.Employees.Add(newEmployee);
}
try
{
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
return BadRequest(ex.InnerException?.Message ?? ex.Message);
}
responsemessage = "User created successfully.";
}
return Ok(ApiResponse<object>.SuccessResponse("Success.", responsemessage, 200));
}
//[HttpPost("manage-mobile")]
//public async Task<IActionResult> CreateUserMoblie([FromBody] CreateUserDto model)
//{
// Guid tenantId = _userHelper.GetTenantId();
// if (model == null)
// return BadRequest(ApiResponse<object>.ErrorResponse("Invalid data", "Invaild Data", 400));
// if (model.FirstName == null && model.PhoneNumber == null)
// return BadRequest(ApiResponse<object>.ErrorResponse("Invalid data", "Invaild Data", 400));
[HttpPost("manage-mobile")]
public async Task<IActionResult> CreateUserMoblie([FromBody] MobileUserManageDto model)
{
Guid tenantId = _userHelper.GetTenantId();
if (model == null)
{
_logger.LogWarning("User submitted empty or null employee information during employee creation or update in tenant {TenantId}", tenantId);
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid data", "Invaild Data", 400));
}
// string responsemessage = "";
if (string.IsNullOrWhiteSpace(model.FirstName) || string.IsNullOrWhiteSpace(model.PhoneNumber))
{
_logger.LogWarning("User submitted empty or null first name or phone number during employee creation or update in tenant {TenantId}", tenantId);
return BadRequest(ApiResponse<object>.ErrorResponse("First name and phone number are required fields.", "First name and phone number are required fields.", 400));
}
// if (model.Email != null)
// {
// // Check if user already exists by email
// IdentityUser? existingUser = await _userHelper.GetRegisteredUser(model.Email);
// var existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == model.Id && e.IsActive == true);
// var demo = existingUser != new IdentityUser();
// if (existingUser != null)
// {
// /* Identity user Exists - Create/update employee Employee */
if (model.Id == null)
{
byte[]? imageBytes = null;
if (!string.IsNullOrWhiteSpace(model.ProfileImage))
{
try
{
imageBytes = Convert.FromBase64String(model.ProfileImage);
}
catch (FormatException)
{
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid image format.", "Invalid image format", 400));
}
}
Employee employee = model.ToEmployeeFromMobileUserManageDto(tenantId, imageBytes);
_context.Employees.Add(employee);
await _context.SaveChangesAsync();
// // Update Employee record
// existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.Email == model.Email && e.Id == model.Id && e.IsActive == true);
// if (existingEmployee != null)
// {
// existingEmployee = GetUpdateEmployeeModel(model, existingEmployee, existingUser);
EmployeeVM employeeVM = employee.ToEmployeeVMFromEmployee();
// _context.Employees.Update(existingEmployee);
// await _context.SaveChangesAsync();
// responsemessage = "User updated successfully.";
// }
// else
// {
// // Create Employee record if missing
// //Employee newEmployee = GetNewEmployeeModel(model, TenantId, existingUser.Id);
// //_context.Employees.Add(newEmployee);
// return Conflict(ApiResponse<object>.ErrorResponse("Email already exist", "Email already exist", 409));
// }
_logger.LogInfo($"Employee {employee.FirstName} {employee.LastName} created in tenant {tenantId}");
return Ok(ApiResponse<object>.SuccessResponse(employeeVM, "Employee created successfully", 200));
}
else
{
Employee? existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == model.Id.Value);
if (existingEmployee == null)
{
_logger.LogError("User tries to update employee {EmployeeId} but not found in database", model.Id);
return NotFound(ApiResponse<object>.ErrorResponse("Employee not found", "Employee not found", 404));
}
byte[]? imageBytes = null;
if (!string.IsNullOrWhiteSpace(model.ProfileImage))
{
try
{
imageBytes = Convert.FromBase64String(model.ProfileImage);
}
catch (FormatException)
{
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid image format.", "Invalid image format", 400));
}
}
imageBytes ??= existingEmployee.Photo;
// }
// else
// {
// var user = new ApplicationUser
// {
// UserName = model.Email,
// Email = model.Email,
// EmailConfirmed = true,
// TenantId = tenantId
existingEmployee.FirstName = model.FirstName;
existingEmployee.LastName = model.LastName;
existingEmployee.Gender = model.Gender;
existingEmployee.PhoneNumber = model.PhoneNumber;
existingEmployee.JobRoleId = model.JobRoleId;
existingEmployee.Photo = imageBytes;
// };
await _context.SaveChangesAsync();
// // Create Identity User
// var result = await _userManager.CreateAsync(user, "User@123");
// if (!result.Succeeded)
// return Ok(ApiResponse<object>.ErrorResponse("Failed to create user", result.Errors, 400));
EmployeeVM employeeVM = existingEmployee.ToEmployeeVMFromEmployee();
// if (existingEmployee == null)
// {
// Employee newEmployee = GetNewEmployeeModel(model, tenantId, user.Id);
// _context.Employees.Add(newEmployee);
// await _context.SaveChangesAsync();
// /* SEND USER REGISTRATION MAIL*/
// var token = await _userManager.GeneratePasswordResetTokenAsync(user);
// var resetLink = $"{_configuration["AppSettings:WebFrontendUrl"]}/reset-password?token={WebUtility.UrlEncode(token)}";
// if (newEmployee.FirstName != null)
// {
// await _emailSender.SendResetPasswordEmailOnRegister(user.Email, newEmployee.FirstName, resetLink);
// }
// }
// else
// {
// existingEmployee.Email = model.Email;
// existingEmployee = GetUpdateEmployeeModel(model, existingEmployee, existingUser);
// _context.Employees.Update(existingEmployee);
// await _context.SaveChangesAsync();
// /* SEND USER REGISTRATION MAIL*/
// var token = await _userManager.GeneratePasswordResetTokenAsync(user);
// var resetLink = $"{_configuration["AppSettings:WebFrontendUrl"]}/reset-password?token={WebUtility.UrlEncode(token)}";
// if (existingEmployee.FirstName != null)
// {
// await _emailSender.SendResetPasswordEmailOnRegister(user.Email, existingEmployee.FirstName, resetLink);
// }
// }
// responsemessage = "User created successfully. Password reset link is sent to registered email";
// }
// }
// else
// {
// var existingEmployee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == model.Id && e.IsActive == true);
// if (existingEmployee != null)
// {
// existingEmployee = GetUpdateEmployeeModel(model, existingEmployee);
// _context.Employees.Update(existingEmployee);
// responsemessage = "User updated successfully.";
// }
// else
// {
// // Create Employee record if missing
// Employee newEmployee = GetNewEmployeeModel(model, tenantId, string.Empty);
// _context.Employees.Add(newEmployee);
// }
// try
// {
// await _context.SaveChangesAsync();
// }
// catch (Exception ex)
// {
// return BadRequest(ex.InnerException?.Message ?? ex.Message);
// }
// responsemessage = "User created successfully.";
// }
// return Ok(ApiResponse<object>.SuccessResponse("Success.", responsemessage, 200));
//}
_logger.LogInfo($"Employee {existingEmployee.FirstName} {existingEmployee.LastName} updated in tenant {tenantId}");
return Ok(ApiResponse<object>.SuccessResponse(employeeVM, "Employee updated successfully", 200));
}
}
[HttpDelete("{id}")]
public async Task<IActionResult> SuspendEmployee(Guid id)
@ -484,7 +428,6 @@ namespace MarcoBMS.Services.Controllers
}
return Ok(ApiResponse<object>.SuccessResponse(new { }, "Employee Suspended successfully", 200));
}
private static Employee GetNewEmployeeModel(CreateUserDto model, Guid TenantId, string ApplicationUserId)
{
var newEmployee = new Employee
@ -511,7 +454,6 @@ namespace MarcoBMS.Services.Controllers
};
return newEmployee;
}
private static Employee GetUpdateEmployeeModel(CreateUserDto model, Employee existingEmployee, IdentityUser? existingIdentityUser = null)
{
if (existingEmployee.ApplicationUserId == null && existingIdentityUser != null)
@ -536,7 +478,6 @@ namespace MarcoBMS.Services.Controllers
return existingEmployee;
}
private static async Task<FileDetails> GetFileDetails(IFormFile file)
{
FileDetails info = new FileDetails();

View File

@ -1,8 +1,10 @@
using System.Globalization;
using System.Data;
using System.Globalization;
using Marco.Pms.DataAccess.Data;
using Marco.Pms.Model.Dtos.Attendance;
using Marco.Pms.Model.Projects;
using Marco.Pms.Model.Roles;
using Marco.Pms.Model.Dtos.Mail;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Mail;
using Marco.Pms.Model.Utilities;
using Marco.Pms.Model.ViewModels.Report;
using MarcoBMS.Services.Helpers;
@ -21,198 +23,308 @@ namespace Marco.Pms.Services.Controllers
{
private readonly ApplicationDbContext _context;
private readonly IEmailSender _emailSender;
private readonly IConfiguration _configuration;
private readonly ILoggingService _logger;
private readonly UserHelper _userHelper;
public ReportController(ApplicationDbContext context, IEmailSender emailSender, IConfiguration configuration, ILoggingService logger, UserHelper userHelper)
private readonly IWebHostEnvironment _env;
public ReportController(ApplicationDbContext context, IEmailSender emailSender, ILoggingService logger, UserHelper userHelper, IWebHostEnvironment env)
{
_context = context;
_emailSender = emailSender;
_configuration = configuration;
_logger = logger;
_userHelper = userHelper;
_env = env;
}
[HttpGet("project-statistics/{id}")]
public async Task<IActionResult> GetProjectStatistics(Guid id, [FromQuery] string? date)
[HttpPost("set-mail")]
public async Task<IActionResult> AddMailDetails([FromBody] MailDetailsDto mailDetailsDto)
{
DateTime reportDate = DateTime.UtcNow;
if (date != null && DateTime.TryParse(date, out reportDate) == false)
Guid tenantId = _userHelper.GetTenantId();
MailDetails mailDetails = new MailDetails
{
_logger.LogError("User sent Invalid from Date while featching project report");
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Date", "Invalid Date", 400));
ProjectId = mailDetailsDto.ProjectId,
Recipient = mailDetailsDto.Recipient,
Schedule = mailDetailsDto.Schedule,
MailListId = mailDetailsDto.MailListId,
Subject = mailDetailsDto.Subject,
TenantId = tenantId
};
_context.MailDetails.Add(mailDetails);
await _context.SaveChangesAsync();
return Ok("Success");
}
if (id == Guid.Empty)
[HttpPost("mail-template")]
public async Task<IActionResult> AddMailTemplate([FromBody] MailTemeplateDto mailTemeplateDto)
{
_logger.LogError("Provided empty project ID while fetching project report");
return BadRequest(ApiResponse<object>.ErrorResponse("Provided empty ProjectID", "Provided empty ProjectID", 400));
Guid tenantId = _userHelper.GetTenantId();
MailingList mailingList = new MailingList
{
Title = mailTemeplateDto.Title,
Body = mailTemeplateDto.Body,
Keywords = mailTemeplateDto.Keywords,
TenantId = tenantId
};
_context.MailingList.Add(mailingList);
await _context.SaveChangesAsync();
return Ok("Success");
}
Project? project = await _context.Projects.FirstOrDefaultAsync(p => p.Id == id);
[HttpGet("project-statistics")]
public async Task<IActionResult> SendProjectReport()
{
Guid tenantId = _userHelper.GetTenantId();
// Use AsNoTracking() for read-only queries to improve performance
List<MailDetails> mailDetails = await _context.MailDetails
.AsNoTracking()
.Include(m => m.MailBody)
.Where(m => m.TenantId == tenantId)
.ToListAsync();
int successCount = 0;
int notFoundCount = 0;
int invalidIdCount = 0;
var groupedMails = mailDetails
.GroupBy(m => new { m.ProjectId, m.MailListId })
.Select(g => new
{
ProjectId = g.Key.ProjectId,
MailListId = g.Key.MailListId,
Recipients = g.Select(m => m.Recipient).Distinct().ToList(),
MailBody = g.FirstOrDefault()?.MailBody?.Body ?? ""
})
.ToList();
var semaphore = new SemaphoreSlim(1);
// Using Task.WhenAll to send reports concurrently for better performance
var sendTasks = groupedMails.Select(async mailDetail =>
{
await semaphore.WaitAsync();
try
{
var response = await GetProjectStatistics(mailDetail.ProjectId, mailDetail.Recipients, mailDetail.MailBody, tenantId);
if (response.StatusCode == 200)
Interlocked.Increment(ref successCount);
else if (response.StatusCode == 404)
Interlocked.Increment(ref notFoundCount);
else if (response.StatusCode == 400)
Interlocked.Increment(ref invalidIdCount);
}
finally
{
semaphore.Release();
}
}).ToList();
await Task.WhenAll(sendTasks);
//var response = await GetProjectStatistics(Guid.Parse("2618eb89-2823-11f0-9d9e-bc241163f504"), "ashutosh.nehete@marcoaiot.com", tenantId);
_logger.LogInfo(
"Emails of project reports sent for tenant {TenantId}. Successfully sent: {SuccessCount}, Projects not found: {NotFoundCount}, Invalid IDs: {InvalidIdsCount}",
tenantId, successCount, notFoundCount, invalidIdCount);
return Ok(ApiResponse<object>.SuccessResponse(
new { },
$"Reports sent successfully: {successCount}. Projects not found: {notFoundCount}. Invalid IDs: {invalidIdCount}.",
200));
}
/// <summary>
/// Retrieves project statistics for a given project ID and sends an email report.
/// </summary>
/// <param name="projectId">The ID of the project.</param>
/// <param name="recipientEmail">The email address of the recipient.</param>
/// <returns>An ApiResponse indicating the success or failure of retrieving statistics and sending the email.</returns>
private async Task<ApiResponse<object>> GetProjectStatistics(Guid projectId, List<string> recipientEmails, string body, Guid tenantId)
{
DateTime reportDate = DateTime.UtcNow.AddDays(-1).Date;
if (projectId == Guid.Empty)
{
_logger.LogError("Provided empty project ID while fetching project report.");
return ApiResponse<object>.ErrorResponse("Provided empty Project ID.", "Provided empty Project ID.", 400);
}
var project = await _context.Projects
.AsNoTracking()
.FirstOrDefaultAsync(p => p.Id == projectId);
if (project == null)
{
_logger.LogWarning("User attempted to fetch project progress of project ID {ProjectId} but not found in database", id);
return NotFound(ApiResponse<object>.ErrorResponse("Project not found", "Project not found", 404));
_logger.LogWarning("User attempted to fetch project progress for project ID {ProjectId} but not found.", projectId);
return ApiResponse<object>.ErrorResponse("Project not found.", "Project not found.", 404);
}
ProjectStatisticReport statisticReport = new ProjectStatisticReport
var statisticReport = new ProjectStatisticReport
{
Date = reportDate,
ProjectName = project.Name ?? "",
TimeStamp = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss", CultureInfo.InvariantCulture)
};
var projectAllocations = await _context.ProjectAllocations.Include(p => p.Employee).Where(p => p.ProjectId == project.Id && p.IsActive).ToListAsync();
var assignedEmployeeIds = projectAllocations.Select(p => p.EmployeeId).ToList();
var attendances = await _context.Attendes.AsNoTracking().Where(a => a.ProjectID == project.Id && a.InTime != null && a.InTime.Value.Date == reportDate.Date).ToListAsync();
var checkedInEmployeeIds = attendances.Select(p => p.EmployeeID).Distinct().ToList();
var checkedOutPendingEmployeeIds = attendances.Where(a => a.ProjectID == project.Id && a.InTime != null && a.InTime.Value.Date == reportDate.Date && a.OutTime == null).Select(p => p.EmployeeID).Distinct().ToList();
var regularizationEmployeeIds = attendances.Where(a => a.ProjectID == project.Id && a.InTime != null && a.InTime.Value.Date == reportDate.Date && a.Activity == ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE).Select(p => p.EmployeeID).Distinct().ToList();
// Preload relevant data
var projectAllocations = await _context.ProjectAllocations
.Include(p => p.Employee)
.Where(p => p.ProjectId == project.Id && p.IsActive)
.ToListAsync();
var assignedEmployeeIds = projectAllocations.Select(p => p.EmployeeId).ToHashSet();
var attendances = await _context.Attendes
.AsNoTracking()
.Where(a => a.ProjectID == project.Id && a.InTime != null && a.InTime.Value.Date == reportDate)
.ToListAsync();
var checkedInEmployeeIds = attendances.Select(a => a.EmployeeID).Distinct().ToHashSet();
var checkoutPendingIds = attendances.Where(a => a.OutTime == null).Select(a => a.EmployeeID).Distinct().ToHashSet();
var regularizationIds = attendances
.Where(a => a.Activity == ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE)
.Select(a => a.EmployeeID).Distinct().ToHashSet();
// Preload buildings, floors, areas
var buildings = await _context.Buildings.Where(b => b.ProjectId == project.Id).ToListAsync();
var buildingIds = buildings.Select(b => b.Id).Distinct().ToList();
var buildingIds = buildings.Select(b => b.Id).ToList();
var floors = await _context.Floor.Where(f => buildingIds.Contains(f.BuildingId)).ToListAsync();
var floorIds = floors.Select(f => f.Id).Distinct().ToList();
var floorIds = floors.Select(f => f.Id).ToList();
var areas = await _context.WorkAreas.Where(a => floorIds.Contains(a.FloorId)).ToListAsync();
var areaIds = areas.Select(a => a.Id).Distinct().ToList();
var areaIds = areas.Select(a => a.Id).ToList();
var workItems = await _context.WorkItems.Include(i => i.ActivityMaster).Where(i => areaIds.Contains(i.WorkAreaId)).ToListAsync();
var itemIds = workItems.Select(i => i.Id).Distinct().ToList();
var workItems = await _context.WorkItems
.Include(w => w.ActivityMaster)
.Where(w => areaIds.Contains(w.WorkAreaId))
.ToListAsync();
var tasks = await _context.TaskAllocations.Where(t => itemIds.Contains(t.WorkItemId)).ToListAsync();
var taskIds = tasks.Select(t => t.Id).Distinct().ToList();
var itemIds = workItems.Select(i => i.Id).ToList();
var taskMembers = await _context.TaskMembers.Include(m => m.Employee).Where(m => taskIds.Contains(m.TaskAllocationId)).ToListAsync();
var tasks = await _context.TaskAllocations
.Where(t => itemIds.Contains(t.WorkItemId))
.ToListAsync();
double totalPlannedWork = 0;
double totalCompletedWork = 0;
foreach (var items in workItems)
{
totalPlannedWork += items.PlannedWork;
totalCompletedWork += items.CompletedWork;
}
var taskIds = tasks.Select(t => t.Id).ToList();
var todayAssigned = tasks.Where(t => t.AssignmentDate.Date == reportDate.Date).ToList();
var taskMembers = await _context.TaskMembers
.Include(m => m.Employee)
.Where(m => taskIds.Contains(m.TaskAllocationId))
.ToListAsync();
// Aggregate data
double totalPlannedWork = workItems.Sum(w => w.PlannedWork);
double totalCompletedWork = workItems.Sum(w => w.CompletedWork);
var todayAssignedTasks = tasks.Where(t => t.AssignmentDate.Date == reportDate).ToList();
var reportPending = tasks.Where(t => t.ReportedDate == null).ToList();
double totalPlannedTask = 0;
double totalCompletedTask = 0;
foreach (var items in todayAssigned)
{
totalPlannedTask += items.PlannedTask;
totalCompletedTask += items.CompletedTask;
}
double totalPlannedTask = todayAssignedTasks.Sum(t => t.PlannedTask);
double totalCompletedTask = todayAssignedTasks.Sum(t => t.CompletedTask);
var jobRoles = await _context.JobRoles.Where(r => r.TenantId == project.TenantId).ToListAsync();
List<TeamOnSite> teamOnSite = new List<TeamOnSite>();
foreach (var role in jobRoles)
{
int numberOfEmployees = 0;
var roleassigned = projectAllocations.Where(p => p.JobRoleId == role.Id && checkedInEmployeeIds.Contains(p.EmployeeId)).ToList();
if (roleassigned.Count > 0)
{
numberOfEmployees = roleassigned.Count;
}
TeamOnSite team = new TeamOnSite
{
RoleName = role.Name,
NumberofEmployees = numberOfEmployees,
};
teamOnSite.Add(team);
}
List<PerformedTask> performedTasks = new List<PerformedTask>();
var todaysTask = tasks.Where(t => t.AssignmentDate.Date == reportDate.Date).ToList();
foreach (var task in todaysTask)
{
WorkItem workItem = workItems.FirstOrDefault(i => i.Id == task.WorkItemId) ?? new WorkItem();
string activityName = (workItem.ActivityMaster != null ? workItem.ActivityMaster.ActivityName : "") ?? "";
var jobRoles = await _context.JobRoles
.Where(j => j.TenantId == project.TenantId)
.ToListAsync();
WorkArea workArea = areas.FirstOrDefault(a => a.Id == workItem.WorkAreaId) ?? new WorkArea();
string areaName = workArea.AreaName ?? "";
// Team on site
var teamOnSite = jobRoles
.Select(role =>
{
var count = projectAllocations.Count(p => p.JobRoleId == role.Id && checkedInEmployeeIds.Contains(p.EmployeeId));
return new TeamOnSite { RoleName = role.Name, NumberofEmployees = count };
})
.OrderByDescending(t => t.NumberofEmployees)
.ToList();
Floor floor = floors.FirstOrDefault(f => f.Id == workArea.FloorId) ?? new Floor();
string floorName = floor.FloorName ?? "";
// Task details
var performedTasks = todayAssignedTasks.Select(task =>
{
var workItem = workItems.FirstOrDefault(w => w.Id == task.WorkItemId);
var area = areas.FirstOrDefault(a => a.Id == workItem?.WorkAreaId);
var floor = floors.FirstOrDefault(f => f.Id == area?.FloorId);
var building = buildings.FirstOrDefault(b => b.Id == floor?.BuildingId);
Building building = buildings.FirstOrDefault(b => b.Id == floor.BuildingId) ?? new Building();
string buildingName = building.Name ?? "";
string activityName = workItem?.ActivityMaster?.ActivityName ?? "";
string location = $"{building?.Name} > {floor?.FloorName}</span><br/><span style=\"color: gray; font-size: small; padding-left: 10px;\"> {floor?.FloorName}-{area?.AreaName}";
double pending = (workItem?.PlannedWork ?? 0) - (workItem?.CompletedWork ?? 0);
string location = $"{buildingName} > {floorName} </span><br/><span style=\"color: gray; font-size: small; padding-left: 10px;\"> {floorName}-{areaName}";
double pending = workItem.PlannedWork - workItem.CompletedWork;
PerformedTask performedTask = new PerformedTask
var taskTeam = taskMembers
.Where(m => m.TaskAllocationId == task.Id)
.Select(m =>
{
string name = $"{m.Employee?.FirstName ?? ""} {m.Employee?.LastName ?? ""}";
var role = jobRoles.FirstOrDefault(r => r.Id == m.Employee?.JobRoleId);
return new TaskTeam { Name = name, RoleName = role?.Name ?? "" };
})
.ToList();
return new PerformedTask
{
Activity = activityName,
Location = location,
AssignedToday = task.PlannedTask,
Pending = pending,
CompletedToday = task.CompletedTask,
Comment = task.Description
Pending = pending,
Comment = task.Description,
Team = taskTeam
};
}).ToList();
var taskTeams = taskMembers.Where(m => m.TaskAllocationId == task.Id).ToList();
List<TaskTeam> Team = new List<TaskTeam>();
foreach (var team in taskTeams)
// Attendance details
var performedAttendance = attendances.Select(att =>
{
string firstName = (team.Employee != null ? team.Employee.FirstName : "") ?? "";
string lastName = (team.Employee != null ? team.Employee.LastName : "") ?? "";
string name = $"{firstName} {lastName}";
var alloc = projectAllocations.FirstOrDefault(p => p.EmployeeId == att.EmployeeID);
var role = jobRoles.FirstOrDefault(r => r.Id == alloc?.JobRoleId);
string name = $"{alloc?.Employee?.FirstName ?? ""} {alloc?.Employee?.LastName ?? ""}";
JobRole role = jobRoles.FirstOrDefault(r => r.Id == (team.Employee != null ? team.Employee.JobRoleId : Guid.Empty)) ?? new JobRole();
string roleName = role.Name ?? "";
TaskTeam taskTeam = new TaskTeam
return new PerformedAttendance
{
Name = name,
RoleName = roleName,
RoleName = role?.Name ?? "",
InTime = att.InTime ?? DateTime.UtcNow,
OutTime = att.OutTime,
Comment = att.Comment
};
Team.Add(taskTeam);
}
performedTask.Team = Team;
performedTasks.Add(performedTask);
}
List<PerformedAttendance> performedAttendances = new List<PerformedAttendance>();
foreach (var attendance in attendances)
{
ProjectAllocation projectAllocation = projectAllocations.FirstOrDefault(p => p.EmployeeId == attendance.EmployeeID) ?? new ProjectAllocation();
JobRole role = jobRoles.FirstOrDefault(r => r.Id == projectAllocation.JobRoleId) ?? new JobRole();
string firstName = (projectAllocation.Employee != null ? projectAllocation.Employee.FirstName : "") ?? "";
string lastName = (projectAllocation.Employee != null ? projectAllocation.Employee.LastName : "") ?? "";
string name = $"{firstName} {lastName}";
PerformedAttendance performedAttendance = new PerformedAttendance
{
Name = name,
RoleName = role.Name ?? "",
InTime = attendance.InTime ?? DateTime.UtcNow,
OutTime = attendance.OutTime,
Comment = attendance.Comment
};
performedAttendances.Add(performedAttendance);
}
}).ToList();
// Fill report
statisticReport.TodaysAttendances = checkedInEmployeeIds.Count;
statisticReport.TotalEmployees = assignedEmployeeIds.Count;
statisticReport.RegularizationPending = regularizationEmployeeIds.Count;
statisticReport.CheckoutPending = checkedOutPendingEmployeeIds.Count;
statisticReport.RegularizationPending = regularizationIds.Count;
statisticReport.CheckoutPending = checkoutPendingIds.Count;
statisticReport.TotalPlannedWork = totalPlannedWork;
statisticReport.TotalCompletedWork = totalCompletedWork;
statisticReport.TotalPlannedTask = totalPlannedTask;
statisticReport.TotalCompletedTask = totalCompletedTask;
statisticReport.CompletionStatus = totalCompletedWork / totalPlannedWork;
statisticReport.TodaysAssignTasks = todayAssigned.Count;
statisticReport.CompletionStatus = totalPlannedWork > 0 ? totalCompletedWork / totalPlannedWork : 0;
statisticReport.TodaysAssignTasks = todayAssignedTasks.Count;
statisticReport.ReportPending = reportPending.Count;
statisticReport.TeamOnSite = teamOnSite.OrderByDescending(c => c.NumberofEmployees).ToList();
statisticReport.TeamOnSite = teamOnSite;
statisticReport.PerformedTasks = performedTasks;
statisticReport.PerformedAttendance = performedAttendances;
statisticReport.PerformedAttendance = performedAttendance;
string emails = _configuration["MailingList:ProjectStatisticsReceivers"] ?? "";
List<string> result = emails
.Split(';', StringSplitOptions.RemoveEmptyEntries)
.Select(item => item.Trim())
.ToList();
await _emailSender.SendProjectStatisticsEmail(result, statisticReport);
return Ok(ApiResponse<object>.SuccessResponse(new { }, "Email sent successfully", 200));
// Send Email
var emailBody = await _emailSender.SendProjectStatisticsEmail(recipientEmails, body, statisticReport);
var employee = await _context.Employees.FirstOrDefaultAsync(e => e.Email != null && recipientEmails.Contains(e.Email)) ?? new Employee();
List<MailLog> mailLogs = new List<MailLog>();
foreach (var recipientEmail in recipientEmails)
{
mailLogs.Add(
new MailLog
{
ProjectId = projectId,
EmailId = recipientEmail,
Body = emailBody,
EmployeeId = employee.Id,
TimeStamp = DateTime.UtcNow,
TenantId = tenantId
});
}
_context.MailLogs.AddRange(mailLogs);
await _context.SaveChangesAsync();
return ApiResponse<object>.SuccessResponse(statisticReport, "Email sent successfully", 200);
}
}
}

View File

@ -442,7 +442,7 @@
Regularization Pending
</div>
<div style="font-size: 25px; color: #bc3803; margin: 20px 20px 0px !important; font-weight: bold;">
{{REGULRIZATION_PENDING}}
{{REGULARIZATION_PENDING}}
</div>
</div>
</td>
@ -453,7 +453,7 @@
Checkout Pending
</div>
<div style="font-size: 25px; color: #bc3803; margin: 20px 20px 0px !important; font-weight: bold;">
{{CHECKOUT_PRNDING}}
{{CHECKOUT_PENDING}}
</div>
</div>
</td>

View File

@ -112,90 +112,127 @@ namespace MarcoBMS.Services.Service
}
public async Task SendProjectStatisticsEmail(List<string> toEmails, ProjectStatisticReport report)
public async Task<string> SendProjectStatisticsEmail(List<string> toEmails, string emailBody, ProjectStatisticReport report)
{
//List<string> toEmails = [
// "ashutosh.nehete@marcoaiot.com"
//];
var date = report.Date.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture);
var replacements = new Dictionary<string, string>
{
{"DATE",date },
{"PROJECT_NAME",report.ProjectName },
{"TIMESTAMP",report.TimeStamp },
{"DATE", date},
{"PROJECT_NAME", report.ProjectName},
{"TIMESTAMP", report.TimeStamp},
{"TODAYS_ATTENDANCES", report.TodaysAttendances.ToString("N0")},
{"TOTAL_EMPLOYEES",report.TotalEmployees.ToString("N0") },
{"TODAYS_PLANNED",report.TotalPlannedTask.ToString("N0") },
{"TODAYS_COMPLETED",report.TotalCompletedTask.ToString("N0") },
{"REGULRIZATION_PENDING", report.RegularizationPending.ToString("N0") },
{"CHECKOUT_PRNDING",report.CheckoutPending.ToString("N0") },
{"TOTAL_PLANNED",report.TotalPlannedWork.ToString("N0") },
{"TOTAL_COMPLETED",report.TotalCompletedWork.ToString() },
{"PROJECT_STATUS",report.CompletionStatus.ToString("P") },
{"TODAYS_ASSIGNED",report.TodaysAssignTasks.ToString("N0") },
{"REPORT_PENDING",report.ReportPending.ToString("N0") }
{"TOTAL_EMPLOYEES", report.TotalEmployees.ToString("N0")},
{"TODAYS_PLANNED", report.TotalPlannedTask.ToString("N0")},
{"TODAYS_COMPLETED", report.TotalCompletedTask.ToString("N0")},
{"REGULARIZATION_PENDING", report.RegularizationPending.ToString("N0")},
{"CHECKOUT_PENDING", report.CheckoutPending.ToString("N0")},
{"TOTAL_PLANNED", report.TotalPlannedWork.ToString("N0")},
{"TOTAL_COMPLETED", report.TotalCompletedWork.ToString("N0")},
{"PROJECT_STATUS", report.CompletionStatus.ToString("P")},
{"TODAYS_ASSIGNED", report.TodaysAssignTasks.ToString("N0")},
{"REPORT_PENDING", report.ReportPending.ToString("N0")}
};
string emailBody = await GetEmailTemplate("project-report", replacements);
//string emailBody = await GetEmailTemplate("test-project", replacements);
var teamHtml = new StringBuilder();
teamHtml.Append("<tr style=\"vertical-align:middle\">");
int flag = 0;
foreach (var item in report.TeamOnSite)
foreach (var item in replacements)
{
if (flag == 6)
{
teamHtml.Append("</tr>");
teamHtml.Append("<tr style=\"vertical-align:middle\">");
flag = 0;
}
teamHtml.AppendFormat("<td class=\"team\" style=\"text-align:center\"><div style=\"border: 1px solid #d5d5d5; border-radius: 10px; margin: 10px 10px; padding: 10px;\"><div style=\"font-size: 15px; color: #525b75 \">{0}</div> <div style=\"font-size: 20px; color: #003cc7; margin: 20px !important; font-weight: bold; \">{1}</div></div></td>", item.RoleName, item.NumberofEmployees);
flag += 1;
}
teamHtml.Append("</tr>");
emailBody = emailBody.Replace("{{TEAM_ON_SITE}}", teamHtml.ToString());
var taskHtml = new StringBuilder();
if (report.PerformedTasks.Count > 0)
{
foreach (var task in report.PerformedTasks)
{
taskHtml.AppendFormat("<tr>\r\n<td style=\"text-align:left;\">\r\n<span style=\"padding-left: 10px; text-align: left;\">\r\n {0} \r\n</span><br />\r\n<span style=\"color: gray; font-size: small; padding-left: 10px;\"> {1} </span>\r\n</td>\r\n<td style=\"text-align:center\">\r\n {2} / {3} \r\n</td>\r\n<td style=\"text-align:center\">\r\n {4} \r\n</td>\r\n<td style=\"text-align:center\"> {5} </td>\r\n <td style=\"padding-left: 10px; text-align: left;\">\r\n",
task.Activity, task.Location, task.AssignedToday, task.Pending, task.CompletedToday, report.Date.ToString("dd-MMM-yyy"));
foreach (var member in task.Team)
{
taskHtml.AppendFormat(" {0} &nbsp; \r\n<span style=\"color: gray; font-size: small; padding-left: 10px;\">({1})</span>\r\n<br />",
member.Name, member.RoleName);
}
taskHtml.AppendFormat("</td>\r\n<td style=\"padding-left: 10px; max-width: 150px; text-align: left;\"> {0} </td>\r\n</tr>", task.Comment);
}
}
else
{
taskHtml.Append("<tr><td style=\"padding: 10px 0px 5px;\" colspan=\"6\"><span style=\"line-height: 25.2px; color: #666666;margin:10px\">No Activities (Tasks) Performed Today</span></td></tr>");
emailBody = emailBody.Replace($"{{{{{item.Key}}}}}", item.Value);
}
emailBody = emailBody.Replace("{{PERFORMED_TASK}}", taskHtml.ToString());
emailBody = emailBody.Replace("{{TEAM_ON_SITE}}", BuildTeamOnSiteHtml(report.TeamOnSite));
emailBody = emailBody.Replace("{{PERFORMED_TASK}}", BuildPerformedTaskHtml(report.PerformedTasks, report.Date));
emailBody = emailBody.Replace("{{PERFORMED_ATTENDANCE}}", BuildPerformedAttendanceHtml(report.PerformedAttendance));
var attendanceHtml = new StringBuilder();
if (report.PerformedAttendance.Count > 0)
{
foreach (var attendance in report.PerformedAttendance)
{
attendanceHtml.AppendFormat("<tr>\r\n<td style=\"text-align:left\">\r\n<span style=\"padding-left:10px;\"> {0} </span>\r\n</td>\r\n<td style=\"text-align:center\"> {1} </td>\r\n<td style=\"text-align:center\"> {2} </td>\r\n<td style=\"text-align:center\"> {3} </td>\r\n<td style=\"padding-left:10px; max-width:150px\"> {4} </td>\r\n</tr>",
attendance.Name, attendance.RoleName, attendance.InTime.ToString("dd-MMM-yyyy h:mm tt", CultureInfo.InvariantCulture), (attendance.OutTime != null ? attendance.OutTime.Value.ToString("dd-MMM-yyyy h:mm tt", CultureInfo.InvariantCulture) : ""), attendance.Comment);
}
}
else
{
attendanceHtml.Append("<tr><td style=\"padding: 10px 0px 5px;\" colspan=\"5\"><span style=\"line-height: 25.2px; color: #666666;margin:10px\">No Attendance Performed Today</span></td></tr>");
}
emailBody = emailBody.Replace("{{PERFORMED_ATTENDANCE}}", attendanceHtml.ToString());
string subject = $"DPR - {date} - {report.ProjectName}";
await SendEmailAsync(toEmails, subject, emailBody);
return emailBody;
}
private string BuildTeamOnSiteHtml(List<TeamOnSite> team)
{
if (team == null || !team.Any()) return "";
var sb = new StringBuilder();
sb.Append("<tr style=\"vertical-align:middle\">");
int count = 0;
foreach (var member in team)
{
if (count == 6)
{
sb.Append("</tr><tr style=\"vertical-align:middle\">");
count = 0;
}
sb.AppendFormat(
"<td class=\"team\" style=\"text-align:center\">" +
"<div style=\"border: 1px solid #d5d5d5; border-radius: 10px; margin: 10px; padding: 10px;\">" +
"<div style=\"font-size: 15px; color: #525b75\">{0}</div>" +
"<div style=\"font-size: 20px; color: #003cc7; margin: 20px !important; font-weight: bold;\">{1}</div>" +
"</div></td>", member.RoleName, member.NumberofEmployees);
count++;
}
sb.Append("</tr>");
return sb.ToString();
}
private string BuildPerformedTaskHtml(List<PerformedTask> tasks, DateTime reportDate)
{
if (tasks == null || !tasks.Any())
{
return "<tr><td style=\"padding: 10px 0px 5px;\" colspan=\"6\">" +
"<span style=\"line-height: 25.2px; color: #666666;margin:10px\">" +
"No Activities (Tasks) Performed Today</span></td></tr>";
}
var sb = new StringBuilder();
foreach (var task in tasks)
{
sb.AppendFormat("<tr>" +
"<td style=\"text-align:left;\"><span style=\"padding-left: 10px;\">{0}</span><br />" +
"<span style=\"color: gray; font-size: small; padding-left: 10px;\">{1}</span></td>" +
"<td style=\"text-align:center\">{2} / {3}</td>" +
"<td style=\"text-align:center\">{4}</td>" +
"<td style=\"text-align:center\">{5}</td>" +
"<td style=\"padding-left: 10px; text-align: left;\">",
task.Activity, task.Location, task.AssignedToday, task.Pending, task.CompletedToday, reportDate.ToString("dd-MMM-yyyy"));
foreach (var member in task.Team)
{
sb.AppendFormat("{0} <span style=\"color: gray; font-size: small; padding-left: 10px;\">({1})</span><br />",
member.Name, member.RoleName);
}
sb.AppendFormat("</td><td style=\"padding-left: 10px; max-width: 150px; text-align: left;\">{0}</td></tr>", task.Comment);
}
return sb.ToString();
}
private string BuildPerformedAttendanceHtml(List<PerformedAttendance> attendances)
{
if (attendances == null || !attendances.Any())
{
return "<tr><td style=\"padding: 10px 0px 5px;\" colspan=\"5\">" +
"<span style=\"line-height: 25.2px; color: #666666;margin:10px\">No Attendance Performed Today</span></td></tr>";
}
var sb = new StringBuilder();
foreach (var a in attendances)
{
sb.AppendFormat("<tr>" +
"<td style=\"text-align:left\"><span style=\"padding-left:10px;\">{0}</span></td>" +
"<td style=\"text-align:center\">{1}</td>" +
"<td style=\"text-align:center\">{2}</td>" +
"<td style=\"text-align:center\">{3}</td>" +
"<td style=\"padding-left:10px; max-width:150px\">{4}</td>" +
"</tr>",
a.Name,
a.RoleName,
a.InTime.ToString("dd-MMM-yyyy h:mm tt", CultureInfo.InvariantCulture),
a.OutTime?.ToString("dd-MMM-yyyy h:mm tt", CultureInfo.InvariantCulture) ?? "",
a.Comment);
}
return sb.ToString();
}
public async Task SendEmailAsync(List<string> toEmails, string subject, string body)

View File

@ -10,6 +10,6 @@ namespace MarcoBMS.Services.Service
Task SendResetPasswordSuccessEmail(string toEmail, string userName);
Task SendRequestDemoEmail(List<string> toEmails, InquiryEmailObject demoEmailObject);
Task SendEmailAsync(List<string> toEmails, string subject, string body);
Task SendProjectStatisticsEmail(List<string> toEmails, ProjectStatisticReport report);
Task<string> SendProjectStatisticsEmail(List<string> toEmails, string emailBody, ProjectStatisticReport report);
}
}

View File

@ -6,7 +6,6 @@
},
"ConnectionStrings": {
//"DefaultConnectionString": "Server=localhost;port=3306;User ID=root;Password=root;Database=MarcoBMS2"
"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMSGuid"
},
"SmtpSettings": {
@ -36,7 +35,7 @@
},
"MailingList": {
"RequestDemoReceivers": "ashutosh.nehete@marcoaiot.com;vikas@marcoaiot.com;umesh@marcoait.com",
"ProjectStatisticsReceivers": "ashutosh.nehete@marcoaiot.com;vikas@marcoaiot.com;umesh@marcoait.com"
//"ProjectStatisticsReceivers": "ashutosh.nehete@marcoaiot.com;vikas@marcoaiot.com;umesh@marcoait.com"
},
"AWS": {
"AccessKey": "AKIARZDBH3VDMSUUY2FX",