/// <summary> /// Tries to log in with the corresponding method of /// <c>UserService</c>, and if successful, inserts in the /// session the necessary objects for an authenticated user. /// </summary> /// <param name="context">Http Context includes request, response, etc.</param> /// <param name="loginName">Username</param> /// <param name="password">User Password</param> /// <param name="passwordIsEncrypted">Password is either encrypted or /// in clear text</param> /// <param name="rememberMyPassword">Remember password to the next /// logins</param> /// <exception cref="IncorrectPasswordException"/> /// <exception cref="InstanceNotFoundException"/> private static LoginResult DoLogin(HttpContext context, String loginName, String password, Boolean passwordIsEncrypted, Boolean rememberMyPassword) { LoginResult loginResult = userService.Login(loginName, password, passwordIsEncrypted); /* Insert necessary objects in the session. */ UserSession userSession = new UserSession(); userSession.UserProfileId = loginResult.UserProfileId; userSession.FirstName = loginResult.FirstName; userSession.Rol = loginResult.Rol; userSession.CardDefaultId = loginResult.CardId; userSession.CardDefaultNumber = loginResult.CardNumber; ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; shoppingCart.Address = loginResult.Addres; Locale locale = new Locale(loginResult.Language, loginResult.Country); UpdateSessionForAuthenticatedUser(context, userSession, locale); UpdateCartSession(context, shoppingCart); return(loginResult); }
/// <summary> /// Updates the user profile details. /// </summary> /// <param name="context">The context.</param> /// <param name="userProfileDetails">The user profile details.</param> public static void UpdateUserProfileDetails(HttpContext context, UserProfileDetails userProfileDetails) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; /* Update user's profile details. */ UserSession userSession = (UserSession)context.Session[USER_SESSION_ATTRIBUTE]; userService.UpdateUserProfileDetails(userSession.UserProfileId, userProfileDetails); /* Update user's session objects. */ Locale locale = new Locale(userProfileDetails.language, userProfileDetails.country); shoppingCart.Address = userProfileDetails.address; userSession.FirstName = userProfileDetails.firstName; UpdateSessionForAuthenticatedUser(context, userSession, locale); UpdateCartSession(context, shoppingCart); }
/// <summary> /// Registers the user. /// </summary> /// <param name="context">Http Context includes request, response, etc.</param> /// <param name="loginName">Username</param> /// <param name="clearPassword">Password in clear text</param> /// <param name="userProfileDetails">The user profile details.</param> /// <exception cref="DuplicateInstanceException"/> public static long RegisterUser(HttpContext context, String loginName, String clearPassword, UserProfileDetails userProfileDetails) { /* Register user. */ long usrId = userService.RegisterUser(loginName, clearPassword, userProfileDetails); /* Insert necessary objects in the session. */ UserSession userSession = new UserSession(); userSession.UserProfileId = usrId; userSession.Rol = userProfileDetails.role; userSession.FirstName = userProfileDetails.firstName; Locale locale = new Locale(userProfileDetails.language, userProfileDetails.country); ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; shoppingCart.Address = userProfileDetails.address; UpdateSessionForAuthenticatedUser(context, userSession, locale); UpdateCartSession(context, shoppingCart); FormsAuthentication.SetAuthCookie(loginName, false); return(usrId); }
public static void TouchCart(HttpContext context) { ShoppingCartSession shoppingCartSession = new ShoppingCartSession(); shoppingCartSession.ShoppingCart = new List <ShoppingCart>(); UpdateCartSession(context, shoppingCartSession); }
public static void DeleteProductOfCart(HttpContext context, long productId) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; shoppingCart.ShoppingCart = shoppingService.DeleteShoppingCartDetails(shoppingCart.ShoppingCart, productId); UpdateCartSession(context, shoppingCart); }
public static void ForGift(HttpContext context, long productId, bool gitf) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; shoppingCart.ShoppingCart = shoppingService.ModifyGift(shoppingCart.ShoppingCart, productId, gitf); UpdateCartSession(context, shoppingCart); }
public static void ModifyAmount(HttpContext context, long productId, int amount) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; shoppingCart.ShoppingCart = shoppingService.ModifyAmountOfItems(shoppingCart.ShoppingCart, productId, amount); UpdateCartSession(context, shoppingCart); }
public static void AddToShoppingCart(HttpContext context, long productId, int amount, bool gift) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; shoppingCart.ShoppingCart = shoppingService.UpdateShoppingCartDetails(shoppingCart.ShoppingCart, productId, amount, gift); UpdateCartSession(context, shoppingCart); }
public static void Buy(HttpContext context, long creditNumber, string description, string address) { UserSession userSession = (UserSession)context.Session[USER_SESSION_ATTRIBUTE]; ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; shoppingService.CreateDelivery(GetTotalPrice(context), creditNumber, userSession.UserProfileId, description, shoppingCart.ShoppingCart, address); shoppingCart.ShoppingCart = new List <ShoppingCart>(); UpdateCartSession(context, shoppingCart); }
public static decimal GetTotalPrice(HttpContext context) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; decimal price = 0; foreach (ShoppingCart line in shoppingCart.ShoppingCart) { price += line.Product.productPrice * line.Amount; } return(price); }
public static void UpdateCartSession(HttpContext context, ShoppingCartSession shoppingCartSession) { context.Session.Add(SHOPPING_CART_SESSION_ATTRIBUTE, shoppingCartSession); }
public static String GetAddress(HttpContext context) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; return(shoppingCart.Address); }
public static List <ShoppingCart> GetShoppingCart(HttpContext context) { ShoppingCartSession shoppingCart = (ShoppingCartSession)context.Session[SHOPPING_CART_SESSION_ATTRIBUTE]; return(shoppingCart.ShoppingCart); }