public AdminLoginResponse Login(string username, string password) { try { IAdminRepository adminRepository = RepositoryClassFactory.GetInstance().GetAdminRepository(); Admin _admin = adminRepository.FindByUserName(username); if (_admin != null) { if (_admin.Locked) { return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_account_locked }); } } Admin admin = adminRepository.Login(username, password); if (admin != null) { IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository(); //Delete session id existed try { userSessionRepository.DeleteByUserID(admin.AdminID); } catch (Exception) { } int timeOut = TIME_OUT_MINUTES * 60 * 1000; UserSession userSession = new UserSession { CreatedDate = DateTime.Now, UserID = admin.AdminID, SessionID = Guid.NewGuid().ToString(), UpdatedDate = DateTime.Now }; object sessionID = userSessionRepository.Insert(userSession); return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.None, Message = "", SessionId = userSession.SessionID, AdminId = admin.AdminID, AdminName = admin.LastName }); } else { return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_login_fail }); } } catch (Exception ex) { return(new AdminLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }
public UserLoginResponse Login(string username, string password) { try { IUserRepository userRepository = RepositoryClassFactory.GetInstance().GetUserRepository(); User _user = userRepository.FindByUserName(username); if (_user != null) { if (_user.Locked) { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_account_locked }); } } IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository(); User user = userRepository.Login(username, password); if (user != null) { try { userSessionRepository.DeleteByUserID(user.UserID); } catch (Exception) { } int timeOut = TIME_OUT_MINUTES * 60 * 1000; UserSession userSession = new UserSession { CreatedDate = DateTime.Now, UserID = user.UserID, SessionID = Guid.NewGuid().ToString(), UpdatedDate = DateTime.Now }; object sessionID = userSessionRepository.Insert(userSession); return(new UserLoginResponse { ErrorCode = (int)ErrorCode.None, Message = string.Empty, SessionId = userSession.SessionID, UserId = user.UserID, UserName = user.UserName }); } else { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = Resources.Resource.msg_login_fail }); } } catch (Exception ex) { return(new UserLoginResponse { ErrorCode = (int)ErrorCode.Error, Message = ex.Message }); } }