Last active
March 9, 2017 13:50
-
-
Save yemrekeskin/549f6ee918c51bd6922440b1fc2d420d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ComManager.Models; | |
using Dapper; | |
using System.Collections.Generic; | |
using System.Configuration; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Linq; | |
namespace ComManager.Repository | |
{ | |
public class CompanySpRepository | |
: IRepository<Company> | |
{ | |
private IDbConnection _db = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); | |
public int Create(Company t) | |
{ | |
var parm = new DynamicParameters(); | |
parm.Add("@NAME", t.Name); | |
parm.Add("@DESCRIPTION", t.Description); | |
parm.Add("@IS_ACTIVE", t.IsActive); | |
var result = _db.Query<Company>("COR.INSERT_COMPANY", parm, commandType: CommandType.StoredProcedure); | |
return 1; | |
} | |
public int Delete() | |
{ | |
var parm = new DynamicParameters(); | |
parm.Add("@ID", -1); | |
var result = _db.Query<Company>("COR.DELETE_COMPANY", parm, commandType: CommandType.StoredProcedure); | |
return 1; | |
} | |
public int Delete(int id) | |
{ | |
var parm = new DynamicParameters(); | |
parm.Add("@ID", id); | |
var result = _db.Query<Company>("COR.DELETE_COMPANY", parm, commandType: CommandType.StoredProcedure); | |
return 1; | |
} | |
public Company Find(int id) | |
{ | |
var parm = new DynamicParameters(); | |
parm.Add("@ID", id); | |
parm.Add("@NAME", ""); | |
parm.Add("@DESCRIPTION", ""); | |
parm.Add("@IS_ACTIVE", false); | |
var result = _db.Query<Company>("COR.SELECT_COMPANY", parm, commandType: CommandType.StoredProcedure).Single(); | |
return result; | |
} | |
public List<Company> List() | |
{ | |
var parm = new DynamicParameters(); | |
parm.Add("@ID", -1); | |
parm.Add("@NAME", ""); | |
parm.Add("@DESCRIPTION", ""); | |
parm.Add("@IS_ACTIVE", false); | |
var list = _db.Query<Company>("COR.SELECT_COMPANY", parm, commandType: CommandType.StoredProcedure).ToList(); | |
return list; | |
} | |
public bool Update(Company t) | |
{ | |
var parm = new DynamicParameters(); | |
parm.Add("@ID", t.Id); | |
parm.Add("@NAME", t.Name); | |
parm.Add("@DESCRIPTION", t.Description); | |
parm.Add("@IS_ACTIVE", t.IsActive); | |
var result = _db.Query<Company>("COR.UPDATE_COMPANY", parm, commandType: CommandType.StoredProcedure); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment