-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIREPO.cs
151 lines (130 loc) · 3.24 KB
/
IREPO.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Data.Entity;
using System.Data.Entity.Migrations;
namespace RPS
{
interface IREPO<T> where T : class
{
List<T> getall();
bool getallbyid(T a); // for login
IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
T insert(T a);
T update(T a);
T delete(T a);
}
class GRepo<T> : IREPO<T>, IDisposable where T : class
{
private Conn cc;
private DbSet<T> entities;
public GRepo()
{
cc = new Conn();
entities = cc.Set<T>();
}
//public GRepo(Conn c)
//{
// this.cc = c;
// entities = cc.Set<T>();
//}
public T delete(T a)
{
entities.Remove(a);
cc.SaveChanges();
return a;
}
public IQueryable<T> FindBy(Expression<Func<T, bool>> predicate)
{
IQueryable<T> query = cc.Set<T>().Where(predicate);
return query;
}
public List<T> getall()
{
return entities.ToList();
}
public bool getallbyid(T a)
{
throw new NotImplementedException();
}
public T insert(T a)
{
entities.Add(a);
try
{
cc.SaveChanges();
return a;
}
catch (Exception)
{
throw new System.Data.Entity.Core.UpdateException();
}
}
public T update(T a)
{
cc.Entry(a).State = EntityState.Modified;
cc.SaveChanges();
return a;
}
~GRepo()
{
Dispose();
}
public void Dispose()
{
cc.Dispose();
}
}
class LoginREpo : IREPO<BAL>// For login only
{
Conn cn = new Conn();
public BAL delete(BAL a)
{
var v = cn.LoginBals.Find(a.Userid);
cn.LoginBals.Remove(v);
cn.SaveChanges();
return a;
}
~LoginREpo() { }
public IQueryable<BAL> FindBy(Expression<Func<BAL, bool>> predicate)
{
throw new NotImplementedException();
}
public List<BAL> getall()
{
var x = cn.LoginBals.ToList();
return x;
}
public bool getallbyid(BAL a)
{
try
{
var x = cn.LoginBals.Any(b => b.Userid == a.Userid && b.Pass == a.Pass);
return x;
}
catch (System.Data.SqlClient.SqlException ex)
{
//return false;
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
public BAL insert(BAL a)
{
cn.LoginBals.Add(a);
cn.SaveChanges();
return a;
}
public BAL update(BAL a)
{
// var x = cn.LoginBals.Find(a);
cn.Entry(a).State = EntityState.Modified;
cn.SaveChanges();
return a;
}
}
}