I am implementing below example link code in 3 tier and get
-6
down vote
favorite
I am implementing below example link code in 3 tier and getting error mail failer, i know 3 tier logic confusing me.
http://www.webcodeexpert.com/2013/08/how-to-recover-and-reset-forgotlost.html
This is a table design:
CREATE TABLE [dbo].[Tbl_Login](
[id] [int] IDENTITY(1,1) NOT NULL,
[UserName] [varchar](100) NULL,
[EmailId] [varchar](100) NULL,
[Pwd] [varchar](50) NULL,
[UniqueCode] [varchar](50) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF GO
Send link to gmail procedures:
create procedure [dbo].[Get_ForgotPassword]
(
@Userid varchar(100)
)
as
begin
select * from Tbl_Login where Emailid=@Userid
end
create procedure [dbo].[Update_ForgotPassword]
(
@Userid varchar(100),
@uniqueCode varchar(100)
)
as
begin
update Tbl_Login set UniqueCode=@UniqueCode where EmailId=@Userid
end
This for reset password procedures
create procedure Get_ResetPassword
(
@Userid varchar(300),
@UniqueCode varchar(100)
)
as
begin
select Email,UniqueCode from Tbl_Login where UniqueCode=@UniqueCode and Email=@Userid
end
create procedure Update_ResetPassword (
@Userid varchar(300),
@Password varchar(50),
@UniqueCode varchar(100) )
as
begin
update Tbl_Login set UniqueCode='',Password=@Password where
UniqueCode=@UniqueCode and Email=@Userid
end
using 3 tier architecture
BusinessObject.cs
DataLogicLayer.cs
BusinessLogic.cs
1.BusinessObject.cs
private string Parameter1;
private string Parameter2;
private string Parameter3;
public string Para1
{
set
{
Parameter1 = value;
}
get
{
return Parameter1;
}
}
public string Para2
{
set
{
Parameter2 = value;
}
get
{
return Parameter2;
}
}
public string Para3
{
set
{
Parameter3 = value;
}
get
{
return Parameter3;
}
}
2.DataLogicLayer.cs
//send link to gmail
public int Get_ForgotPassword(BusinessObject bo)
{
int n = 0;
ConnectMethod();
cmd = new SqlCommand("Get_ForgotPassword", con);
try
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Userid", bo.Para1);
n = Convert.ToInt32(cmd.ExecuteNonQuery());
return n;
}
catch (Exception ex)
{
return n;
}
finally
{
con.Close();
con.Dispose();
cmd.Dispose();
}
}
public int Update_ForgotPassword(BusinessObject bo)
{
int n = 0;
ConnectMethod();
cmd = new SqlCommand("Update_ForgotPassword", con);
try
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Userid", bo.Para1);
cmd.Parameters.AddWithValue("@UniqueCode", bo.Para3);
n = cmd.ExecuteNonQuery();
return n;
}
catch (Exception ex) {
return n;
} finally
{
con.Close();
con.Dispose();
cmd.Dispose();
}
}
//update reset password
public int Get_ResetPassword(BusinessObject bo)
{
int n = 0;
ConnectMethod();
cmd = new SqlCommand(Get_ResetPassword", con);
try
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Userid", bo.Para1);
cmd.Parameters.AddWithValue("@UniqueCode", bo.Para3);
n = Convert.ToInt32(cmd.ExecuteNonQuery());
return n;
}
catch (Exception ex) {
return n;
} finally
{
con.Close();
con.Dispose();
cmd.Dispose();
}
}
public int Update_ResetPassword(BusinessObject bo) {
int n = 0;
ConnectMethod();
cmd = new SqlCommand(Update_ResetPassword", con);
try {
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Parameters.AddWithValue("@Userid", bo.Para1);
cmd.Parameters.AddWithValue("@Password", bo.Para2);
cmd.Parameters.AddWithValue("@UniqueCode", bo.Para3);
n = cmd.ExecuteNonQuery();
return n;
}
catch (Exception ex) {
return n;
} finally { con.Close();
con.Dispose();
cmd.Dispose(); }
}
3.BusinessLogic.cs
public int Get_ForgotPassword(BusinessObject bo) {
return data.Get_ForgotPassword(bo);
}
public void Update_ForgotPassword(BusinessObject bo)
{
if (data.Get_ForgotPassword(bo) == -1) //it is returning -1 values i dont know
{
bo.Para3 = Convert.ToString(System.Guid.NewGuid());
StringBuilder strBody = new StringBuilder();
MailAddress from = new MailAddress(System.Configuration.ConfigurationManager.AppSettings["AdminFromEmailAddress"].ToString());
MailAddress to = new MailAddress(bo.Para1);
MailMessage message = new MailMessage(from, to);
message.IsBodyHtml = true;
strBody.Append("http://localhost:2464/SampleApplication/ResetPassword.aspx?emailId=" + bo.Para1 + "&uCode=" + bo.Para3 + ">Click here to change your password");
SmtpClient client1 = new SmtpClient(System.Configuration.ConfigurationManager.AppSettings["SmtpClientclientPath"].ToString());
client1.Port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientclientPathPort"].ToString());
client1.Send(message);
}
PasswordForgot.aspx
bo.Para1 = txt_Email.Text;
bl.Update_ForgotPassword(bo);
And also need how to write the logic 3 tier for reset forget page..