Compare commits
No commits in common. "cc5badeb0f0813e9c84258bc06eb77e40a117c48" and "afe20b404adbbfe7f8b57e6fb5ac343b5ced4528" have entirely different histories.
cc5badeb0f
...
afe20b404a
@ -1,45 +0,0 @@
|
|||||||
|
|
||||||
using Marco.Pms.Model.AppMenu;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using System;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Marco.Pms.CacheHelper
|
|
||||||
{
|
|
||||||
|
|
||||||
public class SideBarMenu
|
|
||||||
{
|
|
||||||
private readonly IMongoCollection<MenuSection> _collection;
|
|
||||||
private readonly ILogger<SideBarMenu> _logger;
|
|
||||||
|
|
||||||
public SideBarMenu(IConfiguration configuration, ILogger<SideBarMenu> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
var connectionString = configuration["MongoDB:ConnectionMenu"];
|
|
||||||
var mongoUrl = new MongoUrl(connectionString);
|
|
||||||
var client = new MongoClient(mongoUrl);
|
|
||||||
var database = client.GetDatabase(mongoUrl.DatabaseName);
|
|
||||||
_collection = database.GetCollection<MenuSection>("Menus");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<MenuSection?> CreateMenuSectionAsync(MenuSection section)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await _collection.InsertOneAsync(section);
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error occured while added in mongo");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can add Get, Update, Delete later here
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
using MongoDB.Bson;
|
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
|
||||||
|
|
||||||
namespace Marco.Pms.Model.AppMenu
|
|
||||||
{
|
|
||||||
public class MenuSection
|
|
||||||
{
|
|
||||||
[BsonId]
|
|
||||||
[BsonRepresentation(BsonType.String)]
|
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
public string? Header { get; set; }
|
|
||||||
public string? Title { get; set; }
|
|
||||||
public List<MenuItem> Items { get; set; } = new List<MenuItem>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MenuItem
|
|
||||||
{
|
|
||||||
[BsonId]
|
|
||||||
[BsonRepresentation(BsonType.String)]
|
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
public string? Text { get; set; }
|
|
||||||
public string? Icon { get; set; }
|
|
||||||
public bool Available { get; set; } = true;
|
|
||||||
|
|
||||||
public string? Link { get; set; }
|
|
||||||
|
|
||||||
public List<SubMenuItem> Submenu { get; set; } = new List<SubMenuItem> ();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SubMenuItem
|
|
||||||
{
|
|
||||||
[BsonId]
|
|
||||||
[BsonRepresentation(BsonType.String)]
|
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
|
||||||
|
|
||||||
public string? Text { get; set; }
|
|
||||||
public bool Available { get; set; } = true;
|
|
||||||
|
|
||||||
public string Link { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public string PermissionKey { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
using MongoDB.Bson;
|
|
||||||
using MongoDB.Bson.Serialization.Attributes;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Marco.Pms.Model.Dtos.AppMenu
|
|
||||||
{
|
|
||||||
public class MenuSectionDto
|
|
||||||
{
|
|
||||||
|
|
||||||
public string? Header { get; set; }
|
|
||||||
public string? Title { get; set; }
|
|
||||||
public List<MenuItemDto> Items { get; set; } = new List<MenuItemDto>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MenuItemDto
|
|
||||||
{
|
|
||||||
|
|
||||||
public string? Text { get; set; }
|
|
||||||
public string? Icon { get; set; }
|
|
||||||
public bool Available { get; set; } = true;
|
|
||||||
|
|
||||||
public string? Link { get; set; }
|
|
||||||
|
|
||||||
public List<SubMenuItemDto> Submenu { get; set; } = new List<SubMenuItemDto>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SubMenuItemDto
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
public string? Text { get; set; }
|
|
||||||
public bool Available { get; set; } = true;
|
|
||||||
|
|
||||||
public string Link { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public string PermissionKey { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,97 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using Azure;
|
|
||||||
using Marco.Pms.CacheHelper;
|
|
||||||
using Marco.Pms.Model.AppMenu;
|
|
||||||
using Marco.Pms.Model.Dtos.AppMenu;
|
|
||||||
using Marco.Pms.Model.Employees;
|
|
||||||
using Marco.Pms.Model.Entitlements;
|
|
||||||
using Marco.Pms.Model.Utilities;
|
|
||||||
using Marco.Pms.Services.Service;
|
|
||||||
using Marco.Pms.Services.Service.ServiceInterfaces;
|
|
||||||
using MarcoBMS.Services.Helpers;
|
|
||||||
using MarcoBMS.Services.Service;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Org.BouncyCastle.Asn1.Ocsp;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using static System.Collections.Specialized.BitVector32;
|
|
||||||
|
|
||||||
namespace Marco.Pms.Services.Controllers
|
|
||||||
{
|
|
||||||
[Authorize]
|
|
||||||
[ApiController]
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
public class AppMenuController : ControllerBase
|
|
||||||
{
|
|
||||||
|
|
||||||
private readonly UserHelper _userHelper;
|
|
||||||
private readonly EmployeeHelper _employeeHelper;
|
|
||||||
private readonly RolesHelper _rolesHelper;
|
|
||||||
private readonly SideBarMenu _sideBarMenuHelper;
|
|
||||||
private readonly IMapper _mapper;
|
|
||||||
private readonly ILoggingService _logger;
|
|
||||||
|
|
||||||
public AppMenuController(EmployeeHelper employeeHelper, IProjectServices projectServices, UserHelper userHelper, RolesHelper rolesHelper, SideBarMenu sideBarMenuHelper, IMapper mapper, ILoggingService logger) {
|
|
||||||
|
|
||||||
_userHelper = userHelper;
|
|
||||||
_employeeHelper = employeeHelper;
|
|
||||||
_rolesHelper = rolesHelper;
|
|
||||||
_sideBarMenuHelper = sideBarMenuHelper;
|
|
||||||
_mapper = mapper;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//[HttpGet("/appMenu")]
|
|
||||||
|
|
||||||
//public async Task<IActionResult> getAppSideBarMenu()
|
|
||||||
//{
|
|
||||||
// return Ok();
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
[HttpPost("create/appsidebar")]
|
|
||||||
public async Task<IActionResult> PostAppSideBarMenu([FromBody] MenuSectionDto sidebarMenu)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
var user = await _userHelper.GetCurrentEmployeeAsync();
|
|
||||||
|
|
||||||
if (!(user.ApplicationUser?.IsRootUser ?? false))
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Access Denied while creating side menu");
|
|
||||||
return StatusCode(403, ApiResponse<object>.ErrorResponse("access denied", "User haven't permission", 403));
|
|
||||||
}
|
|
||||||
|
|
||||||
var sideMenu = _mapper.Map<MenuSection>(sidebarMenu);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sideMenu = await _sideBarMenuHelper.CreateMenuSectionAsync(sideMenu);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Error Occurred while creating Menu");
|
|
||||||
return StatusCode(500, ApiResponse<object>.ErrorResponse("Server Error", ex, 500));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sideMenu == null) {
|
|
||||||
_logger.LogWarning("Error Occurred while creating Menu");
|
|
||||||
return BadRequest(ApiResponse<object>.ErrorResponse("Menu creation failed", 400));
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.LogInfo("Error Occurred while creating Menu");
|
|
||||||
return Ok(ApiResponse<object>.SuccessResponse(sideMenu, "Sidebar menu created successfully.", 201));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,6 +1,4 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Marco.Pms.Model.AppMenu;
|
|
||||||
using Marco.Pms.Model.Dtos.AppMenu;
|
|
||||||
using Marco.Pms.Model.Dtos.Project;
|
using Marco.Pms.Model.Dtos.Project;
|
||||||
using Marco.Pms.Model.Employees;
|
using Marco.Pms.Model.Employees;
|
||||||
using Marco.Pms.Model.Master;
|
using Marco.Pms.Model.Master;
|
||||||
@ -65,12 +63,6 @@ namespace Marco.Pms.Services.MappingProfiles
|
|||||||
#region ======================================================= Projects =======================================================
|
#region ======================================================= Projects =======================================================
|
||||||
CreateMap<Employee, EmployeeVM>();
|
CreateMap<Employee, EmployeeVM>();
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ======================================================= AppMenu =======================================================
|
|
||||||
CreateMap<MenuSectionDto, MenuSection>();
|
|
||||||
CreateMap<MenuItemDto, MenuItem>();
|
|
||||||
CreateMap<SubMenuItemDto, SubMenuItem>();
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -189,7 +189,6 @@ builder.Services.AddScoped<CacheUpdateHelper>();
|
|||||||
builder.Services.AddScoped<ProjectCache>();
|
builder.Services.AddScoped<ProjectCache>();
|
||||||
builder.Services.AddScoped<EmployeeCache>();
|
builder.Services.AddScoped<EmployeeCache>();
|
||||||
builder.Services.AddScoped<ReportCache>();
|
builder.Services.AddScoped<ReportCache>();
|
||||||
builder.Services.AddScoped<SideBarMenu>();
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// Singleton services (one instance for the app's lifetime)
|
// Singleton services (one instance for the app's lifetime)
|
||||||
|
|||||||
@ -47,9 +47,7 @@
|
|||||||
"BucketName": "testenv-marco-pms-documents"
|
"BucketName": "testenv-marco-pms-documents"
|
||||||
},
|
},
|
||||||
"MongoDB": {
|
"MongoDB": {
|
||||||
"SerilogDatabaseUrl": "mongodb://devuser:DevPass123@147.93.98.152:27017/DotNetLogs?authSource=admin",
|
"SerilogDatabaseUrl": "mongodb://localhost:27017/DotNetLogs",
|
||||||
"ConnectionString": "mongodb://devuser:DevPass123@147.93.98.152:27017/DevelopmentCache?authSource=admin&socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500",
|
"ConnectionString": "mongodb://localhost:27017/MarcoBMS_Caches?socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500"
|
||||||
"ConnectionMenu": "mongodb://devuser:DevPass123@147.93.98.152:27017/UpdateLogs?authSource=admin&socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500",
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user