Last active
December 29, 2015 00:39
-
-
Save jpsullivan/7587899 to your computer and use it in GitHub Desktop.
Service class example w/ Dapper usage for SProcs.
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.Data; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
using Dapper; | |
... | |
namespace Services { | |
public class UserService : IUserService | |
{ | |
/// <summary> | |
/// Retrieve all of the users within some kind of constraint. | |
/// </summary> | |
/// <param name="exampleParameter">A parameter that will be passed into the sproc.</param> | |
/// <returns>List of users</returns> | |
public IEnumerable<User> GetUsers(int exampleParameter) | |
{ | |
return Current.DB.Query<User>("sp_GetUsers", new { | |
@v_ParameterName = exampleParameter | |
}, commandType: CommandType.StoredProcedure); | |
} | |
/// <summary> | |
/// Check if user exists. | |
/// </summary> | |
/// <param name="username"></param> | |
/// <param name="organizationId"></param> | |
/// <returns>True if user exists, otherwise false</returns> | |
public bool UserExists(string username, int organizationId) { | |
var p = new DynamicParameters(); | |
p.Add("@v_UserName", username); | |
p.Add("@v_OrganizationId", organizationId); | |
p.Add("@o_Exists", null, DbType.Boolean, ParameterDirection.Output); | |
Current.DB.Execute("sp_DoesUserExist", p, CommandType.StoredProcedure); | |
return p.Get<Boolean>("@o_Exists"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment