Game.Changers.Core.Standard.Frameworks 1.0.0.1

dotnet add package Game.Changers.Core.Standard.Frameworks --version 1.0.0.1
NuGet\Install-Package Game.Changers.Core.Standard.Frameworks -Version 1.0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Game.Changers.Core.Standard.Frameworks" Version="1.0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Game.Changers.Core.Standard.Frameworks --version 1.0.0.1
#r "nuget: Game.Changers.Core.Standard.Frameworks, 1.0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Game.Changers.Core.Standard.Frameworks as a Cake Addin
#addin nuget:?package=Game.Changers.Core.Standard.Frameworks&version=1.0.0.1

// Install Game.Changers.Core.Standard.Frameworks as a Cake Tool
#tool nuget:?package=Game.Changers.Core.Standard.Frameworks&version=1.0.0.1

License

MIT

Installation

Install my-project with npm

 NuGet\Install-Package Game.Changers.Core.Standard.Frameworks -Version 1.0.0

Quickstart

Build an Interface inside your Repositories

namespace Data.Repositories
{
    public interface IUsersRepository
    {
        /// <summary>
        /// Delete User
        /// </summary>
        /// <param name="UserID">UserID</param>
        /// <returns>true when success</returns>
        Task<bool> DeleteUser(int UserID);

        /// <summary>
        /// SubmitUser
        /// </summary>
        /// <param name="oAtsUser">Object of AtsUser</param>
        /// <returns>True when success</returns>
        Task<bool> SubmitUser(User oUser);

        /// <summary>
        /// Update User
        /// </summary>
        /// <param name="oAtsUser">Object of oAtsUser</param>
        /// <returns>true when success </returns>

        Task<bool> UpdateUser(User oUser);

        /// <summary>
        /// Sync Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        List<User> GetAllUsers(string UserFullName) ;

        /// <summary>
        /// Async Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        Task<List<User>> AsyncGetAllUsers(string UserFullName);
    }

}

Implement the Interface


namespace  Data.Repositories
{
    public class UsersRepository : Repository , IUsersRepository
    { 
        // Pass Connection to Base to exectue the the Context and return result 
        public UsersRepository(DbContext oDbContextInitialization) : base(oDbContextInitialization) { }
        
        /// <summary>
        /// Delete User
        /// </summary>
        /// <param name="UserID">UserID</param>
        /// <returns>true when success</returns>
        public async Task<bool> DeleteUser(int UserID)
        {
            bool bResult = false;
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(new SqlParameter() { ParameterName = "ID", SqlDbType = System.Data.SqlDbType.Int, Value = UserID });
            lstParameters.Add(new SqlParameter() { ParameterName = "oPERATION_RESULT", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Output });
            try
            {
                await  this.ExecuteSqlStoredProcedureCommand("DEL_ATS_USERS", lstParameters);
                bResult = ((int)lstParameters[1].Value) > 0;
            }
            catch (DbUpdateException oDbUpdateException)
            {
                throw oDbUpdateException.InnerException;
            }
            return bResult;
        }

        /// <summary>
        /// SubmitUser
        /// </summary>
        /// <param name="oUser">Object of AtsUser</param>
        /// <returns>True when success</returns>
        public async Task<bool> SubmitUser(User oUser)
        {
            bool bResult = false;
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(new SqlParameter() { ParameterName = "ID", SqlDbType = System.Data.SqlDbType.UniqueIdentifier, Value = Guid.NewGuid() });
            lstParameters.Add(new SqlParameter() { ParameterName = "NAME", SqlDbType = System.Data.SqlDbType.NVarChar, Value = oUser.FirstName });
            lstParameters.Add(new SqlParameter() { ParameterName = "DESCRIPTION", SqlDbType = System.Data.SqlDbType.NVarChar, Value = oUser.Lastname });
            lstParameters.Add(new SqlParameter() { ParameterName = "RECORD_STATE", SqlDbType = System.Data.SqlDbType.Int, Value = 1 });
            lstParameters.Add(new SqlParameter() { ParameterName = "DONE_BY", SqlDbType = System.Data.SqlDbType.Int, Value = oUser.UserId, });
            lstParameters.Add(new SqlParameter() { ParameterName = "LANGUAGE_ID", SqlDbType = System.Data.SqlDbType.Int, Value = oUser.UserId });
            lstParameters.Add(new SqlParameter() { ParameterName = "oPERATION_RESULT", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Output, });
            try
            {
                await  this.ExecuteSqlStoredProcedureCommand("INS_ATS_USERS", lstParameters);
                int nOutPutIndex = lstParameters.IndexOf(lstParameters.Find(x => x.ParameterName == "oPERATION_RESULT"));
                bResult = ((int)lstParameters[nOutPutIndex].Value) > 0;
            }
            catch (DbUpdateException oDbUpdateException)
            {
                throw oDbUpdateException.InnerException;
            }
            return bResult;
        }

