public ActionResult Login(LoginViewModel model) { try { if (ModelState.IsValid) { DbfunctionUtility dbfunction = new DbfunctionUtility(_appSettings); DataSet ds = dbfunction.GetDataset("select * from users where username ='******' and Password ='******'"); if (ds.Tables[0].Rows.Count == 0) { ViewBag.ErrorMessage = "Incorrect username or password"; } else { CommanUtility commanUtility = new CommanUtility(_appSettings); var userMenus = commanUtility.GetUserMenus(Convert.ToString(ds.Tables[0].Rows[0]["RoleId"])); HttpContext.Session.SetString("UserMenus", JsonConvert.SerializeObject(userMenus)); HttpContext.Session.SetString("UserId", Convert.ToString(ds.Tables[0].Rows[0]["Userid"])); HttpContext.Session.SetString("RoleId", Convert.ToString(ds.Tables[0].Rows[0]["RoleId"])); HttpContext.Session.SetString("Username", model.Username); return(RedirectToAction("Dashboard", "Home")); } } } catch (Exception ex) { } return(View(model)); }
public ActionResult Login(LoginViewModel model) { try { if (ModelState.IsValid) { DbfunctionUtility dbfunction = new DbfunctionUtility(_appSettings); DataSet ds = dbfunction.GetDataset("select * from users join roles on users.roleid = roles.roleid where username ='******' and Password ='******'"); if (ds.Tables[0].Rows.Count == 0) { ViewBag.ErrorMessage = "Incorrect username or password"; } else { CommanUtility commanUtility = new CommanUtility(_appSettings); var userMenus = commanUtility.GetUserMenus(Convert.ToString(ds.Tables[0].Rows[0]["RoleId"])); HttpContext.Session.SetString("UserMenus", JsonConvert.SerializeObject(userMenus)); HttpContext.Session.SetString("UserId", Convert.ToString(ds.Tables[0].Rows[0]["Userid"])); HttpContext.Session.SetString("RoleName", Convert.ToString(ds.Tables[0].Rows[0]["RoleName"])); HttpContext.Session.SetString("HrGroupId", Convert.ToString(ds.Tables[0].Rows[0]["HrGroupId"])); HttpContext.Session.SetString("Username", model.Username); if (Convert.ToString(ds.Tables[0].Rows[0]["RoleName"]) != "CareGiver") { return(RedirectToAction("List", "CareGiver")); } else { var TestList = _dbContext.tbl_Tests.Where(w => w.SeasonId == 1).ToList(); var testCount = 0; foreach (var test in TestList) { var totalVideos = _dbContext.tbl_Testvideos.Count(); var watchedVideos = (from userVideo in _dbContext.tbl_AttendentTestVideos join testVideo in _dbContext.tbl_Testvideos on userVideo.VideoId equals testVideo.Id where userVideo.UserId == Convert.ToInt32(ds.Tables[0].Rows[0]["Userid"]) && testVideo.TestId == test.Id && userVideo.IsCompleted == true select testVideo.Id).Count(); if (totalVideos == watchedVideos) { testCount++; } } if (testCount > 0) { HttpContext.Session.SetString("ShowTest", "True"); return(RedirectToAction("Exam", "Attendant")); } else { HttpContext.Session.SetString("ShowTest", "False"); HttpContext.Session.SetString("Username", model.Username); return(RedirectToAction("Videos", "Test")); } } } } } catch (Exception ex) { } return(View(model)); }