8. Models 폴더에 8번에서 작성한 인터페이스를 상속 받아 멤버를 구현하는 CommunityCampJoinMemberRepository.cs 클래스를 다음과 같이 작성한다. SQL 구문은 따로 저장 프로시저를 만들지 않았으므로 리파지터리 클래스에서 인라인 SQL로 작성한다.
▼ /Models/CommunityCampJoinMemberRepository.cs
using Dapper;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
namespace DotNetNote.Models
{
public class CommunityCampJoinMemberRepository :
ICommunityCampJoinMemberRepository
{
private readonly IConfiguration _config;
private SqlConnection con;
public CommunityCampJoinMemberRepository(IConfiguration config)
{
_config = config;
con = new SqlConnection(_config.GetSection(“Data”)
.GetSection(“DefaultConnection”).GetSection(“ConnectionString”).Value);
}
public List<CommunityCampJoinMember> GetAll()
{
return con.Query<CommunityCampJoinMember>(
“Select * From CommunityCampJoinMembers Order By Id Asc”).ToList();
}
public void AddMember(CommunityCampJoinMember model)
{
con.Execute(“Insert Into CommunityCampJoinMembers “
+ ” (CommunityName, Name, Mobile, Email, Size, CreationDate) “
+ ” Values (@CommunityName, @Name, @Mobile, @Email, @Size, GetDate())”,
model);
}
public void DeleteMember(CommunityCampJoinMember model)
{
con.Execute(“Delete CommunityCampJoinMembers Where “
+ ” CommunityName = @CommunityName And Name = @Name And “
+ “Mobile = @Mobile And Email = @Email”, model);
}
}
}