        /// <summary>
        /// Update User
        /// </summary>
        /// <param name="oUser">Object of oAtsUser</param>
        /// <returns>true when success </returns>
        public async Task<bool> UpdateUser(User oUser)
        {
            bool bResult = false;
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(new SqlParameter() { ParameterName = "ID", SqlDbType = System.Data.SqlDbType.UniqueIdentifier, Value = oUser.UserId });
            lstParameters.Add(new SqlParameter() { ParameterName = "NAME", SqlDbType = System.Data.SqlDbType.NVarChar, Value = oUser.UserId });
            lstParameters.Add(new SqlParameter() { ParameterName = "DESCRIPTION", SqlDbType = System.Data.SqlDbType.NVarChar, Value = oUser.UserId });
            lstParameters.Add(new SqlParameter() { ParameterName = "RECORD_STATE", SqlDbType = System.Data.SqlDbType.Int, Value = oUser.UserId });
            lstParameters.Add(new SqlParameter() { ParameterName = "DONE_BY", SqlDbType = System.Data.SqlDbType.UniqueIdentifier, Value = oUser.UserId });
            lstParameters.Add(new SqlParameter() { ParameterName = "LANGUAGE_ID", SqlDbType = System.Data.SqlDbType.Int, Value = oUser.UserId });
            lstParameters.Add(new SqlParameter() { ParameterName = "oPERATION_RESULT", SqlDbType = System.Data.SqlDbType.Int, Direction = System.Data.ParameterDirection.Output });
            try
            {
               await this.ExecuteSqlStoredProcedureCommand("UMS_SP_UPDATE_APPLICATION", lstParameters);
                bResult = ((int)lstParameters[5].Value) > 0;
            }
            catch (DbUpdateException oDbUpdateException)
            {
                throw oDbUpdateException.InnerException;
            }
            return bResult;
        }

        /// <summary>
        /// Sync Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        public List<User>  GetAllUsers(string UserFullName)
        {
            List<User> lstUsers = new List<User>();
            List <SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(new SqlParameter() { ParameterName = "PIN_FULL_NAME", SqlDbType = System.Data.SqlDbType.NVarChar, Value = UserFullName });
            try
            {
                lstUsers = this.ExecuteSqlStoredProcedureList<User>("GET_USERS_BY_NAME", lstParameters);
             }
            catch (DbUpdateException oDbUpdateException)
            {
                throw oDbUpdateException.InnerException;
            }
            return lstUsers;
        }

        /// <summary>
        /// Async Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        public async Task<List<User>> AsyncGetAllUsers(string UserFullName)
        {
            List<User> lstUsers = new List<User>();
            List<SqlParameter> lstParameters = new List<SqlParameter>();
            lstParameters.Add(new SqlParameter() { ParameterName = "PIN_FULL_NAME", SqlDbType = System.Data.SqlDbType.NVarChar, Value = UserFullName });
            try
            {
                lstUsers =await this.AsyncExecuteSqlStoredProcedureList<User>("GET_USERS_BY_NAME", lstParameters);
            }
            catch (DbUpdateException oDbUpdateException)
            {
                throw oDbUpdateException.InnerException;
            }
            return lstUsers;
        }
    }


Build Unit Of Work Interface


namespace  Data.UnitOfWork
{
     public interface IDataAccessUnitOfWork<U> where U : DbContext, IDisposable
     {
        #region Methods
        #region Method :: Commit
        /// <summary>
        /// This method will commit all changes on ORM data model context
        /// </summary>
        /// <returns>The number of objects written to the underlying database.</returns>
        int intCommit();
        #endregion

