Created a new API to update tenant infromation
This commit is contained in:
parent
dca6414a59
commit
6ee508645a
15
Marco.Pms.Model/Dtos/Tenant/UpdateTenantDto.cs
Normal file
15
Marco.Pms.Model/Dtos/Tenant/UpdateTenantDto.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace Marco.Pms.Model.Dtos.Tenant
|
||||
{
|
||||
public class UpdateTenantDto
|
||||
{
|
||||
public string OrganizatioinName { get; set; }
|
||||
public string About { get; set; }
|
||||
public string Website { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ContactNumber { get; set; }
|
||||
|
||||
//public string? OragnizationSize { get; set; }
|
||||
//public int IndustryId { get; set; }
|
||||
public DateTime OnBoardingDate { get; set; }
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityUser> _userManager;
|
||||
private readonly ILoggingService _logger;
|
||||
public TenantController(ApplicationDbContext context,UserManager<IdentityUser> userManager, ILoggingService logger)
|
||||
public TenantController(ApplicationDbContext context, UserManager<IdentityUser> userManager, ILoggingService logger)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
@ -55,7 +55,6 @@ namespace Marco.Pms.Services.Controllers
|
||||
Description = settings.JobRoleDescription,
|
||||
TenantId = TenantId
|
||||
};
|
||||
var existingJobRole = await _context.JobRoles.AsNoTracking().FirstOrDefaultAsync(r => r.Name == settings.JobRoleName);
|
||||
|
||||
ApplicationRole role = new ApplicationRole
|
||||
{
|
||||
@ -63,27 +62,10 @@ namespace Marco.Pms.Services.Controllers
|
||||
Description = settings.RoleDescription,
|
||||
TenantId = TenantId
|
||||
};
|
||||
var existingRole = await _context.ApplicationRoles.AsNoTracking().FirstOrDefaultAsync(r => r.Role == settings.RoleName);
|
||||
|
||||
if (existingJobRole == null)
|
||||
{
|
||||
_context.JobRoles.Add(jobRole);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
jobRole = existingJobRole;
|
||||
}
|
||||
|
||||
if (existingRole == null)
|
||||
{
|
||||
_context.ApplicationRoles.Add(role);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
role = existingRole;
|
||||
}
|
||||
|
||||
List<FeaturePermission> permissions = await _context.FeaturePermissions.AsNoTracking().ToListAsync();
|
||||
List<RolePermissionMappings> rolePermissionMappings = new List<RolePermissionMappings>();
|
||||
@ -111,7 +93,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
var result = await _userManager.CreateAsync(user, createTenantDto.Password);
|
||||
if (result.Succeeded)
|
||||
{
|
||||
Employee newEmployee = CreateTenantDtoToEmployee(createTenantDto, TenantId, user.Id,jobRole.Id);
|
||||
Employee newEmployee = CreateTenantDtoToEmployee(createTenantDto, TenantId, user.Id, jobRole.Id);
|
||||
_context.Employees.Add(newEmployee);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
@ -132,7 +114,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
// Log error.Description
|
||||
_logger.LogError("{Error}",error.Description);
|
||||
_logger.LogError("{Error}", error.Description);
|
||||
}
|
||||
return BadRequest("Failed to create the root user.");
|
||||
}
|
||||
@ -140,6 +122,31 @@ namespace Marco.Pms.Services.Controllers
|
||||
return BadRequest("Falied to create Tenant");
|
||||
|
||||
}
|
||||
[HttpPost("edit/{tenantId}")]
|
||||
public async Task<IActionResult> SuspendTenant(int tenantId,UpdateTenantDto model)
|
||||
{
|
||||
if (tenantId <= 0)
|
||||
{
|
||||
return BadRequest("Tenant Id is required and must be greater than zero.");
|
||||
}
|
||||
var tenant = await _context.Tenants.FirstOrDefaultAsync(t => t.Id == tenantId);
|
||||
//var user = await _context.ApplicationUsers.FirstOrDefaultAsync(u => u.TenantId == tenantId && u.IsRootUser == true);
|
||||
//var employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == tenantId && e.ApplicationUserId == user.Id);
|
||||
if (tenant == null)
|
||||
{
|
||||
return NotFound("Tenant Not Found");
|
||||
}
|
||||
tenant.Name = model.OrganizatioinName;
|
||||
tenant.DomainName = model.Website;
|
||||
tenant.ContactName = model.Name;
|
||||
tenant.Description = model.About;
|
||||
tenant.ContactNumber = model.ContactNumber;
|
||||
tenant.OnBoardingDate = model.OnBoardingDate;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
TenantVM tenantVM = tenant.ToTenantVMFromTenant();
|
||||
return Ok(ApiResponse<object>.SuccessResponse(tenantVM, "Tenant Profile.", 200));
|
||||
}
|
||||
private static Employee CreateTenantDtoToEmployee(CreateTenantDto model, int TenantId, string? ApplicationUserId,int jobRoleId)
|
||||
{
|
||||
return new Employee
|
||||
|
Loading…
x
Reference in New Issue
Block a user