I've been thinkin all day about my design.. I realized that the ID of the Cart doesnt have to stay inside the CartManager. I have to get it out from the CartManager, this is a problem of the UserManager, i had to create the class User. the User Manager has
to provide me a User and get his SessionID. Since the user ID is unknown until i had the user to the DB, but i have to store the Cart even if i dont know the user ID, i thought to save the Cart in the DB with a SessionID of the User. Once the user decides
to register, i can register and the i can buy what he has in his Cart, i can save the Items in the Cart using a new ID, the UserID. It that a better solution? Your help is really appreciate. Luigi this is the code of the UserManager public class UserManager
{ public static IUser UserInit(HttpSessionState session, HttpRequest request, HttpResponse response) { string userID; HttpCookie cookie; DateTime dtNow; cookie = request.Cookies["userID"]; // check whether a cookie exists or not if (cookie == null || cookie.Value.ToString().Length<35)
{ /* This is a new user or an existing user with no cookies */ Debug.Print("there isnt a cookie"); // check whether the session exists or not if ((string)session["userID"] == null) { /* The session doesn't exists, i have to create it and then add it to * the
IUser objetc, this is the first time the user enters the site in this session */ Debug.Print("there isnt a session"); dtNow = DateTime.Now; userID = session.SessionID.ToString() + dtNow.ToString("G", DateTimeFormatInfo.InvariantInfo); userID = userID.Replace(".","");
userID = userID.Replace(" ",""); userID = userID.Replace("/",""); userID = userID.Replace(":",""); // set the session session["userID"] = userID; } else { /* The use has already a SessionID, i load it. */ Debug.Print("there is a session"); userID = session["userID"].ToString();
} /* * Until the user logs in I consider it a new user, so i give him * a new SessionID * * The cookie doesnt exists I try to create it, i'm not sure * the client accepts cookies */ cookie = new HttpCookie("userID"); cookie.Value = userID; dtNow = DateTime.Now;
TimeSpan tsMinute = new TimeSpan(30, 0, 0, 0); cookie.Expires = dtNow + tsMinute; response.Cookies.Add(cookie); } else { /* I know that the user has a cookie, it contais a SessionID, i create new user with existing SessionID * * I check wheter the SessionID
exists, if not i create it */ Debug.Print("there is a cookie"); userID = cookie.Value.ToString(); if ((string)session["userID"]==null) { /* The session doesn't exists, i have to create it and then add it to * the IUser objetc, this is the first time the user
enters the site in this session */ Debug.Print("there isnt a session"); // set the session session["userID"] = userID; } else { /* The use has already a SessionID, i load it, it should be the same as the Cookie, * if not i consider the SessionID the right
one */ Debug.Print("there is a session"); // check whether the session and the Cookie are different if (userID != session["userID"].ToString()) { Debug.Print("cookie and session are different!! use session"); userID = session["userID"].ToString(); } } } Debug.Print("create
the use with SessionID " + userID); return new User(userID); } }
luigi_malago
Member
70 Points
14 Posts
Re: Design of an e-commerce site
Dec 03, 2003 06:23 PM|LINK