public ActionResult Login() { var cookieEmail = Utility.Utility.ReadCookie("HotelierHubUserEmail"); try { if (cookieEmail != null) { var result = LogInManager.LoginWithCookie(cookieEmail); switch (result) { case LoginStatus.Success: if (LogInManager.HasRights("STUDENT")) { //Create Dummy Reservation. TempReservation.CreateDummyReservation(); } var trackActivityStatus = RecordActivityLog.TrackUsersActivityByUserId(LogInManager.LoggedInUser.Id); if (trackActivityStatus == TrackActivityStatus.Success) { return(RedirectToAction("Index", "Home")); } else { //Remove Cookie Utility.Utility.RemoveCookie("HotelierHubUserEmail"); return(RedirectToAction("Login", "Account")); } case LoginStatus.Failure: default: //Remove Cookie Utility.Utility.RemoveCookie("HotelierHubUserEmail"); //Abandon current sessions. System.Web.HttpContext.Current.Session.Abandon(); return(RedirectToAction("Login", "Account")); } } } catch (Exception e) { Utility.Utility.LogError(e, "Login"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } return(View()); }
public ActionResult SearchIndividualProfile(SearchIndividualProfileParametersVM model) { try { object sortColumn = ""; object sortDirection = ""; if (model.order.Count == 0) { sortColumn = "CreatedOn"; sortDirection = "desc"; } else { sortColumn = model.columns[Convert.ToInt32(model.order[0].column)].data ?? (object)DBNull.Value; sortDirection = model.order[0].dir ?? (object)DBNull.Value; } model.PageSize = Constants.PAGESIZE; model.CreatedBy = LogInManager.LoggedInUserId; model.IsAdminUser = LogInManager.HasRights("ADMIN"); var profiles = profileRepository.SearchIndividualProfile(model, Convert.ToString(sortColumn), Convert.ToString(sortDirection)); int totalRecords = 0; var dbRecords = profiles.Select(m => m.TotalCount).FirstOrDefault(); if (dbRecords != 0) { totalRecords = Convert.ToInt32(dbRecords); } #region Record Activity Log RecordActivityLog.RecordActivity(Pages.INDIVIDUAL_PROFILE, "Searched profile."); #endregion return(Json(new { IsSuccess = true, CurrentPage = model.PageNum, PageSize = Constants.PAGESIZE, TotalRecords = totalRecords, data = profiles }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Utility.Utility.LogError(e, "SearchIndividualProfile"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }
public ActionResult SearchAdvanceProfile(SearchAdvanceProfileParametersVM model) { try { model.CreatedBy = LogInManager.LoggedInUserId; model.IsAdminUser = LogInManager.HasRights("ADMIN"); var profiles = profileRepository.SearchAdvanceProfile(model); return(Json(new { IsSuccess = true, data = profiles }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Utility.Utility.LogError(e, "SearchAdvanceProfile"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }
public ActionResult Login(LoginViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var result = LogInManager.Login(model.Email, Utility.Utility.Encrypt(model.Password, Utility.Utility.EncryptionKey)); switch (result) { case LoginStatus.Success: RecordActivityLog.RecordActivity(Pages.LOGIN, "Loggedin successfully."); if (LogInManager.HasRights("STUDENT")) { //Create Dummy Reservation. TempReservation.CreateDummyReservation(); } if (model.RememberMe) { // Create a new cookie, Utility.Utility.WriteCookie("HotelierHubUserEmail", model.Email, 24); //24 Hours expiration time. } return(Json(new { IsSuccess = true, data = new { UserId = LogInManager.LoggedInUserId } }, JsonRequestBehavior.AllowGet)); case LoginStatus.AlreadyLoggedIn: return(Json(new { IsSuccess = false, errorMessage = "User already logged in!" }, JsonRequestBehavior.AllowGet)); case LoginStatus.InvalidLoginTime: var msg = "Please note your course is restricted; therefore, you can only access it during the times & day set by your Tutor."; return(Json(new { IsSuccess = false, errorMessage = msg }, JsonRequestBehavior.AllowGet)); case LoginStatus.Failure: default: RecordActivityLog.RecordActivity(Pages.LOGIN, "Login fail."); return(Json(new { IsSuccess = false, errorMessage = "Invalid Email and Password." }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { Utility.Utility.LogError(e, "Login POST"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }
public ActionResult LoggedInUserInfo(SearchLoggedInUserInfoParametersVM model) { try { object sortColumn = ""; object sortDirection = ""; if (model.order.Count == 0) { sortColumn = "LastLoggedOn"; sortDirection = "desc"; } else { sortColumn = model.columns[Convert.ToInt32(model.order[0].column)].data ?? (object)DBNull.Value; sortDirection = model.order[0].dir ?? (object)DBNull.Value; } model.PageSize = Constants.PAGESIZE; if (LogInManager.HasRights("TUTOR")) { model.TutorId = LogInManager.LoggedInUser.Id; var userRoles = userRoleRepository.GetUserRoles(); var studentRoleId = userRoles.Where(m => m.Code == "STUDENT").FirstOrDefault().Id; model.UserRoleId = studentRoleId; } var users = userRepository.SearchLoggedInUserInfo(model, Convert.ToString(sortColumn), Convert.ToString(sortDirection)); int totalRecords = 0; var dbRecords = users.Select(m => m.TotalCount).FirstOrDefault(); if (dbRecords != 0) { totalRecords = Convert.ToInt32(dbRecords); } //Get Total Users (student) var loggedInUsers = userRepository.GetLoggedInUserInfo(model); int totalUsers = 0; var dbTotalUsers = loggedInUsers.Count; if (dbTotalUsers != 0) { totalUsers = Convert.ToInt32(dbTotalUsers); } return(Json(new { IsSuccess = true, CurrentPage = model.PageNum, PageSize = Constants.PAGESIZE, TotalRecords = totalRecords, TotalUsers = totalUsers, data = users }, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Utility.Utility.LogError(e, "LoggedInUserInfo"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }