root/trunk/eCard/eCardMVC/Platnosci.Tests/Web/FakeDataContext.cs @ 883

Wersja 883, 5.0 KB (wprowadzona przez alina, 16 years temu)

re #215 edycja widoku dla zapłaconej faktury, zmiana funkcji UpdateStatus? (edycja statusu po CURRENTSTATE a nie VALIDATIONCODE)

RevLine 
[872]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using Platnosci.Core.Interface;
6
7namespace Platnosci.Core.Linq
8{
9    public class FakeDataContext : IDataContext
10    {
11        private List<vPlatnosciEcard> listaPlatnosci = new List<vPlatnosciEcard>();
12        private List<PotwierdzeniaEcard> listaPotwierdzenia = new List<PotwierdzeniaEcard>();
13        private List<PlatnosciEcard> listaPl = new List<PlatnosciEcard>();
14        private List<object> lista = new List<object>();
[883]15        private string code_Ok = "payment_deposited";        //transakcja potwierdzona do rozliczenia
16        private string code_Bad = "payment_declined";        //transakcja odrzucona
[872]17
18        public vPlatnosciEcard DodajPlatnosc(int id, string numer, string nip)
19        {
20            vPlatnosciEcard p = new vPlatnosciEcard();
21            p.ID_faktury = id;
22            p.Faktura_Numer = numer;
23            p.nip = nip;
24           
25            return p;
26        }
27        public PotwierdzeniaEcard DodajPotwierdzenie(string code, int ordernumber)
28        {
29            PotwierdzeniaEcard potwierdzenie = new PotwierdzeniaEcard();
[883]30            potwierdzenie.CURRENTSTATE = code;
[872]31            potwierdzenie.ORDERNUMBER = ordernumber;
32
33            return potwierdzenie;
34        }
35        public PlatnosciEcard createNewPayment(int ordernumber, bool status, DateTime data, int id_faktury)
36        {
37            PlatnosciEcard platnosc = new PlatnosciEcard();
38            platnosc.ORDERNUMBER = ordernumber;
39            platnosc.Status = status;
40            platnosc.Status_data = data;
41            platnosc.IDFaktury = id_faktury;
42
43            return platnosc;
44        }
45        public FakeDataContext()
46        {
47            listaPlatnosci.Add(DodajPlatnosc(1,"1","123"));
48            listaPlatnosci.Add(DodajPlatnosc(2, "2", "aaa"));
49        }
50        public FakeDataContext(int i)
51        {
[877]52            if (i == 1)
53            {
54                listaPlatnosci.Add(DodajPlatnosc(1000, "abcd", "12345"));
55                listaPl.Add(createNewPayment(9999, true, DateTime.Now, 1000));
[883]56                listaPotwierdzenia.Add(DodajPotwierdzenie(code_Ok, 9999));
[877]57            }
58            else if (i == 2)
59            {
60                listaPl.Add(createNewPayment(9999, true, DateTime.Now, 1000));
61            }
[872]62        }
63        public IQueryable<T> GetTable<T>() where T : class
64        {
65            var query = from objects in lista   
66                    where typeof(T).IsAssignableFrom(objects.GetType())
67                    select objects;
68                return query.Select(o => (T)o).AsQueryable();
69        }
70        public void Insert<T>(T item) where T : class
71        {
72            lista.Add(item);
73        }
74        public void Delete<T>(T item) where T : class
75        {
76            lista.Remove(item);
77        }
78        public IQueryable<vPlatnosciEcard> FindInvoiceById(int id)
79            {
80            List<object> lp = lista;
81            for (int i = 0; i < lp.Count(); i++)
82            {
83                if (lp[i].GetType() == typeof(vPlatnosciEcard))
84                {
85                    listaPlatnosci.Add((vPlatnosciEcard)lp[i]);
86                }
87            }
88            lista.Clear();
89
90            var query = from l in listaPlatnosci
91                        where l.ID_faktury == id
92                            select l;
93               
94            return query.AsQueryable();
95            }
96        public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
97        {
[877]98            List<object> lp = lista;
99            for (int i = 0; i < lp.Count(); i++)
100            {
101                if (lp[i].GetType() == typeof(vPlatnosciEcard))
102                {
103                    listaPlatnosci.Add((vPlatnosciEcard)lp[i]);
104                }
105            }
106            lista.Clear();
107
[872]108            var query = from l in listaPlatnosci
109                        where l.nip == nip && l.Faktura_Numer == numer
110                        select l;
111
112            return query.AsQueryable();
113        }
114        public List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury)
115        {
116            List<PotwierdzeniaEcard> listazaplaconych = new List<PotwierdzeniaEcard>();
117            for (int j = 0; j < listaPl.Count(); j++)
118            {
119                for (int i = 0; i < listaPotwierdzenia.Count(); i++)
120                {
[883]121                    if (listaPl[j].IDFaktury == idFaktury && listaPl[j].ORDERNUMBER == listaPotwierdzenia[i].ORDERNUMBER && listaPotwierdzenia[i].CURRENTSTATE == code_Ok) listazaplaconych.Add(listaPotwierdzenia[i]);
[872]122                }
123            }
124            return listazaplaconych;
125        }
[877]126        public IQueryable<PlatnosciEcard> FindPaymentByOrdernumber(int ordernumber)
127        {
128            var query = from l in listaPl
129                        where l.ORDERNUMBER == ordernumber
130                        select l;
131
132            return query.AsQueryable();
133        }
[872]134        public void SubmitChanges()
135        {
136           
137        }
138       
139    }
140}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.