/// <summary> /// This is login method and it will connect to DB and check if user is exists or not. If user exists then it will display the user detail /// </summary> /// <param name="userLogin"></param> /// <returns></returns> public MDTTransactionInfo Login(UserLogin userLogin) { MDTTransactionInfo mdt = null; try { UserLoginDetails loginDetails = null; List <SqlParameter> prm = new List <SqlParameter>(); //SqlParameter email = new SqlParameter("@email", userLogin.UserName); //prm.Add(email); //SqlParameter pwd = new SqlParameter("@pwd", userLogin.Password); //prm.Add(pwd); //SqlParameter status = new SqlParameter("@Status", 0); //status.Direction = ParameterDirection.Output; //prm.Add(status); prm = DatabaseSettings.BindParamers(APIHelper.getLoginDetailsParameters, userLogin.UserName + "~||~" + userLogin.Password); int StatusValue = 0; DataSet ds = DatabaseSettings.GetDataSet(APIHelper.getLoginDetails, out StatusValue, prm); DataTable dt; if (StatusValue == 1) { dt = ds.Tables[0]; mdt = new MDTTransactionInfo(); if (dt.Rows.Count > 0) { loginDetails = new UserLoginDetails(); loginDetails.USER_ID = Convert.ToInt32(dt.Rows[0]["USER_ID"]); loginDetails.FIRST_NAME = dt.Rows[0]["FIRST_NAME"].ToString(); loginDetails.LAST_NAME = dt.Rows[0]["LAST_NAME"].ToString(); loginDetails.EMAIL_ADDRESS = dt.Rows[0]["EMAIL_ADDRESS"].ToString(); loginDetails.FORCE_PWD_CHNG = Convert.ToBoolean(dt.Rows[0]["FORCE_PWD_CHNG"]); loginDetails.PHOTO = dt.Rows[0]["PHOTO"].ToString(); loginDetails.ROLE_NAME = dt.Rows[0]["ROLE_NAME"].ToString(); loginDetails.ROLE_ID = Convert.ToInt32(dt.Rows[0]["ROLE_ID"]); loginDetails.UserKey = SecurityEncryptDecrypt.Encrypt(dt.Rows[0]["EMAIL_ADDRESS"].ToString()); loginDetails.UserValue = SecurityEncryptDecrypt.Encrypt(dt.Rows[0]["PASSWORD"].ToString()); mdt.status = HttpStatusCode.OK; mdt.transactionObject = loginDetails; mdt.msgCode = MessageCode.Success; mdt.message = "Login Successfully"; } else { mdt.msgCode = MessageCode.Failed; mdt.status = HttpStatusCode.NoContent; mdt.message = "No record found"; } } else if (StatusValue == 5 || StatusValue == 6) { mdt = DatabaseSettings.GetTransObject(null, StatusValue, "", ds); } } catch (Exception ex) { mdt.status = HttpStatusCode.ExpectationFailed; mdt.msgCode = MessageCode.TechnicalError; mdt.message = "Technical Error in the system, please contact to administrator"; } return(mdt); }
/// <summary> /// This is login method and it will connect to DB and check if user is exists or not. If user exists then it will display the user detail /// </summary> /// <param name="userLogin"></param> /// <returns></returns> public MDTTransactionInfo Login(UserLogin userLogin) { MDTTransactionInfo mdt = null; UserLoginDetails loginDetails = null; List <SqlParameter> prm = new List <SqlParameter>(); SqlParameter email = new SqlParameter("@email", userLogin.UserName); prm.Add(email); SqlParameter pwd = new SqlParameter("@pwd", userLogin.Password); prm.Add(pwd); SqlParameter status = new SqlParameter("@Status", 0); status.Direction = ParameterDirection.Output; prm.Add(status); int StatusValue = 0; DataSet ds = DatabaseSettings.GetDataSet(APIHelper.getLoginDetails, out StatusValue, prm); DataTable dt; if (StatusValue == 1) { dt = ds.Tables[0]; mdt = new MDTTransactionInfo(); if (dt.Rows.Count > 0) { loginDetails = new UserLoginDetails(); loginDetails.USER_ID = Convert.ToInt32(dt.Rows[0]["USER_ID"]); loginDetails.FIRST_NAME = dt.Rows[0]["FIRST_NAME"].ToString(); loginDetails.LAST_NAME = dt.Rows[0]["LAST_NAME"].ToString(); loginDetails.EMAIL_ADDRESS = dt.Rows[0]["EMAIL_ADDRESS"].ToString(); loginDetails.FORCE_PWD_CHNG = Convert.ToBoolean(dt.Rows[0]["FORCE_PWD_CHNG"]); loginDetails.PHOTO = dt.Rows[0]["PHOTO"].ToString(); loginDetails.ROLE_NAME = dt.Rows[0]["ROLE_NAME"].ToString(); loginDetails.ROLE_ID = Convert.ToInt32(dt.Rows[0]["ROLE_ID"]); loginDetails.UserKey = SecurityEncryptDecrypt.Encrypt(dt.Rows[0]["EMAIL_ADDRESS"].ToString()); loginDetails.UserValue = SecurityEncryptDecrypt.Encrypt(dt.Rows[0]["PASSWORD"].ToString()); } mdt.status = HttpStatusCode.OK; mdt.transactionObject = loginDetails; mdt.msgCode = MessageCode.Success; mdt.message = "Login Successfully"; } else if (StatusValue == 5 || StatusValue == 6) { mdt = DatabaseSettings.GetTransObject(null, StatusValue, "", ds); //ErrorInfoFromSQL eInfo = null; //if (dt.Rows.Count > 0) //{ // eInfo = new ErrorInfoFromSQL(); // eInfo = DatabaseSettings.GetError(dt); // mdt.status = HttpStatusCode.BadRequest; // mdt.transactionObject = eInfo; // mdt.msgCode = (eInfo.Status == 1) ? MessageCode.Success : (eInfo.Status == 6) ? MessageCode.TechnicalError : MessageCode.Failed; // mdt.message = eInfo.ErrorMessage; // mdt.LineNumber = eInfo.ErrorLineNo; // mdt.ProcedureName = eInfo.Procedure; //} } return(mdt); }