Index: trunk/eCard/eCardMVC/Platnosci.Core/Interface/IRepository.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci.Core/Interface/IRepository.cs (revision 866)
+++ trunk/eCard/eCardMVC/Platnosci.Core/Interface/IRepository.cs (revision 870)
@@ -4,4 +4,5 @@
 using System.Linq.Expressions;
 using System.Text;
+using Platnosci.Core.Linq;
 
 namespace Platnosci.Core.Interface
@@ -16,5 +17,5 @@
 
         void Delete(T entity);
-
+        
         void Update(T entity);
 
@@ -36,4 +37,10 @@
 
         IQueryable<T> Find(Expression<Func<T, bool>> expression);
+
+        IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer);
+
+        IQueryable<vPlatnosciEcard> FindInvoiceById(int id);
+
+        List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury);
     }
 }
Index: trunk/eCard/eCardMVC/Platnosci.Core/Platnosci.Core.csproj
===================================================================
--- trunk/eCard/eCardMVC/Platnosci.Core/Platnosci.Core.csproj (revision 866)
+++ trunk/eCard/eCardMVC/Platnosci.Core/Platnosci.Core.csproj (revision 870)
@@ -63,8 +63,10 @@
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Interface\IDataContext.cs" />
     <Compile Include="Interface\IIdentifiable.cs" />
+    <Compile Include="Interface\IRep.cs" />
     <Compile Include="Interface\IRepository.cs" />
-    <Compile Include="Interface\IRepositoryPE.cs" />
-    <Compile Include="Interface\IRepositoryPT.cs" />
+    <Compile Include="Linq\DataContext1.cs" />
+    <Compile Include="Linq\FakeDataContext.cs" />
     <Compile Include="Linq\Payer.cs" />
     <Compile Include="Linq\Platnosci.cs">
@@ -78,7 +80,7 @@
     <Compile Include="Linq\PlatnosciDataContext.cs" />
     <Compile Include="Linq\PlatnosciEcard.cs" />
+    <Compile Include="Linq\PotwierdzeniaEcard.cs" />
+    <Compile Include="Linq\Rep.cs" />
     <Compile Include="Linq\Repository.cs" />
-    <Compile Include="Linq\RepositoryPlatnosciEcard.cs" />
-    <Compile Include="Linq\RepositoryPotwierdzeniaEcard.cs" />
     <Compile Include="Linq\vPlatnosciEcard.cs" />
     <Compile Include="Linq\Waluta.cs" />
Index: trunk/eCard/eCardMVC/Platnosci.Core/Linq/Platnosci.designer.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci.Core/Linq/Platnosci.designer.cs (revision 866)
+++ trunk/eCard/eCardMVC/Platnosci.Core/Linq/Platnosci.designer.cs (revision 870)
@@ -22,11 +22,10 @@
 	using System.ComponentModel;
 	using System;
-	
+    using Platnosci.Core.Interface;
 	
 	[System.Data.Linq.Mapping.DatabaseAttribute(Name="BAZA_REKLAM_TEST")]
-	public partial class PlatnosciDataContext : System.Data.Linq.DataContext
+	public partial class PlatnosciDataContext : DataContext
 	{
-		
-		private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
+        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
 		
     #region Extensibility Method Definitions
@@ -48,34 +47,28 @@
     partial void DeletevPlatnosciEcard(vPlatnosciEcard instance);
     #endregion
-    public PlatnosciDataContext() : 
-				base(global::Platnosci.Core.Properties.Settings.Default.BAZA_REKLAM_TESTConnectionString, mappingSource)
-		{
-			OnCreated();
-		}
-		
-		public PlatnosciDataContext(string connection) : 
-				base(connection, mappingSource)
-		{
-			OnCreated();
-		}
-		
-		public PlatnosciDataContext(System.Data.IDbConnection connection) : 
-				base(connection, mappingSource)
-		{
-			OnCreated();
-		}
-		
-		public PlatnosciDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
-				base(connection, mappingSource)
-		{
-			OnCreated();
-		}
-		
-		public PlatnosciDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
-				base(connection, mappingSource)
-		{
-			OnCreated();
-		}
-		
+       public PlatnosciDataContext() :base(global::Platnosci.Core.Properties.Settings.Default.BAZA_REKLAM_TESTConnectionString, mappingSource)
+		{
+           OnCreated();
+		}
+		
+		public PlatnosciDataContext(string connection) : base(connection, mappingSource)
+		{
+            OnCreated();
+		}
+		
+		public PlatnosciDataContext(System.Data.IDbConnection connection) : base(connection, mappingSource)
+		{
+            OnCreated();
+		}
+		
+		public PlatnosciDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :base(connection, mappingSource)
+		{
+            OnCreated();
+		}
+		
+		public PlatnosciDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :base(connection, mappingSource)
+		{
+            OnCreated();
+		}
 		public System.Data.Linq.Table<PlatnosciEcard> PlatnosciEcards
 		{
Index: trunk/eCard/eCardMVC/Platnosci.Core/Linq/PlatnosciDataContext.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci.Core/Linq/PlatnosciDataContext.cs (revision 866)
+++ trunk/eCard/eCardMVC/Platnosci.Core/Linq/PlatnosciDataContext.cs (revision 870)
@@ -2,47 +2,12 @@
 using System.Collections.Generic;
 using System.Linq;
+using Platnosci.Core.Interface;
 
 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;
-        }
+       
     }
 }
