public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                if (returnUrl == null)
                {
                    returnUrl = "~/Timesheet";
                }
                string userId = SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();
                //checking here for soft deletes
                var teacherService = new TeacherService(new HomeworkHotlineEntities());
                var teacher        = teacherService.GetById(userId);
                if (teacher == null)     //teacher is deleted
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    LogOff();
                    return(View(model));
                }
                TimeEntry openTimeEntry = TimeEntries.GetOpenTimeEntriesByUser(userId);
                if (openTimeEntry != null && openTimeEntry.EntryDate.Value.Date == DateTime.Today)   //user is still logged in for today, redirect to timesheets without logging in a second time.
                {
                    return(RedirectToLocal(returnUrl));
                }
                if (openTimeEntry != null && openTimeEntry.EntryDate.Value.Date < DateTime.Today)    //user is still logged in for yesterday, log out, back in and redirect to timesheets
                {
                    TimeEntries.ClockOutAtEndOfDay(userId, openTimeEntry);
                }
                TimeEntries.ClockIn(userId);
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }