using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
using Repositories;
using MvcApplication1.ViewModelBuilders;

namespace MvcApplication1.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult RegisterOrganization()
        {
            RegisterOrganizationViewModel viewModel = RegisterOrganizationViewModelBuilder.Build();
            return View(viewModel);
        }


        //[HttpPost]
        ////[PopulateOrganizationCategories]
        //public ActionResult RegisterOrganization([Bind(Exclude = "ID")] Organization organization)
        //{
        //    //model.OrganizationEditable.OrganizationcategoryId = model.OrganizationCategory.ID;
        //    //ModelState.Remove("OrganizationcategoryId");

        //    if (ModelState.IsValid)
        //    {
        //        //Organization organization = (Organization)model.OrganizationEditable;
        //        //organization.OrganizationcategoryId = model.OrganizationCategory.ID;
        //        //OrganizationRepository.Register(organization);
        //        return RedirectToAction("Index", "Home");
        //    }
        //    else
        //    {
        //        return View();
        //    }
        //}

        public ActionResult MyOrganizationProfile()
        {
            //Guid userId = (Guid)System.Web.HttpContext.Current.Session["session_UserId"];
            Guid userId = Guid.NewGuid();
            OrganizationNavigationViewModel model = new OrganizationNavigationViewModel
            {
                OrganizationNavigationData = OrganizationNavigationDataBuilder.BuildOrganizationNavigationData(OrganizationUsersRepository.GetOrganizationsAdmined(userId, 1, 10), "MyOrganizationProfilePartial")
            };
            return View(model);
        }
        //[PopulateOrganizationCategories]
        public ActionResult MyOrganizationProfilePartial(string OrganizationId)
        {
            //OrganizationProfileViewModel model = MyOrganizationProfilePartialViewModelBuilder.Build(OrganizationId);
            Address add=new Address {
             City ="XXX",
             Country ="UK",
             ID =Guid.NewGuid(),
             Street ="XXXx",
            Zip ="123456"};
            OrganizationProfileViewModel model = new OrganizationProfileViewModel()
            {
                Address = add,
                Name = "XYZ.com",
                Phonenumber = "0017027367898"
            };
            List<OrganizationCategory> OrganizationCategoryList = new List<OrganizationCategory>();

            OrganizationCategory category1 = new OrganizationCategory
            {
                ID = Guid.NewGuid(),
                Name = "Company",
                Description = "Company",
                Isvalid = true
            };
            OrganizationCategory category2 = new OrganizationCategory
            {
                ID = Guid.NewGuid(),
                Name = "Unit",
                Description = "Unit",
                Isvalid = true
            };

            OrganizationCategoryList.Add(category1);
            OrganizationCategoryList.Add(category2);



            model.OrganizationCategory = OrganizationCategoryList.Select(s => new SelectListItem() { Text = s.Name, Value = s.ID.ToString(), Selected = (s.Name == "Company") }).AsEnumerable();

            return PartialView(model);

        }


        public ActionResult MyOrganizationUserInRole()
        {
            //Guid userId = (Guid)System.Web.HttpContext.Current.Session["session_UserId"];
            Guid userId = Guid.NewGuid();
            OrganizationNavigationViewModel model = new OrganizationNavigationViewModel
            {
                OrganizationNavigationData = OrganizationNavigationDataBuilder.BuildOrganizationNavigationData(OrganizationUsersRepository.GetOrganizationsAdmined(userId, 1, 10), "MyOrganizationUserInRolePartial")
            };
            return View(model);
        }

        public ActionResult MyOrganizationUserInRolePartial(string OrganizationId)
        {
            Guid myOrganizationId = new Guid(OrganizationId);
            OrganizationUsersPartialViewModel model = new OrganizationUsersPartialViewModel
            {
                OrganizationUsers = OrganizationUsersRepository.GetOrganizationAdministrators(myOrganizationId, 1, 10)
            };
            return PartialView(model);
        }

    }
}
