public ActionResult Login(LogOnViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (authProvider.Authenticate(model.EmailAddress, model.Password, this.userRepository))
                {
                    var userObj = userRepository.GetUserByEmailAddress(model.EmailAddress);
                    Session["user"] = userObj;
                    var accountObj = accRepository.Accounts.FirstOrDefault(x => x.ID == userObj.AccountID);
                    Session["account"] = accountObj;
                    var timeZone = accRepository.Accounts.Where(aid => aid.ID == userObj.AccountID).FirstOrDefault().TimeZone;
                    Session["timeZone"] = timeZone;
                    Session["SysAdminDetails"] = null;

                    List<NotificationListViewModel> notificationList = new List<NotificationListViewModel>();

                    CronJobController CJC = new CronJobController();
                    Session["account"] = CJC.checkAccountTrialExpiryForAccount(accountObj);

                    //save details into error table
                    //SaveLogonDetails(model.EmailAddress);

                    if ( userObj.UserType == "Admin" || userObj.UserType == "Standard")
                    {
                        if (userObj.EmailVerified == true)
                        {
                            //get the folders
                            var folders = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList();
                            Session["folderss"] = folders;

                            HelperFunctions HF = new HelperFunctions();
                            notificationList = HF.generateNotificationList(accountObj);

                            HF.CheckAcccountStatus(accountObj);

                            if(notificationList.Count>0)
                                Session["notifications"] = notificationList;
                            else
                                Session["notifications"] = null;

                            return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
                        }
                        else
                        {
                            return Redirect(returnUrl ?? Url.Action("ResendVerification", "SignUp", new { uid = userObj.ID }));
                        }
                    }
                    else if (userObj.UserType == "SystemAdmin")
                    {
                        HelperFunctions HF = new HelperFunctions();
                        notificationList = HF.generateNotificationList(accountObj);
                        if (notificationList.Count > 0)
                            Session["notifications"] = notificationList;

                        Session["SysAdminDetails"] = userRepository.GetUserByEmailAddress(model.EmailAddress);

                        return Redirect(returnUrl ?? Url.Action("Index", "CorporateContactsAdmin"));
                    }
                    else
                    {
                        return Redirect(returnUrl ?? Url.Action("SetupSync", "User"));
                    }
                }
                else
                {
                    //save details into error table
                    //SaveLogonDetails(model.EmailAddress);
                    ModelState.AddModelError("", "Incorrect username or password");
                    return View();

                }
            }
            else
            {
                return View();
            }
        }
        public ActionResult Index(LogOnViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (authProvider.Authenticate(model.EmailAddress, model.Password, this.userRepository))
                {
                    var userObj = userRepository.GetUserByEmailAddress(model.EmailAddress);
                    Session["user"] = userObj;
                    var accountObj = accRepository.Accounts.FirstOrDefault(x => x.ID == userObj.AccountID);
                    Session["account"] = accountObj;
                    var timeZone = accRepository.Accounts.Where(aid => aid.ID == userObj.AccountID).FirstOrDefault().TimeZone;
                    Session["timeZone"] = timeZone;

                    //save details into error table
                    SaveLogonDetails(model.EmailAddress);

                    if (userObj.UserType == "Admin" || userObj.UserType == "Standard")
                    {
                        if (userObj.EmailVerified == true)
                        {
                            //get the folders
                            var folders = CCFolderRepository.CCFolders.Where(guid => guid.AccountGUID == accountObj.AccountGUID).ToList();
                            Session["folderss"] = folders;

                            return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
                        }
                        else
                        {
                            return Redirect(returnUrl ?? Url.Action("ResendVerification", "SignUp", new { uid = userObj.ID }));
                        }
                    }
                    else if (userObj.UserType == "SystemAdmin")
                    {
                        return Redirect(returnUrl ?? Url.Action("Index", "CorporateContactsAdmin"));
                    }
                    else
                    {
                        return Redirect(returnUrl ?? Url.Action("SetupSync", "User"));
                    }
                }
                else
                {
                    //save details into error table
                    SaveLogonDetails(model.EmailAddress);
                    ModelState.AddModelError("", "Incorrect username or password");
                    return View();

                }
            }
            else
            {
                return View();
            }
        }