Last active
March 9, 2017 13:51
-
-
Save yemrekeskin/6bafa15582c61ed394a1d61a8cbb9b76 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 CompanyRepository | |
: IRepository<Company> | |
{ | |
private IDbConnection _db = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); | |
public int Create(Company t) | |
{ | |
var sqlQuery = "INSERT INTO COR.COMPANY (NAME, DESCRIPTION,IS_ACTIVE) VALUES(@Name, @Description, @IsActive); " + | |
"SELECT CAST(SCOPE_IDENTITY() as int)"; | |
var id = this._db.Query<int>(sqlQuery, t).Single(); | |
t.Id = id; | |
return t.Id; | |
} | |
public int Delete() | |
{ | |
var sqlQuery = ("DELETE FROM COR.COMPANY"); | |
return _db.Execute(sqlQuery); | |
} | |
public int Delete(int id) | |
{ | |
var sqlQuery = ("DELETE FROM COR.COMPANY WHERE ID=" + id + ""); | |
return _db.Execute(sqlQuery); | |
} | |
public Company Find(int id) | |
{ | |
string query = "SELECT * FROM COR.COMPANY(NOLOCK) WHERE ID = " + id + ""; | |
return _db.Query<Company>(query).SingleOrDefault(); | |
} | |
public List<Company> List() | |
{ | |
List<Company> list = this._db.Query<Company>("SELECT * FROM COR.COMPANY(NOLOCK)").ToList(); | |
return list; | |
} | |
public bool Update(Company t) | |
{ | |
var sqlQuery = | |
"UPDATE COR.COMPANY " + | |
"SET NAME = @Name, " + | |
" DESCRIPTION = @Description, " + | |
" IS_ACTIVE = @IsActive " + | |
"WHERE ID = @Id"; | |
_db.Execute(sqlQuery, t); | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment