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 System.Collections.Generic; | |
namespace NPOCOTestProject.DataLayer | |
{ | |
public interface IUserRepository | |
{ | |
Models.User Find(int id); | |
List<Models.User> GetAll(); | |
Models.User Add(Models.User user); | |
Models.User Update(Models.User user); |
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
public User Add(User user) | |
{ | |
db.BeginTransaction(); | |
db.Insert(user); | |
db.CompleteTransaction(); | |
return user; | |
} |
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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using NPoco; | |
namespace NPOCOTestProject.Models | |
{ | |
[TableName("ADDR_Address")] | |
[PrimaryKey("ADDR_ID")] |
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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using NPoco; | |
namespace NPOCOTestProject.Models | |
{ | |
[TableName("ADDR_Address")] | |
[PrimaryKey("ADDR_ID")] |
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
/* PetaPoco - A Tiny ORMish thing for your POCO's. | |
* Copyright © 2011-2012 Topten Software. All Rights Reserved. | |
* | |
* Apache License 2.0 - http://www.toptensoftware.com/petapoco/license | |
* | |
* Special thanks to Rob Conery (@robconery) for original inspiration (ie:Massive) and for | |
* use of Subsonic's T4 templates, Rob Sullivan (@DataChomp) for hard core DBA advice | |
* and Adam Schroder (@schotime) for lots of suggestions, improvements and Oracle support | |
*/ |
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
public Database(IDbConnection connection) | |
{ | |
_sharedConnection = connection; | |
_connectionString = connection.ConnectionString; | |
_sharedConnectionDepth = 0; | |
_providerName = connection.GetType().Namespace; | |
CommonConstruct(); | |
} |
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
var user = new Models.User | |
{ | |
USER_LastName = "Smith", | |
USER_FirstName = "Jim", | |
USER_FK_USST_ID = 1, | |
USER_FK_USTY_ID = 1, | |
USER_Password = "Pass", | |
USER_DateCreated = DateTime.Now, | |
USER_DateModified = DateTime.Now, | |
USER_EmailAddress = "JimSmith@gmail.com" |
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
private readonly Repositories.IUserRepository repository; | |
public HomeController(Repositories.IUserRepository iRepository) | |
{ | |
repository = iRepository; | |
} |
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
public void Save(User user) | |
{ | |
using (var connection = new SqlConnection(Startup.ConnectionStrings.DefaultConnection)) | |
{ | |
connection.Open(); | |
using (var transaction = connection.BeginTransaction()) | |
{ | |
if (user.IsNew) |
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
public User GetFullContact(int id) | |
{ | |
var user = this.Find(id); | |
var addresses = this.db.Query<Address>("WHERE ADDR_ID = @0", id).ToList(); | |
if (user != null && addresses != null) | |
{ | |
user.Addresses.AddRange(addresses); | |
} |
NewerOlder