| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Linq;
|
|---|
| 4 | using Platnosci.Core.Interface;
|
|---|
| 5 |
|
|---|
| 6 | namespace Platnosci.Core.Linq
|
|---|
| 7 | {
|
|---|
| 8 | public class DataContext : IDataContext
|
|---|
| 9 | {
|
|---|
| 10 | private readonly PlatnosciDataContext _dataContext;
|
|---|
| 11 | private readonly List<object> _listaPlatnosci = new List<object>();
|
|---|
| 12 |
|
|---|
| 13 | public DataContext()
|
|---|
| 14 | {
|
|---|
| 15 | _dataContext = new PlatnosciDataContext();
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | public IQueryable<T> GetTable<T>() where T : class
|
|---|
| 19 | {
|
|---|
| 20 | return _dataContext.GetTable<T>();
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | public void Insert<T>(T item) where T : class
|
|---|
| 24 | {
|
|---|
| 25 | _dataContext.GetTable<T>().InsertOnSubmit(item);
|
|---|
| 26 | _dataContext.SubmitChanges();
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | public void Delete<T>(T item) where T : class
|
|---|
| 30 | {
|
|---|
| 31 | if (item == null) return;
|
|---|
| 32 |
|
|---|
| 33 | _dataContext.GetTable<T>().DeleteOnSubmit(item);
|
|---|
| 34 | _dataContext.SubmitChanges();
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | public void SubmitChanges()
|
|---|
| 38 | {
|
|---|
| 39 | _dataContext.SubmitChanges();
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
|
|---|
| 43 | {
|
|---|
| 44 | var query = from i in _dataContext.vPlatnosciEcards
|
|---|
| 45 | where (i.nip == nip && i.Faktura_Numer == numer)
|
|---|
| 46 | select i;
|
|---|
| 47 | return query;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | public IQueryable<vPlatnosciEcard> FindInvoiceById(int id)
|
|---|
| 51 | {
|
|---|
| 52 | var query = from i in _dataContext.vPlatnosciEcards
|
|---|
| 53 | where i.ID_faktury == id
|
|---|
| 54 | select i;
|
|---|
| 55 | return query;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | public List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury)
|
|---|
| 59 | {
|
|---|
| 60 | var query = _dataContext.PlatnosciEcards
|
|---|
| 61 | .Where(vp => vp.IDFaktury == idFaktury && vp.Status == true)
|
|---|
| 62 | .OrderByDescending(vp => vp.IDFaktury);
|
|---|
| 63 |
|
|---|
| 64 | query.ToList();
|
|---|
| 65 |
|
|---|
| 66 | var tablica = new List<PotwierdzeniaEcard>();
|
|---|
| 67 |
|
|---|
| 68 | foreach (var pt in query)
|
|---|
| 69 | {
|
|---|
| 70 | var ecard = pt;
|
|---|
| 71 | var query2 = _dataContext.PotwierdzeniaEcards
|
|---|
| 72 | .Where(ps => ps.ORDERNUMBER == ecard.ORDERNUMBER && ps.CURRENTSTATE == "payment_deposited")
|
|---|
| 73 | .OrderBy(ps => ps.id);
|
|---|
| 74 |
|
|---|
| 75 | for (var i = 0; i < query2.ToList().Count; i++)
|
|---|
| 76 | {
|
|---|
| 77 | tablica.Add(query2.ToList()[i]);
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | return tablica;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | public List<object> Getlista()
|
|---|
| 85 | {
|
|---|
| 86 | return _listaPlatnosci;
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | public IQueryable<PlatnosciEcard> FindPaymentByOrdernumber(int ordernumber)
|
|---|
| 90 | {
|
|---|
| 91 | var query = from l in _dataContext.PlatnosciEcards
|
|---|
| 92 | where l.ORDERNUMBER == ordernumber
|
|---|
| 93 | select l;
|
|---|
| 94 |
|
|---|
| 95 | return query;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | public int GetOrdernumber(string description, int? idfaktury, DateTime? data)
|
|---|
| 99 | {
|
|---|
| 100 | var ordernumber = 0;
|
|---|
| 101 |
|
|---|
| 102 | var query = from l in _dataContext.PlatnosciEcards
|
|---|
| 103 | where l.ORDERDESCRIPTION == description && l.IDFaktury == idfaktury && l.Data == data
|
|---|
| 104 | select l;
|
|---|
| 105 |
|
|---|
| 106 | var pl = query.ToList();
|
|---|
| 107 |
|
|---|
| 108 | if (pl.Count > 0 && pl[0].ORDERNUMBER > 0) ordernumber = pl[0].ORDERNUMBER;
|
|---|
| 109 |
|
|---|
| 110 | return ordernumber;
|
|---|
| 111 | }
|
|---|
| 112 | }
|
|---|
| 113 | } |
|---|