public ActionResult SubmitLogin(LoginViewModel loginObj) { try { var db = new DatabaseController(); if (db.DbNotExists()) { db.CreateDatabase(); } if (db.DbIsNotRequiredVersion()) { db.UpdateDatabase(); } if (Context.Users.ToList().Count() == 0) { throw new FirstAccessException("No users in DataBase, please register."); } var userObj = Context.Users.Where(i => i.Username == loginObj.Username).FirstOrDefault(); if (LoginIsOk(loginObj, userObj)) { if (LastYearIsNotThisYear(userObj.Id)) { InsertMonths(userObj); } WebHelpers.SetSession(userObj); return(Redirect("/Home/Home")); } else { throw new Exception("Wrong password"); } } catch (Exception ex) { ViewBag.Message = ex.Message; ViewBag.IsFirstAccess = ex is FirstAccessException; return(View("Login")); } }