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