//
        // GET: /Default/
        public ActionResult Index()
        {
            if (Request.Cookies["KardoLanguagePreference"] == null || Request.Cookies["KardoLanguagePreference"].Value == "" || Request.Cookies["KardoLanguagePreference"].Value == "null")
            {
                Session.Add("KardoLanguagePreference", "tr-TR");
                if (Request.Cookies["KardoLanguagePreference"] != null)
                {
                    Response.Cookies["KardoLanguagePreference"].Value   = "tr-TR";
                    Response.Cookies["KardoLanguagePreference"].Expires = DateTime.Now.AddYears(99);
                }
            }
            if ((Session["KardoUserId"] == null && Session["KardoUserName"] == null))
            {
                if (Request.Cookies["KardoUserInfos"] != null)
                {
                    if (Request.Cookies["KardoUserInfos"]["userId"] != null && Request.Cookies["KardoUserInfos"]["status"] != null)
                    {
                        string[] savedAccounts = Request.Cookies["KardoUserInfos"]["userId"].Split('_');
                        string[] status        = Request.Cookies["KardoUserInfos"]["status"].Split('_');
                        //string[] priority = Request.Cookies["KardoUserInfos"]["priority"].Split('_');
                        if (savedAccounts.Length == status.Length)
                        {
                            string tempUserId = null;
                            for (int i = 0; i < savedAccounts.Length; i++)
                            {
                                if (status[i] == "active")
                                {
                                    tempUserId = savedAccounts[i];
                                    break;
                                }
                            }

                            if (tempUserId != null)
                            {
                                /*KardoModel kardoModel = new KardoModel("kardo");
                                 * kardoModel.selectOnlyFirstData("users", "*");
                                 * kardoModel.addInnerJoin("users", "profils", "userId");*/
                                string tempStr = UseKardoEncryption.getDecipherString(Request.Cookies["KardoUserInfos"]["userId"]);
                                if (tempStr == "KardoEncryptionError")
                                {
                                    Response.Cookies["KardoUserInfos"].Expires = DateTime.Now.AddDays(-1);
                                    Response.Redirect("/Default/Index");
                                }
                                else
                                {
                                    int userId = Convert.ToInt32(tempStr);
                                    Dictionary <string, Object> theUser = DefaultModel.getUserFromUserId(userId);
                                    string userName = (string)theUser["username"];

                                    Session.Add("KardoUserId", Request.Cookies["KardoUserInfos"]["userId"]);
                                    Session.Add("KardoUserName", UseKardoEncryption.getEncryptedString(userName, 50));
                                    Session.Add("KardoLanguagePreference", (string)theUser["languagePreference"]);

                                    ViewBag.userInfos = theUser;
                                }
                            }
                        }
                        else
                        {
                            Response.Cookies["KardoUserInfos"].Expires = DateTime.Now.AddDays(-1);
                        }
                    }
                    else
                    {
                        Response.Cookies["KardoUserInfos"].Expires = DateTime.Now.AddDays(-1);
                    }
                }

                /*else if (Request.Cookies["KardoVisitorInfos"] != null && (Session["KardoVisitorId"] == null && Session["KardoVisitorName"] == null))
                 * {
                 *  KardoModel kardoModel = new KardoModel("kardo");
                 *  kardoModel.selectOnlyFirstData("visitors", "*");
                 *  string tempStr = UseKardoEncryption.getDecipherString(Request.Cookies["KardoVisitorInfos"]["visitorId"]);
                 *  if (tempStr == "KardoEncryptionError")
                 *  {
                 *      Response.Cookies["KardoVisitorInfos"].Expires = DateTime.Now.AddDays(-1);
                 *      Response.Redirect("/Kardo/Index");
                 *  }
                 *  else
                 *  {
                 *      kardoModel.addWhere("visitorId", Convert.ToInt32(tempStr));
                 *      ArrayList results = kardoModel.selectResults();
                 *      kardoModel.close();
                 *
                 *      string visitorName = KardoModel.getFirstValueFromColumnName(results, "visitorName");
                 *
                 *      Session.Add("KardoVisitorId", Request.Cookies["KardoVisitorInfos"]["visitorId"]);
                 *      Session.Add("KardoVisitorName", visitorName);
                 *      Session.Add("KardoLanguagePreference", Request.Cookies["KardoLanguagePreference"].Value);
                 *  }
                 * }*/
                else
                {
                    // will be creat new visitor // first visit or cookieEnabled is false
                }
            }
            else if ((Session["KardoUserId"] != null && Session["KardoUserName"] != null))
            {
                int userId = Convert.ToInt32(UseKardoEncryption.getDecipherString(Session["KardoUserId"].ToString()));
                Dictionary <string, Object> theUser = DefaultModel.getUserFromUserId(userId);

                ViewBag.userInfos = theUser;
            }

            //****************************************************

            Dictionary <string, List <Object> > events = DefaultModel.getEvents();

            ViewBag.Events = events;
            Dictionary <string, List <Object> > eventsCities = DefaultModel.getEventsCities();

            ViewBag.EventsCities = eventsCities;
            Dictionary <string, List <Object> > eventsTeams = DefaultModel.getEventsTeams();

            ViewBag.EventsTeams = eventsTeams;


            return(View());
        }