
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace Test
{
    public class TenantController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult Add(List<dtoBaseTenant> models)
        {
            return Json(models[0], JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult Update(List<dtoBaseTenant> models)
        {
            //Save tenant to DB
            return Json(models[0], JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult Delete(List<dtoBaseTenant> models)
        {
            return TenantList();
        }

        [ValidateAntiForgeryToken]
        public JsonResult TenantList()
        {
            List<dtoBaseTenant> list = new List<dtoBaseTenant>();
            Guid productID = Guid.NewGuid();
            dtoBaseTenant t = new dtoBaseTenant
            {
                ActivationCode = Guid.NewGuid(), 
                ActivationStatus = 0, 
                BillingAccountNumber = "Bill 1234", 
                Cnt = 0, 
                Created = DateTime.Now,
                CustomerName = "Cust 1234",
                InvitationEmail = "Robert.Manookian@Sage.com",
                LastModified = DateTime.Now,
                ProductID = productID,
                ProductName = "Product",
                ProductUserID = Guid.Empty,
                ProductVersion = DateTime.Now,
                SageCustomerID = Guid.Empty,
                SageCustomerNumber = "Sage 1234",
                TenantCode = "Code",
                TenantID = Guid.NewGuid(),
                TenantName = "Tenant Name",
                TenantStatus = 0,
                TenantStatusText = "Created",
                UsageType = 0,
            };
            t.Apps.Add(new dtoBaseTenantApp() { AppID = Guid.NewGuid(), AppName = "App 1", Cnt = 0, Created = DateTime.Now, Description = "App 1", IsBase = true, LastModified = DateTime.Now, ProductID = productID, ProvisionURL = null });
            t.Apps.Add(new dtoBaseTenantApp() { AppID = Guid.NewGuid(), AppName = "App 2", Cnt = 0, Created = DateTime.Now, Description = "App 2", IsBase = true, LastModified = DateTime.Now, ProductID = productID, ProvisionURL = null });
            t.Apps.Add(new dtoBaseTenantApp() { AppID = Guid.NewGuid(), AppName = "App 3", Cnt = 0, Created = DateTime.Now, Description = "App 3", IsBase = true, LastModified = DateTime.Now, ProductID = productID, ProvisionURL = null });
            list.Add(t);
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        public JsonResult AppList(Guid ProductID)
        {
            List<dtoBaseTenantApp> list = new List<dtoBaseTenantApp>();
            list.Add(new dtoBaseTenantApp() { AppID = Guid.NewGuid(), AppName = "App 1", Cnt = 0, Created = DateTime.Now, Description = "App 1", IsBase = true, LastModified = DateTime.Now, ProductID = ProductID, ProvisionURL = null });
            list.Add(new dtoBaseTenantApp() { AppID = Guid.NewGuid(), AppName = "App 2", Cnt = 0, Created = DateTime.Now, Description = "App 2", IsBase = true, LastModified = DateTime.Now, ProductID = ProductID, ProvisionURL = null });
            list.Add(new dtoBaseTenantApp() { AppID = Guid.NewGuid(), AppName = "App 3", Cnt = 0, Created = DateTime.Now, Description = "App 3", IsBase = true, LastModified = DateTime.Now, ProductID = ProductID, ProvisionURL = null });
            return Json(list, JsonRequestBehavior.AllowGet);
        }

        public JsonResult AppListUpdate(List<dtoBaseTenantApp> models)
        {
            return Json(models, JsonRequestBehavior.AllowGet);
        }
        

        public JsonResult KeyChangeList(string SageCust)
        {
            return TenantList();
        }

        public JsonResult AutoCompleteSageCustomerList(string SageCust)
        {
            return Json(TenantList(), JsonRequestBehavior.AllowGet);
        }
    }
}
