public ACRF_UserDetailsModel EmployeeAuth(LoginModel objLogModel) { ACRF_UserDetailsModel objModel = new ACRF_UserDetailsModel(); try { string sqlstr = "select Id, EmployeeName, Email from ACRF_EmployeeDetails " + " where Email=@Email and Password=@Password"; var connection = gConnection.Connection(); connection.Open(); SqlCommand cmd = new SqlCommand(sqlstr, connection); cmd.Parameters.AddWithValue("@Email", objLogModel.UserName); cmd.Parameters.AddWithValue("@Password", Encryption.encrypt(objLogModel.Password)); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { objModel.email = sdr["Email"].ToString(); objModel.fullName = sdr["EmployeeName"].ToString(); objModel.id = Convert.ToInt32(sdr["Id"].ToString()); objModel.userType = UserType.VendorUser; } connection.Close(); } catch (Exception ex) { ErrorHandlerClass.LogError(ex); } return(objModel); }
public IHttpActionResult Login(LoginModel _objLogin) { string result = ""; if (ModelState.IsValid) { try { ACRF_UserDetailsModel ud = objAuthVM.UserAuth(_objLogin); if (ud.email != "") { string token = WriteCookie(ud.email, ud.fullName, UserType.AdminUser, ""); string res = objAuthVM.UpdateLastLogin(UserType.AdminUser, ud.id); ud.token = token; return(Ok(new { results = ud })); } else { ud = objAuthVM.VendorAuth(_objLogin); if (ud != null) { if (ud.email != "") { string token = WriteCookie(ud.email, ud.fullName, UserType.VendorUser, ""); string res = objAuthVM.UpdateLastLogin(UserType.VendorUser, ud.id); ud.token = token; //return Ok(new ResponseModel(RESPONSE_STATUS.SUCCESS, new LoginResponse(WriteCookie(ud.UserId, ud.UserType), ud.UserId), ud)); return(Ok(new { results = ud })); } else { ud.token = ""; //return Ok(new ResponseModel(RESPONSE_STATUS.AUTH_UNAUTHORIZED, new LoginResponse(), new ACRF_UserDetailsModel())); return(Ok(new { results = ud })); } } else { return(Ok(new ResponseModel(RESPONSE_STATUS.AUTH_UNAUTHORIZED, new LoginResponse(), new ACRF_UserDetailsModel()))); } } } catch (Exception ex) { result = ex.Message; } } else { result = "Enter Mandatory Fields"; } return(Ok(new { results = result })); }
public ACRF_UserDetailsModel VendorAuth(LoginModel objLogModel) { ACRF_UserDetailsModel objModel = new ACRF_UserDetailsModel(); objModel.email = ""; objModel.fullName = ""; try { string sqlstr = "select Id, VendorName, Email, isnull(ProfilePicture,'') as ProfilePicture from ACRF_VendorDetails " + " where Email=@Email and Password=@Password"; var connection = gConnection.Connection(); connection.Open(); SqlCommand cmd = new SqlCommand(sqlstr, connection); cmd.Parameters.AddWithValue("@Email", objLogModel.UserName); cmd.Parameters.AddWithValue("@Password", Encryption.encrypt(objLogModel.Password)); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { objModel.email = sdr["Email"].ToString(); objModel.fullName = sdr["VendorName"].ToString(); objModel.id = Convert.ToInt32(sdr["Id"].ToString()); objModel.userType = UserType.VendorUserShort; objModel.profileimage = sdr["ProfilePicture"].ToString(); if (sdr["ProfilePicture"].ToString() == "") { objModel.profileimage = ""; } else { objModel.profileimage = GlobalFunction.GetAPIUrl() + objModel.profileimage; } } connection.Close(); } catch (Exception ex) { ErrorHandlerClass.LogError(ex); } return(objModel); }
public ACRF_UserDetailsModel AdminAuth(AuthModel objAuthModel) { ACRF_UserDetailsModel objModel = new ACRF_UserDetailsModel(); try { string sqlstr = "select Email, AdminName, Id, isnull(ProfilePicture,'') as ProfilePicture from ACRF_AdminDetails " + " where Email=@Email "; var connection = gConnection.Connection(); connection.Open(); SqlCommand cmd = new SqlCommand(sqlstr, connection); cmd.Parameters.AddWithValue("@Email", objAuthModel.UserName); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { objModel.email = sdr["Email"].ToString(); objModel.fullName = sdr["AdminName"].ToString(); objModel.id = Convert.ToInt32(sdr["Id"].ToString()); objModel.userType = UserType.AdminUser; objModel.profileimage = sdr["ProfilePicture"].ToString(); if (sdr["ProfilePicture"] == "") { objModel.profileimage = ""; } else { objModel.profileimage = GlobalFunction.GetAPIUrl() + objModel.profileimage; } } connection.Close(); } catch (Exception ex) { ErrorHandlerClass.LogError(ex); } return(objModel); }