| 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using System.Web.Mvc;
|
|---|
| 4 | using Platnosci.Models;
|
|---|
| 5 | using Platnosci.Core.Linq;
|
|---|
| 6 | using Platnosci.Core.Interface;
|
|---|
| 7 | using System.Configuration;
|
|---|
| 8 | using System.Net;
|
|---|
| 9 | using System.IO;
|
|---|
| 10 | using System.Threading;
|
|---|
| 11 |
|
|---|
| 12 | namespace Platnosci.Controllers
|
|---|
| 13 | {
|
|---|
| 14 | [Authorize]
|
|---|
| 15 | public class MerchantController : Controller
|
|---|
| 16 | {
|
|---|
| 17 | private readonly IRepository<vPlatnosciEcard> _repVPayment;
|
|---|
| 18 | private readonly IRepository<PlatnosciEcard> _repPayment;
|
|---|
| 19 | private readonly FunkcjePlatnosci _funkcjePlatnosci;
|
|---|
| 20 | private readonly eCardData _eCardData;
|
|---|
| 21 | private readonly ITranslateManager _translateManager;
|
|---|
| 22 |
|
|---|
| 23 | public MerchantController()
|
|---|
| 24 | {
|
|---|
| 25 | _repVPayment = new Repository<vPlatnosciEcard>(new DataContext());
|
|---|
| 26 | _repPayment = new Repository<PlatnosciEcard>(new DataContext());
|
|---|
| 27 | _funkcjePlatnosci = new FunkcjePlatnosci(_repPayment);
|
|---|
| 28 | _translateManager = new Translation();
|
|---|
| 29 | _eCardData = new eCardData(_repPayment);
|
|---|
| 30 | }
|
|---|
| 31 | public MerchantController(IRepository<vPlatnosciEcard> repVPayment, IRepository<PlatnosciEcard> repPayment, ITranslateManager translate)
|
|---|
| 32 | {
|
|---|
| 33 | _repVPayment = repVPayment;
|
|---|
| 34 | _repPayment = repPayment;
|
|---|
| 35 | _translateManager = translate;
|
|---|
| 36 | _funkcjePlatnosci = new FunkcjePlatnosci(_repPayment, _translateManager);
|
|---|
| 37 | _eCardData = new eCardData(_repPayment);
|
|---|
| 38 | }
|
|---|
| 39 | public ActionResult Merchant(Payer payer, string language)
|
|---|
| 40 | {
|
|---|
| 41 | language = _funkcjePlatnosci.SetLanguage(language);
|
|---|
| 42 |
|
|---|
| 43 | var id1 = Convert.ToInt32(payer.Id_faktury);
|
|---|
| 44 | var platnosc = _repVPayment.Find(p => p.ID_faktury == id1).SingleOrDefault();
|
|---|
| 45 |
|
|---|
| 46 | var errorViewData = _funkcjePlatnosci.IsError(platnosc, ControllerContext.HttpContext.User.Identity.Name);
|
|---|
| 47 | if (!String.IsNullOrEmpty(errorViewData.Error))
|
|---|
| 48 | return View("Error1", errorViewData);
|
|---|
| 49 |
|
|---|
| 50 | var merchant = _eCardData.CreateMerchantData(platnosc, payer, language, Session.SessionID);
|
|---|
| 51 |
|
|---|
| 52 | if (merchant == null || (merchant != null && (!String.IsNullOrEmpty(merchant.Error))))
|
|---|
| 53 | return View("Error1", _funkcjePlatnosci.InitErrorViewData(_translateManager.Translate("tlumaczenia", "error_hash"), payer.Id_faktury));
|
|---|
| 54 |
|
|---|
| 55 | var adres = _eCardData.GetUrl(merchant);
|
|---|
| 56 | Response.Redirect(adres);
|
|---|
| 57 | return new EmptyResult();
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|