Skip to content

Commit

Permalink
Merge pull request #5 from rajguptaH/develop
Browse files Browse the repository at this point in the history
Updated KeplerCrud Using
  • Loading branch information
rajguptaH authored Feb 12, 2023
2 parents 95cda7a + e4f8cea commit cb7ee4c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 39 deletions.
3 changes: 1 addition & 2 deletions WebApiExample/WebApiExample/Controllers/StudentController.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
3 changes: 1 addition & 2 deletions WebApiExample/WebApiExample/Models/StudentModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ namespace WebApiCrud.Models
[KeplerTable("Student")]
public class StudentModel
{
[KeplerColumn("Id")]
[KeplerPKey("Id")]
public int Id { get; set; }
[KeplerColumn("Name")]
public string Name { get; set; }
[KeplerColumn]
public int RollNo { get; set; }
[KeplerColumn]
public string Class { get; set; }
[KeplerColumn]
public string Address { get; set; }
}
}
2 changes: 0 additions & 2 deletions WebApiExample/WebApiExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddScoped<IStudentService, StudentService>();
builder.Services.AddScoped<IKeplerRepository<StudentModel>,KeplerRepository<StudentModel>>();
builder.Services.AddSingleton<IKeplerConnection,KeplerConnection>();
builder.Services.AddScoped<IConnectionBuilder, ConnectionBuilder>();

var app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}



}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace WebApiCrud.Library.Connection.Interface
{
public interface IConnectionBuilder
{

IDbConnection GetConnection { get; }
}
}
46 changes: 21 additions & 25 deletions WebApiExample/WebApiExample/Utility/Data/Service/StudentService.cs
Original file line number Diff line number Diff line change
@@ -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<StudentModel> _keplerRepository;
public StudentService(IKeplerRepository<StudentModel> 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<StudentModel>(id);

}
public List<StudentModel> Get()
{
return _keplerRepository.GetAll(false);
using IDbConnection con = _connectionBuilder.GetConnection;
var result = con.GetAll<StudentModel>(true);
return result;
}

public StudentModel Get(int id)
{
using IDbConnection con = _connectionBuilder.GetConnection;
List<ConditionPair> conditionPairs = new List<ConditionPair>
{
new ConditionPair() { Value = $"{id}", Where = "Id" }
};
return _keplerRepository.Get(conditionPairs,true);
return con.Get<StudentModel>(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);
}
}
}
2 changes: 1 addition & 1 deletion WebApiExample/WebApiExample/WebApiCrud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Rng.KeplerCrud" Version="6.2.1" />
<PackageReference Include="Rng.KeplerCrud" Version="3.2.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>
Expand Down

0 comments on commit cb7ee4c

Please sign in to comment.