Organization_Management #142
@ -17,5 +17,6 @@
|
||||
public required string OrganizationSize { get; set; }
|
||||
public required Guid IndustryId { get; set; }
|
||||
public required string Reference { get; set; }
|
||||
public required List<Guid> ServiceIds { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using Marco.Pms.Model.Employees;
|
||||
using Marco.Pms.Model.Entitlements;
|
||||
using Marco.Pms.Model.Filters;
|
||||
using Marco.Pms.Model.MongoDBModels.Utility;
|
||||
using Marco.Pms.Model.OrganizationModel;
|
||||
using Marco.Pms.Model.Projects;
|
||||
using Marco.Pms.Model.Roles;
|
||||
using Marco.Pms.Model.TenantModels;
|
||||
@ -473,6 +474,27 @@ namespace Marco.Pms.Services.Controllers
|
||||
await using var transaction = await _context.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
// Get last SPRID and increment for new organization
|
||||
var lastOrganization = await _context.Organizations.OrderByDescending(sp => sp.SPRID).FirstOrDefaultAsync();
|
||||
double lastSPRID = lastOrganization?.SPRID ?? 5400;
|
||||
|
||||
// Map DTO to entity and set defaults
|
||||
Organization organization = new Organization
|
||||
{
|
||||
Name = model.OrganizationName,
|
||||
Email = model.Email,
|
||||
ContactPerson = $"{model.FirstName} {model.LastName}",
|
||||
Address = model.BillingAddress,
|
||||
ContactNumber = model.ContactNumber,
|
||||
SPRID = lastSPRID + 1,
|
||||
logoImage = model.logoImage,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
CreatedById = loggedInEmployee.Id,
|
||||
IsActive = true
|
||||
};
|
||||
|
||||
_context.Organizations.Add(organization);
|
||||
|
||||
// Create the primary Tenant entity
|
||||
|
||||
var tenant = _mapper.Map<Tenant>(model);
|
||||
@ -480,6 +502,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
tenant.TenantStatusId = tenantActiveStatus;
|
||||
tenant.CreatedById = loggedInEmployee.Id;
|
||||
tenant.IsSuperTenant = false;
|
||||
tenant.OrganizationId = organization.Id;
|
||||
|
||||
_context.Tenants.Add(tenant);
|
||||
|
||||
@ -526,7 +549,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
ApplicationUserId = applicationUser.Id,
|
||||
JobRole = adminJobRole, // Link to the newly created role
|
||||
CurrentAddress = model.BillingAddress,
|
||||
TenantId = tenant.Id
|
||||
OrganizationId = organization.Id
|
||||
};
|
||||
_context.Employees.Add(employeeUser);
|
||||
|
||||
@ -559,6 +582,21 @@ namespace Marco.Pms.Services.Controllers
|
||||
{
|
||||
ApplicationRoleId = applicationRole.Id,
|
||||
FeaturePermissionId = PermissionsMaster.ViewMasters
|
||||
},
|
||||
new RolePermissionMappings
|
||||
{
|
||||
ApplicationRoleId = applicationRole.Id,
|
||||
FeaturePermissionId = PermissionsMaster.ViewOrganization
|
||||
},
|
||||
new RolePermissionMappings
|
||||
{
|
||||
ApplicationRoleId = applicationRole.Id,
|
||||
FeaturePermissionId = PermissionsMaster.AddOrganization
|
||||
},
|
||||
new RolePermissionMappings
|
||||
{
|
||||
ApplicationRoleId = applicationRole.Id,
|
||||
FeaturePermissionId = PermissionsMaster.EditOrganization
|
||||
}
|
||||
};
|
||||
_context.RolePermissionMappings.AddRange(rolePermissionMappigs);
|
||||
@ -579,6 +617,8 @@ namespace Marco.Pms.Services.Controllers
|
||||
ProjectAddress = model.BillingAddress,
|
||||
StartDate = model.OnBoardingDate,
|
||||
EndDate = DateTime.MaxValue,
|
||||
PromoterId = organization.Id,
|
||||
PMCId = organization.Id,
|
||||
ContactPerson = tenant.ContactName,
|
||||
TenantId = tenant.Id
|
||||
};
|
||||
@ -595,6 +635,15 @@ namespace Marco.Pms.Services.Controllers
|
||||
};
|
||||
_context.ProjectAllocations.Add(projectAllocation);
|
||||
|
||||
// Map organization services
|
||||
var serviceOrgMappings = model.ServiceIds.Select(s => new OrgServiceMapping
|
||||
{
|
||||
ServiceId = s,
|
||||
OrganizationId = organization.Id
|
||||
}).ToList();
|
||||
|
||||
_context.OrgServiceMappings.AddRange(serviceOrgMappings);
|
||||
|
||||
// All entities are now added to the context. Save them all in a single database operation.
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user