        #region Method :: CommitAsync
        /// <summary>
        /// This method will commit all changes on ORM data model context
        /// </summary>
        /// <returns>The number of objects written to the underlying database.</returns>
        Task<int> intCommitAsync();
        #endregion
        #endregion

        /// <summary>
        /// IUsersRepository
        /// </summary>
        IUsersRepository UsersRepository { get; }
         
      

    }
 }


Implement the Unit Of work Interface



namespace  Data.UnitOfWork
{
     public interface IDataAccessUnitOfWork<U> where U : DbContext, IDisposable
     {
        #region Methods
        #region Method :: Commit
        /// <summary>
        /// This method will commit all changes on ORM data model context
        /// </summary>
        /// <returns>The number of objects written to the underlying database.</returns>
        int intCommit();
        #endregion

        #region Method :: CommitAsync
        /// <summary>
        /// This method will commit all changes on ORM data model context
        /// </summary>
        /// <returns>The number of objects written to the underlying database.</returns>
        Task<int> intCommitAsync();
        #endregion
        #endregion

        /// <summary>
        /// IUsersRepository
        /// </summary>
        IUsersRepository UsersRepository { get; }
         
      

    }
 }


Build Service


namespace  Data.Services
{
    public interface IUsersService
    {
        /// <summary>
        /// Delete User
        /// </summary>
        /// <param name="UserID">UserID</param>
        /// <returns>true when success</returns>
        Task<bool> DeleteUser(int UserID);

        /// <summary>
        /// SubmitUser
        /// </summary>
        /// <param name="oAtsUser">Object of AtsUser</param>
        /// <returns>True when success</returns>
        Task<bool> SubmitUser(User oUser);

        /// <summary>
        /// Update User
        /// </summary>
        /// <param name="oAtsUser">Object of oAtsUser</param>
        /// <returns>true when success </returns>
        Task<bool> UpdateUser(User oUser);

        /// <summary>
        /// Sync Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        List<User> GetAllUsers(string UserFullName);

        /// <summary>
        /// Async Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        Task<List<User>> AsyncGetAllUsers(string UserFullName);
    }
}

Implement the Service


namespace Data.Services
{
    public class UsersService : IUsersService
    {
        IDataAccessUnitOfWork<DB_Connection> oDataAccessUnitOfWork;
        public UsersService(IDataAccessUnitOfWork<DB_Connection> oUnitOfWork)
        {
            this.oDataAccessUnitOfWork = oUnitOfWork;
        }

        /// <summary>
        /// Delete User
        /// </summary>
        /// <param name="UserID">UserID</param>
        /// <returns>true when success</returns>
        public async Task<bool> DeleteUser(int UserID)
        {
            return await this.oDataAccessUnitOfWork.UsersRepository.DeleteUser(UserID);
        }

        /// <summary>
        /// SubmitUser
        /// </summary>
        /// <param name="oAtsUser">Object of AtsUser</param>
        /// <returns>True when success</returns>
        public async Task<bool> SubmitUser(User oUser)
        {
            return await this.oDataAccessUnitOfWork.UsersRepository.SubmitUser(oUser);
        }
        
        /// <summary>
        /// Update User
        /// </summary>
        /// <param name="oAtsUser">Object of oAtsUser</param>
        /// <returns>true when success </returns>
        public async Task<bool> UpdateUser(User oUser)
        {
            return await this.oDataAccessUnitOfWork.UsersRepository.UpdateUser(oUser);

        }
     
        /// <summary>
        /// Sync Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        public List<User>  GetAllUsers(string UserFullName)
        {
            return   this.oDataAccessUnitOfWork.UsersRepository.GetAllUsers(UserFullName);
        }

