Created a new API to get Tenant Profile

This commit is contained in:
unknown 2025-03-29 15:27:26 +05:30 committed by Vikas Nale
parent 1b0f0b831d
commit 01e88c7ee0
5 changed files with 59 additions and 28 deletions

View File

@ -1,5 +1,6 @@
using Marco.Pms.Model.Dtos.Tenant;
using Marco.Pms.Model.Entitlements;
using Marco.Pms.Model.ViewModels.Tenant;
namespace Marco.Pms.Model.Mapper
{
@ -19,6 +20,18 @@ namespace Marco.Pms.Model.Mapper
OnBoardingDate = createTenant.OnBoardingDate,
};
}
public static TenantVM ToTenantVMFromTenant(this Tenant tenant)
{
return new TenantVM
{
OrganizationName = tenant.Name,
About = tenant.Description,
Website = tenant.DomainName,
Name = tenant.ContactName,
//OragnizationSize = OragnizationSize,
ContactNumber = tenant.ContactNumber,
OnBoardingDate = tenant.OnBoardingDate,
};
}
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Marco.Pms.Model.ViewModels.Tenant
{
public class TenantVM
{
public string OrganizationName { 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; }
}
}

View File

@ -1,18 +1,15 @@
using Marco.Pms.Model.Authentication;
using System.Net;
using Marco.Pms.Model.Authentication;
using Marco.Pms.Model.Dtos;
using Marco.Pms.Model.Dtos.Util;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Entitlements;
using Marco.Pms.Model.Utilities;
using Marco.Pms.Model.ViewModels.Employee;
using MarcoBMS.Services.Helpers;
using MarcoBMS.Services.Service;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Net;
namespace MarcoBMS.Services.Controllers
{

View File

@ -5,6 +5,7 @@ using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Entitlements;
using Marco.Pms.Model.Mapper;
using Marco.Pms.Model.Utilities;
using Marco.Pms.Model.ViewModels.Tenant;
using MarcoBMS.Services.Service;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
@ -55,7 +56,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 +63,11 @@ 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>();
@ -124,7 +108,7 @@ namespace Marco.Pms.Services.Controllers
};
_context.EmployeeRoleMappings.Add(employeeRoleMapping);
await _context.SaveChangesAsync();
return Ok(newEmployee);
return Ok(ApiResponse<object>.SuccessResponse(result.Succeeded, "Tenant created successfully.", 200));
}
else
{
@ -140,6 +124,23 @@ namespace Marco.Pms.Services.Controllers
return BadRequest("Falied to create Tenant");
}
[HttpGet("profile/{tenantId}")]
public async Task<IActionResult> GetTenantProfile(int tenantId)
{
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);
if (tenant == null)
{
return NotFound("Tenant Not Found");
}
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

View File

@ -64,9 +64,8 @@
"ConnectionStrings": {
// "DefaultConnectionString": "Server=103.50.160.45;User ID=marcowvh_admin;Password=Marcoemp@123;Database=marcowvh_empattendanceci",
//"DefaultConnectionString": "Server=localhost;port=3306;User ID=root;Password=Ashutosh;Database=MarcoBMS1"
//"DefaultConnectionString": "Server=localhost;port=3333;User ID=root;Password=root;Database=MarcoBMS1",
"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
"DefaultConnectionString": "Server=localhost;port=3333;User ID=root;Password=root;Database=MarcoBMS1",
//"DefaultConnectionString": "Server=147.93.98.152;User ID=devuser;Password=AppUser@123$;Database=MarcoBMS1"
},
"AppSettings": {
"WebFrontendUrl": "http://localhost:5173",