root/trunk/eCard/eCardMVC/Platnosci.Core/Linq/RepositoryPlatnosciEcard.cs @ 866

Wersja 866, 2.8 KB (wprowadzona przez alina, 16 years temu)

re #215

Line 
1using System;
2using System.Collections.Generic;
3using System.Data.Linq;
4using System.Linq;
5using System.Linq.Expressions;
6using System.Text;
7using Platnosci.Core.Interface;
8using Platnosci.Core.Linq;
9
10namespace Platnosci.Core.Linq
11{
12    public sealed class RepositoryPlatnosciEcard : IRepositoryPE
13    {
14        private readonly PlatnosciDataContext _dataContext = new PlatnosciDataContext();
15
16        public int Count()
17        {
18            return _dataContext.GetTable<PlatnosciEcard>().Count();
19        }
20        public int Count(Expression<Func<PlatnosciEcard, bool>> expression)
21        {
22            return _dataContext.GetTable<PlatnosciEcard>().Count(expression);
23        }
24        public PlatnosciEcard FindOne(int id)
25        {
26            return FindOne(t => t.ORDERNUMBER == id);
27        }
28        public PlatnosciEcard FindOne(Expression<Func<PlatnosciEcard, bool>> expression)
29        {
30            return _dataContext.GetTable<PlatnosciEcard>().Where(expression).SingleOrDefault();
31        }
32
33        public bool TryFindOne(Expression<Func<PlatnosciEcard, bool>> expression, out PlatnosciEcard entity)
34        {
35            entity = FindOne(expression);
36
37            return (entity != null);
38        }
39        public bool Exists(Expression<Func<PlatnosciEcard, bool>> expression)
40        {
41            var entity = FindOne(expression);
42
43            return (entity != null);
44        }
45        public IList<PlatnosciEcard> FindAll()
46        {
47            return _dataContext.GetTable<PlatnosciEcard>().ToList();
48        }
49        public IList<PlatnosciEcard> FindAll(Expression<Func<PlatnosciEcard, bool>> expression)
50        {
51            return _dataContext.GetTable<PlatnosciEcard>().Where(expression).ToList();
52        }
53
54        public void Insert(PlatnosciEcard entity)
55        {
56            _dataContext.GetTable<PlatnosciEcard>().InsertOnSubmit(entity);
57            _dataContext.SubmitChanges();
58        }
59        public void Delete(PlatnosciEcard entity)
60        {
61            if (entity != null)
62            {
63                _dataContext.GetTable<PlatnosciEcard>().DeleteOnSubmit(entity);
64                _dataContext.SubmitChanges();
65            }
66        }
67        public void Update(PlatnosciEcard entity)
68        {
69            _dataContext.SubmitChanges();
70        }
71        public IQueryable<PlatnosciEcard> Find(int id)
72        {
73            return _dataContext.GetTable<PlatnosciEcard>().Where(t => t.ORDERNUMBER == id);
74        }
75        public IQueryable<PlatnosciEcard> Find(Expression<Func<PlatnosciEcard, bool>> expression)
76        {
77            return _dataContext.GetTable<PlatnosciEcard>().Where(expression);
78        }
79        public IQueryable<PlatnosciEcard> Find()
80        {
81            return _dataContext.GetTable<PlatnosciEcard>();
82        }
83    }
84}
85
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.