using ClerkecertifyConnector;
using Microsoft.SqlServer.Server;
using myShoppingCartIntegration.Helper;
using myShoppingCartIntegration.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace myShoppingCartIntegration.Controllers
    {
    public class HomeController : Controller
        {
        string testUrl = "https://test.clerkecertify.com";
        string prodUrl = "https://clerkecertify.com";

        // This is your subscriber code. Get it from Triedata
        string subscribercode = "";
        string token = "";
        // This is your FIPS Code
        string publishercode = "";


        public ActionResult Index()
            {

            List<CourtSearchViewModel> model = new List<CourtSearchViewModel>();
            // lets initiailize our shopping cart ID First. This is tied to the session ID
            ViewBag.CorrelationId = subscribercode + "-" + Cart.GetCartId(this.HttpContext);

            // Lets add three records
            CourtSearchViewModel rec1 = new CourtSearchViewModel();
            rec1.ReferenceNo = "11111";
            rec1.Description = "First record";
            rec1.PageCount = "4";
            model.Add(rec1);

            CourtSearchViewModel rec2 = new CourtSearchViewModel();
            rec2.ReferenceNo = "22222";
            rec2.Description = "Second record";
            rec2.PageCount = "5";
            model.Add(rec2);

            CourtSearchViewModel rec3 = new CourtSearchViewModel();
            rec3.ReferenceNo = "33333";
            rec3.Description = "Third record";
            rec3.PageCount = "10";
            model.Add(rec3);

            return View(model);
            }

        public ActionResult DisplayCart()
            {
            // Lets initiatilize our shopping cart ID first. This is tied to the session ID so that it always changes
            ViewBag.CorrelationId = subscribercode + "-" + Cart.GetCartId(this.HttpContext);

            return View();
            }

        public string AddRecordToShoppingCart(string RefNo, string Description, string PageCount, string Quantity)
            {
            string succ = "True";
            try
                {
                ShoppingCart myCart = new ShoppingCart(Cart.GetCartId(this.HttpContext), testUrl, publishercode, subscribercode, token);
                var ret = myCart.AddORDocToShoppingCart(RefNo, Description, PageCount, "1");
                }
            catch(Exception ex)
                {
                succ = ex.Message;
                }
            return succ;
            }

        public string RemoveRecordFromShoppingCart(string RefNo, string Description, string PageCount, string Quantity)
            {
            string succ = "True";
            try
                {
                ShoppingCart myCart = new ShoppingCart(Cart.GetCartId(this.HttpContext), testUrl, publishercode, subscribercode, token);
                var ret = myCart.RemoveDocFromCart(RefNo, ClerkecertifyConnector.Model.DocumentTypeEnum.DocumentTypes.ORDOCTYPE);
                return ret;
                }
            catch (Exception ex)
                {
                succ = ex.Message;
                }
            return succ;
            }



        public ActionResult About()
            {
            ViewBag.Message = "Your application description page.";

            return View();
            }

        public ActionResult Contact()
            {
            ViewBag.Message = "Your contact page.";

            return View();
            }
        }
    }