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> GetControllerAccessByUserId(string userId) { try { var getMyControllerAccess = await _accountDbContext.ControllerAccess .FromSqlRaw($"EXEC GetElementAccessByUserId @UserId = '{userId}'") .ToListAsync(); return getMyControllerAccess ?? new List(); } catch (Exception ex) { ex.ToString(); throw; } } public async Task> GetDepartment() { try { var departments = await _accountDbContext.Departments .Where(d => d.IsActive == true) .ToListAsync(); return departments; } catch (SqlException ex) { ex.ToString(); throw; } } public async Task> GetUserRights(AccountDto accountDto) { try { var allItems = await _accountDbContext.UserRights .FromSqlRaw($"EXEC GetUserRights @UserId = '{accountDto.UserId}',@IsNotExist = '{accountDto.IsNotExist}'") .ToListAsync(); return allItems ?? new List(); } catch (SqlException ex) { ex.ToString(); throw; } } public async Task 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; } } } }