Hai,
This is my task
Example:when we upload our resume to naukri.com we get mails some companys regarding job openings
so at the bottom we see a link if you want to unscribe please click the link button
so actually this is my task when customer doesnt want to receive mails from our product if he wants to unscribe when he clicks the link button he has to unsubscribe from our website
plz help me what logic i have to write which services i have to use plz help me
Thanks,
Karthik
Loading

Zoran HorvatRank #792 · 2.9K reputationPosted Jul 26, 2011, 1:36 AM EDT
Now whenever your customer subscribes to mailing list, you update his customer record in your database and store Token there. Token should be a relatively long string which is randomly generated and unique.
Unsubscribing page then finds customer with Token found in URL and updates his customer record in the dabase to set Token to NULL.
With this solution, only those customers having non-NULL Token field are actually subscribed to the mailing list. All that have NULL value are not subscribed.
Zoran
karthik parcha150 reputationPosted Jul 26, 2011, 1:44 AM EDT
What you said i understand
But How to write code for this Token should be a relatively long string which is randomly generated and unique
If you know can u write code for me
If you have any example application or just sample overview regarding this task will you post for me
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 26, 2011, 2:00 AM EDT
Function which generates token can look like this:
private string GenerateToken(int length)
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
string ts = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
for (int i = 0; i < ts.Length; i++)
sb.Append((char)(ts[i] - '0' + 'A'));
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
return sb.ToString();
}
private string GenerateToken()
{
return GenerateToken(40);
}
You can use GenerateToken() function and that will generate 40 characters long tokens. First part of the token is created from current timestamp which guarantees uniqueness.
Now suppose that you have a customers table like this:
CREATE TABLE Customer(
CustomerID INT PRIMARY KEY IDENTITY(1, 1),
UserName VARCHAR(100),
MailingListToken CHAR(40)
);
In this case, you can create Subscribe and Unsubscribe stored procedures:
CREATE PROCEDURE Subscribe
@CustomerID INT,
@Token CHAR(40)
AS
BEGIN
UPDATE Customer SET MailingListToken=@Token WHERE CustomerID=@CustomerID
END
GO
CREATE PROCEDURE Unsubscribe
@Token CHAR(40)
AS
BEGIN
UPDATE Customer SET MailingListToken=NULL WHERE MailingListToken=@Token
END
GO
You can extract the list of subscribed customers like this:
SELECT CustomerID, UserName FROM Customer WHERE MailingListToken IS NOT NULL;
Zoran
karthik parcha150 reputationPosted Jul 26, 2011, 2:05 AM EDT
thanq thanq very much i will try it if their any doubts i will contact you zoran
yesterday i tried your storedprocedure its working now
hie
can u explain this code plz dont mind
private string GenerateToken(int length)
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
string ts = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
for (int i = 0; i < ts.Length; i++)
sb.Append((char)(ts[i] - '0' + 'A'));
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
return sb.ToString();
}
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 26, 2011, 2:19 AM EDT
string ts = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
This would produce output:
201107261016464723
, which is year 2011, month 07, day 26, hour 10, minute 16, second 46 and part of the second 4723
Now this string, which consists of digits, is converted to letters so that 0 becomes A, 1 becomes B, ..., 9 becomes I:
for (int i = 0; i < ts.Length; i++)
sb.Append((char)(ts[i] - '0' + 'A'));
Now that this is done, remaining length - sb.Length characters are completely randomly generated:
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
In this way you get string of required length which consists of current UTC timestamp and random part, e.g.:
CABBAHCGBABIEAAHBHPSYWUJYKHIYY
This should always be unique (unless you have more than 16 new customers per second, as clock changes 15-16 times per second).
Zoran
karthik parcha150 reputationPosted Jul 26, 2011, 2:24 AM EDT
thanq awesome explanation
Now that this is done, remaining length - sb.Length characters are completely randomly generated:
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
can u explain this line
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 26, 2011, 2:28 AM EDT
Zoran
karthik parcha150 reputationPosted Jul 26, 2011, 2:56 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 26, 2011, 2:59 AM EDT
Thanks,
Zoran
karthik parcha150 reputationPosted Jul 26, 2011, 6:11 AM EDT
Anil KumarRank #367 · 6.8K reputationPosted Jul 26, 2011, 10:40 PM EDT
karthik parcha150 reputationPosted Jul 27, 2011, 1:54 AM EDT
thanks
karthik