101 lines
3.1 KiB
C#
101 lines
3.1 KiB
C#
using CPRNIMS.Domain.Contracts.Account;
|
|
using CPRNIMS.Infrastructure.Database;
|
|
using CPRNIMS.Infrastructure.Dto.Account;
|
|
using CPRNIMS.Infrastructure.Entities.Account;
|
|
using Google;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CPRNIMS.Domain.Services.Account
|
|
{
|
|
public class Account : IAccount
|
|
{
|
|
private readonly NonInventoryDbContext _accountDbContext;
|
|
|
|
public Account(NonInventoryDbContext applicationDbContext)
|
|
{
|
|
_accountDbContext = applicationDbContext;
|
|
}
|
|
|
|
public async Task<List<Infrastructure.Entities.Account.ControllerAccess>> GetControllerAccessByUserId(string userId)
|
|
{
|
|
try
|
|
{
|
|
|
|
var getMyControllerAccess = await _accountDbContext.ControllerAccess
|
|
.FromSqlRaw($"EXEC GetElementAccessByUserId @UserId = '{userId}'")
|
|
.ToListAsync();
|
|
|
|
return getMyControllerAccess ?? new List<Infrastructure.Entities.Account.ControllerAccess>();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ex.ToString();
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<Departments>> GetDepartment()
|
|
{
|
|
try
|
|
{
|
|
var departments = await _accountDbContext.Departments
|
|
.Where(d => d.IsActive == true)
|
|
.ToListAsync();
|
|
|
|
return departments;
|
|
}
|
|
catch (SqlException ex)
|
|
{
|
|
ex.ToString();
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<List<UserRights>> GetUserRights(AccountDto accountDto)
|
|
{
|
|
try
|
|
{
|
|
var allItems = await _accountDbContext.UserRights
|
|
.FromSqlRaw($"EXEC GetUserRights @UserId = '{accountDto.UserId}',@IsNotExist = '{accountDto.IsNotExist}'")
|
|
.ToListAsync();
|
|
|
|
return allItems ?? new List<UserRights>();
|
|
}
|
|
catch (SqlException ex)
|
|
{
|
|
ex.ToString();
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task<UserRights> PutPostUserAccess(AccountDto itemDto)
|
|
{
|
|
try
|
|
{
|
|
await _accountDbContext.Database
|
|
.ExecuteSqlRawAsync("EXEC PutPostUserAccess @ContAccId,@AdminUserId,@UserId,@AccessTypeId,@UserAccessId,@IsActive",
|
|
new SqlParameter("@ContAccId", itemDto.ContAccId),
|
|
new SqlParameter("@AdminUserId", itemDto.AdminUserId),
|
|
new SqlParameter("@UserId", itemDto.UserId),
|
|
new SqlParameter("@AccessTypeId", itemDto.AccessTypeId),
|
|
new SqlParameter("@UserAccessId", itemDto.UserAccessId),
|
|
new SqlParameter("@IsActive", itemDto.IsActive));
|
|
|
|
return new UserRights();
|
|
}
|
|
catch (SqlException ex)
|
|
{
|
|
ex.ToString();
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|