diff --git a/WebApiExample/WebApiExample/Controllers/StudentController.cs b/WebApiExample/WebApiExample/Controllers/StudentController.cs index 0cf8726..109d71c 100644 --- a/WebApiExample/WebApiExample/Controllers/StudentController.cs +++ b/WebApiExample/WebApiExample/Controllers/StudentController.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using WebApiCrud.Models; using WebApiCrud.Utility.Data.Service.Interface; diff --git a/WebApiExample/WebApiExample/Models/StudentModel.cs b/WebApiExample/WebApiExample/Models/StudentModel.cs index 95a7674..b163f9e 100644 --- a/WebApiExample/WebApiExample/Models/StudentModel.cs +++ b/WebApiExample/WebApiExample/Models/StudentModel.cs @@ -5,7 +5,7 @@ namespace WebApiCrud.Models [KeplerTable("Student")] public class StudentModel { - [KeplerColumn("Id")] + [KeplerPKey("Id")] public int Id { get; set; } [KeplerColumn("Name")] public string Name { get; set; } @@ -13,7 +13,6 @@ public class StudentModel public int RollNo { get; set; } [KeplerColumn] public string Class { get; set; } - [KeplerColumn] public string Address { get; set; } } } diff --git a/WebApiExample/WebApiExample/Program.cs b/WebApiExample/WebApiExample/Program.cs index c74f5eb..1f80b3c 100644 --- a/WebApiExample/WebApiExample/Program.cs +++ b/WebApiExample/WebApiExample/Program.cs @@ -15,8 +15,6 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddScoped(); -builder.Services.AddScoped,KeplerRepository>(); -builder.Services.AddSingleton(); builder.Services.AddScoped(); var app = builder.Build(); diff --git a/WebApiExample/WebApiExample/Utility/Connection/DbConnectionBuilder.cs b/WebApiExample/WebApiExample/Utility/Connection/ConnectionBuilder.cs similarity index 84% rename from WebApiExample/WebApiExample/Utility/Connection/DbConnectionBuilder.cs rename to WebApiExample/WebApiExample/Utility/Connection/ConnectionBuilder.cs index 512e3a1..bffdfd3 100644 --- a/WebApiExample/WebApiExample/Utility/Connection/DbConnectionBuilder.cs +++ b/WebApiExample/WebApiExample/Utility/Connection/ConnectionBuilder.cs @@ -17,20 +17,15 @@ public IDbConnection GetConnection get { { - - try { - SqlConnection connection = new SqlConnection(_configuration["ConnectionStrings:Prop"]); + SqlConnection connection = new SqlConnection(_configuration["ConnectionStrings:Value"]); return connection; } catch (Exception ex) { return null; } - - - } } } diff --git a/WebApiExample/WebApiExample/Utility/Connection/IConnectionBuilder.cs b/WebApiExample/WebApiExample/Utility/Connection/IConnectionBuilder.cs index b5e60f1..835e25b 100644 --- a/WebApiExample/WebApiExample/Utility/Connection/IConnectionBuilder.cs +++ b/WebApiExample/WebApiExample/Utility/Connection/IConnectionBuilder.cs @@ -4,7 +4,6 @@ namespace WebApiCrud.Library.Connection.Interface { public interface IConnectionBuilder { - IDbConnection GetConnection { get; } } } diff --git a/WebApiExample/WebApiExample/Utility/Data/Service/StudentService.cs b/WebApiExample/WebApiExample/Utility/Data/Service/StudentService.cs index c75ede4..f5f1332 100644 --- a/WebApiExample/WebApiExample/Utility/Data/Service/StudentService.cs +++ b/WebApiExample/WebApiExample/Utility/Data/Service/StudentService.cs @@ -1,53 +1,49 @@ -using WebApiCrud.Utility.Data.Service.Interface; +using KeplerCrud.Repository; +using System.Data; +using WebApiCrud.Library.Connection.Interface; using WebApiCrud.Models; -using KeplerCrud.Repository; +using WebApiCrud.Utility.Data.Service.Interface; namespace WebApiCrud.Utility.Data.Service { public class StudentService : IStudentService { - private readonly IKeplerRepository _keplerRepository; - public StudentService(IKeplerRepository keplerRepository) - { - _keplerRepository = keplerRepository; + private readonly IConnectionBuilder _connectionBuilder; + public StudentService(IConnectionBuilder connectionBuilder) + { + _connectionBuilder = connectionBuilder; } - public bool Delete(int id) { - return _keplerRepository.SoftDelete(id); - - } + using IDbConnection con = _connectionBuilder.GetConnection; + return con.SoftDelete(id); + } public List Get() { - return _keplerRepository.GetAll(false); + using IDbConnection con = _connectionBuilder.GetConnection; + var result = con.GetAll(true); + return result; } - public StudentModel Get(int id) { + using IDbConnection con = _connectionBuilder.GetConnection; List conditionPairs = new List { new ConditionPair() { Value = $"{id}", Where = "Id" } }; - return _keplerRepository.Get(conditionPairs,true); + return con.Get(conditionPairs, false); } - public int Insert(StudentModel uiPageTypeModel) { - var result = _keplerRepository.Insert(uiPageTypeModel); - if (result) - { - return 1; - } - else - { - return 0; - } + using IDbConnection con = _connectionBuilder.GetConnection; + var result = con.Insert(uiPageTypeModel); + return result ? 1 : 0; } - public bool Update(StudentModel uiPageTypeModel) { - return _keplerRepository.Update(uiPageTypeModel); + using IDbConnection con = _connectionBuilder.GetConnection; + return con.Update(uiPageTypeModel); } } } diff --git a/WebApiExample/WebApiExample/WebApiCrud.csproj b/WebApiExample/WebApiExample/WebApiCrud.csproj index 0e1d14c..7788507 100644 --- a/WebApiExample/WebApiExample/WebApiCrud.csproj +++ b/WebApiExample/WebApiExample/WebApiCrud.csproj @@ -10,7 +10,7 @@ - +