63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using Dapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Text;
|
|
using TrackerLibrary.Models;
|
|
|
|
|
|
//@PlaceNumber int,
|
|
//@PlaceName nvarchar(50),
|
|
//@PrizeAmount money,
|
|
// @PrizePercentage float,
|
|
//@id int = 0 output
|
|
|
|
namespace TrackerLibrary.DataAccess
|
|
{
|
|
public class SqlConnector : IDataConnection
|
|
{
|
|
public PersonModel CreatePerson(PersonModel model)
|
|
{
|
|
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments"))) {
|
|
var p = new DynamicParameters();
|
|
p.Add("@FirstName", model.FirstName);
|
|
p.Add("@LastName", model.LastName);
|
|
p.Add("@EmailAddress", model.EmailAddress);
|
|
p.Add("@CellPhoneNumber", model.CellPhoneNumber);
|
|
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
|
|
|
connection.Execute("dbo.spPeople_Insert", p, commandType: CommandType.StoredProcedure);
|
|
|
|
model.Id = p.Get<int>("@Id");
|
|
|
|
return model;
|
|
}
|
|
}
|
|
|
|
// TODO - Make the CreatePrize method actually save to the database
|
|
/// <summary>
|
|
/// Saves a prize to the database
|
|
/// </summary>
|
|
/// <param name="model">The prize information.</param>
|
|
/// <returns>The prize information, including the unique identifier.</returns>
|
|
public Models.PrizeModel CreatePrize(Models.PrizeModel model)
|
|
{
|
|
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments")))
|
|
{
|
|
var p = new DynamicParameters();
|
|
p.Add("@PlaceNumber", model.PlaceNumber);
|
|
p.Add("@PlaceName", model.PlaceName);
|
|
p.Add("@PrizeAmount", model.PrizeAmount);
|
|
p.Add("@PrizePercentage", model.PrizePercentage);
|
|
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
|
|
|
connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure);
|
|
|
|
model.Id = p.Get<int>("@Id");
|
|
|
|
return model;
|
|
}
|
|
}
|
|
}
|
|
}
|