Index: trunk/eCard/eCardMVC/Platnosci.Core/Linq/Platnosci.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci.Core/Linq/Platnosci.cs (revision 866)
+++ trunk/eCard/eCardMVC/Platnosci.Core/Linq/Platnosci.cs (revision 870)
@@ -1,5 +1,5 @@
-namespace Platnosci.Core
+namespace Platnosci.Core    
 {
-    partial class PlatnosciDataContext
+    partial class PlatnosciDataContext 
     {
     }
Index: trunk/eCard/eCardMVC/Platnosci.Core/Linq/Repository.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci.Core/Linq/Repository.cs (revision 867)
+++ trunk/eCard/eCardMVC/Platnosci.Core/Linq/Repository.cs (revision 870)
@@ -15,9 +15,14 @@
     /// <typeparam name="T">The generic type representing the entity we are dealing with</typeparam>
     /// <remarks>We use a 1 to 1 mapping of entity -> SQL table</remarks>
-    public sealed class Repository<T> : IRepository<T>
-      where T : class, IIdentifiable
+    public class Repository<T> : IRepository<T> where T : class, IIdentifiable
     {
-        private readonly PlatnosciDataContext _dataContext = new PlatnosciDataContext();
+       // private readonly PlatnosciDataContext _dataContext = new PlatnosciDataContext();
+        //private PlatnosciDataContext _dataContext = new PlatnosciDataContext();
+        protected readonly IDataContext _dataContext;
 
+        public Repository(IDataContext dataContext)
+        {
+            _dataContext = dataContext;
+        }  
         public int Count()
         {
@@ -57,23 +62,11 @@
             return _dataContext.GetTable<T>().Where(expression).ToList();
         }
-
         public void Insert(T entity)
-        {
-            //DataContext.GetTable<T>().InsertOnSubmit(entity);
-            //DataContext.SubmitChanges();
-
-            //using (DataContext dc = new WierszowkiDataContext())
-            //{
-                _dataContext.GetTable<T>().InsertOnSubmit(entity);
-                _dataContext.SubmitChanges();
-            //}
-        }
+	    {
+	        _dataContext.Insert(entity);            
+	    }
         public void Delete(T entity)
         {
-            if (entity != null)
-            {
-                _dataContext.GetTable<T>().DeleteOnSubmit(entity);
-                _dataContext.SubmitChanges();
-            }
+            _dataContext.Insert(entity);
         }
         public void Update(T entity)
@@ -92,5 +85,17 @@
         {
             return _dataContext.GetTable<T>();
-        }       
+        }
+        public IQueryable<vPlatnosciEcard> FindInvoiceByNipNumber(string nip, string numer)
+        {
+            return _dataContext.FindInvoiceByNipNumber(nip, numer);
+        }
+        public IQueryable<vPlatnosciEcard> FindInvoiceById(int id)
+        {
+            return _dataContext.FindInvoiceById(id);
+        }
+        public List<PotwierdzeniaEcard> FindItemsByIdFaktury(int idFaktury)
+        {
+            return _dataContext.FindItemsByIdFaktury(idFaktury);
+        }
     }
 }
