-
Notifications
You must be signed in to change notification settings - Fork 0
/
BidRepoDapper.cs
112 lines (98 loc) · 4.07 KB
/
BidRepoDapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Dapper;
using System.Configuration;
namespace HowMuchTo.Models
{
class BidRepoDapper : IChallengeBidRepository
{
private string connStr;
public BidRepoDapper()
{
connStr = ConfigurationManager.ConnectionStrings["DMTPrimary"].ConnectionString;
}
public void Add(ChallengeBid bid)
{
throw new NotImplementedException();
}
public List<ChallengeBid> Get(long chalID)
{
using (SqlConnection db = new SqlConnection(connStr))
{
db.Open();
var bids=db.Query<ChallengeBid>("spBidGetForChallenge", new { ChallengeID = chalID }, commandType: CommandType.StoredProcedure).AsEnumerable();
return bids.ToList<ChallengeBid>();
}
}
public List<ChallengeBid> GetForCustomer(long custID)
{
using (SqlConnection db = new SqlConnection(connStr))
{
db.Open();
var bids = db.Query<ChallengeBid>("spBidGetForCustomer", new { CustomerID = custID }, commandType: CommandType.StoredProcedure).AsEnumerable();
return bids.ToList<ChallengeBid>();
}
}
public void Update(ChallengeBid bid)
{
throw new NotImplementedException();
}
public ChallengeBid CustomerDidBidOnChallenge(long custID, long chalID)
{
using (SqlConnection db = new SqlConnection(connStr))
{
db.Open();
var bid = db.Query<ChallengeBid>("spBidCustomerBidForChallenge", new { CustomerID = custID, ChallengeID = chalID }, commandType: CommandType.StoredProcedure).FirstOrDefault();
return bid;
}
}
public int GetBidCountForChallenge(long ChallengeID)
{
using (SqlConnection db = new SqlConnection(connStr))
{
db.Open();
DynamicParameters p = new DynamicParameters();
p.Add("@ChallengeID", ChallengeID, DbType.Int64, ParameterDirection.Input);
p.Add("@BidCount", dbType: DbType.Int32, direction: ParameterDirection.Output);
db.Execute("spBidCountForChallenge", p, commandType: CommandType.StoredProcedure);
return p.Get<int>("@BidCount");
}
}
public List<ChallengeBid> GetVotePendingBidsForCustomer(long CustomerID)
{
throw new NotImplementedException();
}
public List<ChallengeBid> GetActiveBidsForCustomer(long CustomerID)
{
throw new NotImplementedException();
}
public void UpdateStatusForBidsOnChallenge(long ChallengeID, ChallengeBid.BidStatusCodes NewStatus)
{
using (SqlConnection db = new SqlConnection(connStr))
{
db.Open();
db.Execute("UpdateStatusForBidsOnChallenge", new { ChallengeID = ChallengeID, NewStatus = (int)NewStatus }, commandType: CommandType.StoredProcedure);
}
}
public void UpdateVotePendingCustomerIDForChallenge(long ChallengeID, long CustomerID)
{
using (SqlConnection db = new SqlConnection(connStr))
{
db.Open();
db.Execute("spBidUpdateVotePendingCustomer", new { ChallengeID = ChallengeID, CustomerID = CustomerID }, commandType: CommandType.StoredProcedure);
}
}
public void UpdateStatusForBid(long ChallengeID, long CustomerID, int Status)
{
using (SqlConnection db = new SqlConnection(connStr))
{
db.Open();
db.Execute("spBidUpdateStatus", new { ChallengeID = ChallengeID, CustomerID = CustomerID, Status = Status }, commandType: CommandType.StoredProcedure);
}
}
}
}