        /// <summary>
        /// Async Get All Users
        /// </summary>
        /// <param name="UserFullName">User Full Name</param>
        /// <returns>List Of Ats user</returns>
        public async Task<List<User>> AsyncGetAllUsers(string UserFullName)
        {
            return await this.oDataAccessUnitOfWork.UsersRepository.AsyncGetAllUsers(UserFullName);
        }
    }
}

Create Class Lib and Inject the service


namespace Infrastructure.Utilities
{


    public static class DependencyInjectionContainer
    {

        /// <summary>
        /// Register Services 
        /// </summary>
        /// <param name="oServices">Collect of the service builder within the system </param>
        private static void RegisterDI(IServiceCollection oServices)
        {
            oServices.AddScoped(typeof(IUnitOfWork<>), typeof(UnitOfWork<>));
            oServices.AddScoped(typeof(IRepository<>), typeof(Repository<>));
            oServices.AddScoped(typeof(IDataAccessUnitOfWork<>), typeof(DataAccessUnitOfWork<>));
            oServices.AddScoped<IUsersService, UsersService>();

        }

        /// <summary>
        /// General Method to register all services 
        /// </summary>
        /// <param name="oServices">Collect of the service builder within the system </param>
        public static void RegisterDISettings(IServiceCollection oServices, IConfiguration oConfiguration)
        {
            RegisterDI(oServices);
            AddMongoDb(oServices, oConfiguration);
        }

        public static void JWT(IServiceCollection oServices, IConfiguration oConfiguration)
        {
           oServices.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
           {
               options.TokenValidationParameters = new TokenValidationParameters
               {
                   ValidateIssuer = true,
                   ValidateAudience = true,
                   ValidateLifetime = true,
                   ValidateIssuerSigningKey = true,
                   ValidIssuer = oConfiguration.GetSection("Jwt:Issuer").Value,
                   ValidAudience = oConfiguration.GetSection("Jwt:Issuer").Value,
                   IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(oConfiguration.GetSection("Jwt:Key").Value))
               };
           });
        }

        public static void AddMongoDb(IServiceCollection oServices, IConfiguration oConfiguration)
        {

            oServices.Configure<MONGO_DB_SETTINGS>(options =>
            {
                options.ConnectionString
                    = oConfiguration.GetSection("Mongo:Connection_String").Value;
                options.Innovation_Oases_DB
                  = oConfiguration.GetSection("Mongo:Innovation_Oases_DB").Value;

                options.Innovation_Oases_ERRORS_DB
                = oConfiguration.GetSection("Mongo:Innovation_Oases_ERRORS_DB").Value;
            });

            //Add Mongo Repository And Services
             

            oServices.AddScoped<IUSERS_REPOSITORY, USERS_REPOSITORY>();
            oServices.AddScoped<IUSER_SERVICE, USER_SERVICE>();
             

        }

    }
}


Finally in the APIs , add this inside Program.cs

DependencyInjectionContainer.RegisterDISettings(builder.Services,builder.Configuration);

In the API controller use the service 😃

 #region  Private Memebers
 private IUsersService oIUsersService;
 private IWebHostEnvironment oIHostingEnvironment;
 private IUSER_SERVICE oIUSER_SERVICE;
 private IConfiguration oConfigurations;
 #endregion

 #region Api Constructor
 /// <summary>
 /// Intialize The POC 
 /// </summary>
 /// <param name="oIAtsUsersServiceObject">Instance Of Ats Users Service</param>
 /// <param name="ApplicationEnvironment"> Instance Of the application environment</param>
 public IOController(IUsersService oIAtsUsersServiceObject
     , IWebHostEnvironment ApplicationEnvironment,
     IUSER_SERVICE oIUSER_SERVICE,
     IConfiguration oConfiguration)
 {
     this.oIUsersService = oIAtsUsersServiceObject;
     this.oIHostingEnvironment = ApplicationEnvironment;
     this.oIUSER_SERVICE = oIUSER_SERVICE;
     this.oConfigurations = oConfiguration;
 }
 #endregion


[HttpGet()]
 public async Task<IEnumerable<User>> SQL()
 {
     var Result = await this.oIUsersService.AsyncGetAllUsers("Omar");
     return Result.AsEnumerable();
 }

License

MIT

Authors

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0.1 71 6/23/2024
1.0.0 68 6/23/2024