Index: trunk/eCard/eCardMVC/Platnosci/Controllers/AccountController.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci/Controllers/AccountController.cs (revision 866)
+++ trunk/eCard/eCardMVC/Platnosci/Controllers/AccountController.cs (revision 870)
@@ -32,5 +32,5 @@
         public AccountController()
         {
-            _repository = new Repository<vPlatnosciEcard>();
+            _repository = new Repository<vPlatnosciEcard>(new DataContext1());
             FormsAuth = new FormsAuthenticationService();
             _context = new PlatnosciDataContext();
@@ -65,5 +65,6 @@
             else
             {
-                var Login = _context.FindInvoiceByNipNumber(nip, numer_faktury).SingleOrDefault();
+                var Login = _repository.FindInvoiceByNipNumber(nip, numer_faktury).SingleOrDefault();
+                    //_context.FindInvoiceByNipNumber(nip, numer_faktury).SingleOrDefault();
                 platnosc = Login;
                 if (platnosc == null) return View();
Index: trunk/eCard/eCardMVC/Platnosci/Controllers/MerchantController.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci/Controllers/MerchantController.cs (revision 868)
+++ trunk/eCard/eCardMVC/Platnosci/Controllers/MerchantController.cs (revision 870)
@@ -32,10 +32,10 @@
         private string merchantId;
         private readonly PlatnosciDataContext _context;
-        private readonly IRepositoryPE _rep;
+        private readonly IRepository<PlatnosciEcard> _rep;
         private FunkcjePlatnosci _func;
 
         public MerchantController()
         {   
-            _rep = new RepositoryPlatnosciEcard();
+            _rep = new Repository<PlatnosciEcard>(new DataContext1());
             _context = new PlatnosciDataContext();
             _func = new FunkcjePlatnosci();
@@ -46,5 +46,5 @@
 
             int id1 = Convert.ToInt32(payer.Id_faktury);
-            vPlatnosciEcard platnosc = _context.FindInvoiceById(id1).SingleOrDefault();
+            vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
             
             if (!_func.UserIdentity(platnosc, ControllerContext.HttpContext.User.Identity.Name))
@@ -64,14 +64,9 @@
 
             string hash = GetHash(newPayment, systemKs);
+            hash = hash.Replace("\n","");
+            if (hash == BAD_HASH  || hash == "" ) return View("Error");
 
-            hash = hash.Replace("\n","");
-            if (hash == BAD_HASH  || hash == "" )
-            {
-                return View("Error"); //nie mo¿na po³¹czyæ siê z serverem p³atnoci. Proszê spróbowaæ jeszcze raz.
-            }
-            if (platnosc.SystemKsiegowyId == 1)
-                merchantId = "170906000";
-            else
-                merchantId = "171485000";
+            if (systemKs == "1") merchantId = "170906000";
+                else merchantId = "171485000";
 
             string link = ConfigurationManager.AppSettings["StatusLink"];
Index: trunk/eCard/eCardMVC/Platnosci/Controllers/PlatnoscController.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci/Controllers/PlatnoscController.cs (revision 868)
+++ trunk/eCard/eCardMVC/Platnosci/Controllers/PlatnoscController.cs (revision 870)
@@ -12,4 +12,6 @@
 using System.Web.UI;
 using System.Threading;
+using System.Data.Linq;
+using System.Web.Configuration;
 
 namespace Platnosci.Controllers
@@ -19,12 +21,19 @@
     {
         private readonly PlatnosciDataContext _context;
-        private readonly IRepositoryPT _rep;
+        private readonly IDataContext _context1;
+        private readonly IRepository<PotwierdzeniaEcard> _rep;
+        private readonly IRep<PotwierdzeniaEcard> _repository;
         private FunkcjePlatnosci _func;
 
+
         public PlatnoscController()
         {
             _context = new PlatnosciDataContext();
-            _rep = new RepositoryPotwierdzeniaEcard();
+            _rep = new Repository<PotwierdzeniaEcard>(new DataContext1()); 
             _func = new FunkcjePlatnosci();
+        }
+        public PlatnoscController(IDataContext datacontext){
+            _rep = new Repository<PotwierdzeniaEcard>(datacontext);
+            _context1 = datacontext;
         }
         public ActionResult Show(string id, string language)
@@ -40,6 +49,6 @@
             {
             }
-            vPlatnosciEcard platnosc = _context.FindInvoiceById(id1).SingleOrDefault();
-
+           
+            vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
             //sprawdzamy czy numer faktury dotyczy zalogowanego usera
             ErrorViewData errorViewData = new ErrorViewData();
@@ -55,5 +64,5 @@
             }
             
-            var tablica_potwierdzenia = _context.FindItemsByIdFaktury(id1);
+            var tablica_potwierdzenia = _rep.FindItemsByIdFaktury(id1);
             if (tablica_potwierdzenia.Count > 0) //platnosc za fakture zostala uregulowana
             {
@@ -83,5 +92,5 @@
             {
             }
-            vPlatnosciEcard platnosc = _context.FindInvoiceById(id1).SingleOrDefault();
+            vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
             ErrorViewData errorViewData = new ErrorViewData();
             if (platnosc == null)
@@ -130,5 +139,5 @@
                 //id1=0 -> error type =  platnoscIsNotExist;
             }
-            vPlatnosciEcard platnosc = _context.FindInvoiceById(id1).SingleOrDefault();
+            vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault();
             ErrorViewData errorViewData = new ErrorViewData();
             if (platnosc == null)
Index: trunk/eCard/eCardMVC/Platnosci.Tests/Web/PlatnosciControllerTests.cs
===================================================================
--- trunk/eCard/eCardMVC/Platnosci.Tests/Web/PlatnosciControllerTests.cs (revision 866)
+++ trunk/eCard/eCardMVC/Platnosci.Tests/Web/PlatnosciControllerTests.cs (revision 870)
@@ -17,39 +17,69 @@
     class PlatnosciControllerTests
     {
-        private string merchantNumber = "123";
+         private string merchantNumber = "123";
 
-        [TearDown]
-        public void TearDown()
+         /*[TearDown]
+         public void TearDown()
+         {
+             IRepository<PotwierdzeniaEcard> _rep = new Repository<PotwierdzeniaEcard>();
+             var potwierdzeniaEcard = _rep.Find(p => p.MERCHANTNUMBER == merchantNumber);
+
+             foreach (var pe in potwierdzeniaEcard)
+             {
+                 _rep.Delete(pe);
+             }
+         }
+        */
+         [Test]
+         public void Status_Saves_Correct_Transaction()
+         {
+            
+             var orderNumber = 9999;
+             FakeDataContext fake = new FakeDataContext();
+             var builder = new TestControllerBuilder();
+             var controller = new PlatnoscController(fake);
+             builder.InitializeController(controller);
+             builder.Form.Add("MERCHANTNUMBER", merchantNumber.ToString());
+             builder.Form.Add("AUTHTIME", DateTime.Now.ToString());
+             builder.Form.Add("DATATRANSMISJI", DateTime.Now.ToString());
+             builder.Form.Add("ORDERNUMBER", orderNumber.ToString());
+
+             var result = controller.Status();
+
+             IRepository<PotwierdzeniaEcard> _rep = new Repository<PotwierdzeniaEcard>(fake);            
+             var potwierdzeniaEcard = _rep.Find(p => p.ORDERNUMBER == orderNumber).First();
+             Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));            
+         } 
+        [Test]
+        public void NumerFaktury()
         {
-            IRepositoryPT _rep = new RepositoryPotwierdzeniaEcard();
-            var potwierdzeniaEcard = _rep.Find(p => p.MERCHANTNUMBER == merchantNumber);
+             FakeDataContext fake = new FakeDataContext();
+             IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
 
-            foreach (var pe in potwierdzeniaEcard)
-            {
-                _rep.Delete(pe);
-            }
+             vPlatnosciEcard platnosc = new vPlatnosciEcard();
+             platnosc = _rep.FindInvoiceById(1).SingleOrDefault();
+             Assert.That(platnosc.Faktura_Numer, Is.EqualTo("222/2"));
         }
+        [Test]
+        public void AddPayment()
+        {
+            FakeDataContext fake = new FakeDataContext();
+            IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);
 
-        [Test]
-        public void Status_Saves_Correct_Transaction()
-        {
-            
-            var orderNumber = 9999;
+            vPlatnosciEcard platnosc = new vPlatnosciEcard();
+            platnosc.ID_faktury = 13;
+            platnosc.nip = "nipek";
+            _rep.Insert(platnosc);
 
-            var builder = new TestControllerBuilder();
-            var controller = new PlatnoscController();
-            builder.InitializeController(controller);
-            builder.Form.Add("MERCHANTNUMBER", merchantNumber.ToString());
-            builder.Form.Add("AUTHTIME", DateTime.Now.ToString());
-            builder.Form.Add("DATATRANSMISJI", DateTime.Now.ToString());
-            builder.Form.Add("ORDERNUMBER", orderNumber.ToString());
+            vPlatnosciEcard pl1 = new vPlatnosciEcard();
+            pl1.ID_faktury = 14;
+            pl1.nip = "vv";
+            _rep.Insert(pl1);
 
-            var result = controller.Status();
-
-            IRepositoryPT _rep = new RepositoryPotwierdzeniaEcard();
-            var potwierdzeniaEcard = _rep.Find(p => p.ORDERNUMBER == orderNumber).First();
-            Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));
-            
+            vPlatnosciEcard pl = _rep.FindInvoiceById(13).SingleOrDefault();
+            Assert.That(pl.nip, Is.EqualTo("nipek"));
         }
+        
     }
 }
+
