using System;
using System.Collections.Generic;
using System.Linq;

namespace Platnosci.Core.Linq
{
    public partial class PlatnosciDataContext
    {
        public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
        {
            var query = from i in vPlatnosciEcards
                where (i.nip == nip && i.Faktura_Numer == numer)
                select i;
            return query;            
        }
        public IQueryable<vPlatnosciEcard> FindInvoiceById(int id)
        {
            var query = from i in vPlatnosciEcards
                        where i.ID_faktury == id
                        select i;
            return query;
        }
        public List<PotwierdzeniaEcard>FindItemsByIdFaktury(int idFaktury)
        {
            var query = from vp in PlatnosciEcards
                        where vp.IDFaktury == idFaktury && vp.Status == true
                        orderby vp.IDFaktury descending
                        select vp;

            query.ToList();
            var tablica = new List<PotwierdzeniaEcard>();
            
            foreach (var pt in query)
            {
                var query2 = from ps in PotwierdzeniaEcards
                             where ps.ORDERNUMBER == pt.ORDERNUMBER && ps.VALIDATIONCODE == "000"
                             orderby ps.id
                             select ps;
               
                for (var i = 0; i < query2.ToList().Count; i++)
                {
                    tablica.Add(query2.ToList()[i]);
                }              
            }            
            return tablica;
        }
    }
}