protected void Page_PreInit(object sender, EventArgs e) { if (!IsPostBack) { string itemId = Request.QueryString["addItem"]; if (!string.IsNullOrEmpty(itemId)) { Profile profile = null; using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(Page.User.Identity.Name); if (profile != null) { profile.Detach(); } } if (profile != null && !string.IsNullOrEmpty(profile.Username)) { CartHelper.Add(profile.WishList, itemId, profile.UniqueID, false); } // Redirect to prevent duplictations in the wish list if user hits "Refresh" Response.Redirect("~/WishList.aspx", true); } } }
public void UpdateItemQuantityShoppingCart() { Stopwatch watch = Stopwatch.StartNew(); //Add new Item to the cart. Profile profile = null; using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(NAME); profile.Detach(); } CartHelper.Add(profile.ShoppingCart, ID, profile.UniqueID, true); CartHelper.Add(profile.ShoppingCart, ID, profile.UniqueID, true); using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(NAME); profile.Detach(); } Assert.IsTrue(profile.ShoppingCart.Count == 1 && profile.ShoppingCart[0].Quantity == 2); Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds); }
// https://prod.liveshare.vsengsaas.visualstudio.com/join?11520D56B900E64EF9597DAA2A347C8D6C89 public async Task <JsonResult> AddJS(int id) { Clothing c = await ClothingDB.GetClothingById(id, _context); // TODO: add item to cart if (c == null) { // return item not found message (404) JsonResult notFound = new JsonResult("Not Found"); notFound.StatusCode = 404; return(notFound); } var item = new ClothingCartViewModel() { ItemId = c.ItemID, Title = c.Title, Price = c.Price, DateAdded = DateTime.Now }; CartHelper.Add(item, _http); // TODO: send success response JsonResult result = new JsonResult("Item Added"); result.StatusCode = 200; // HTTP okay return(result); }
public void ClearShoppingCart() { Stopwatch watch = Stopwatch.StartNew(); //Add new Item to the cart. Profile profile = null; using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(NAME); profile.Detach(); } CartHelper.Add(profile.ShoppingCart, ID, profile.UniqueID, true); //Clear the cart. using (var context = new PetShopDataContext()) { profile = context.Profile.GetProfile(NAME); profile.Detach(); } CartHelper.ClearCart(profile.ShoppingCart); using (var context = new PetShopDataContext()) { Assert.IsTrue(context.Profile.GetProfile(NAME).ShoppingCart.Count == 0); } Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds); }
/// <summary> /// Profile migrate from anonymous. /// </summary> /// <param name="sender">The sender.</param> /// <param name="pe">The <see cref="ProfileMigrateEventArgs"/> instance containing the event data.</param> private void Profile_MigrateAnonymous(Object sender, ProfileMigrateEventArgs pe) { var client = ServiceLocator.Current.GetInstance <OrderClient>(); var orders = client.GetAllCustomerOrders(pe.AnonymousID, UserHelper.CustomerSession.StoreId); if (orders != null) { foreach (var order in orders) { order.CustomerId = UserHelper.CustomerSession.CustomerId; order.CustomerName = UserHelper.CustomerSession.CustomerName; } client.SaveChanges(); } // Migrate shopping cart var cart = new CartHelper(CartHelper.CartName); var anonymousCart = new CartHelper(CartHelper.CartName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousCart.IsEmpty) { // Merge cart cart.Add(anonymousCart.Cart, true); cart.SaveChanges(); // Delete anonymous cart anonymousCart.Delete(); anonymousCart.SaveChanges(); } var wishList = new CartHelper(CartHelper.WishListName); var anonymousWishList = new CartHelper(CartHelper.WishListName, pe.AnonymousID); // Only perform merge if cart is not empty if (!anonymousWishList.IsEmpty) { // Merge wish list wishList.Add(anonymousWishList.Cart, true); if (String.IsNullOrEmpty(wishList.Cart.BillingCurrency)) { wishList.Cart.BillingCurrency = UserHelper.CustomerSession.Currency; } wishList.SaveChanges(); // Delete anonymous wish list anonymousWishList.Delete(); anonymousWishList.SaveChanges(); } //Delete the anonymous data from the database //ProfileManager.DeleteProfile(pe.AnonymousID); //Remove the anonymous identifier from the request so //this event will no longer fire for a logged-in user AnonymousIdentificationModule.ClearAnonymousIdentifier(); }
// Add a single product to the shopping cart. public async Task <IActionResult> AddToCartAsync(int id, string prevUrl) { Clothing c = await ClothingDb.GetClothingById(id, _context); if (c != null) { CartHelper.Add(c, _http); } return(Redirect(prevUrl)); }
// Add a single product to the shopping cart public async Task <IActionResult> Add(int id, string prevUrl) { Clothing c = await ClothingDB.GetClothingbyID(id, _context); if (c != null) { CartHelper.Add(c, _accessor); } return(Redirect(prevUrl)); }
// Add a single product to the shopping cart public async Task <IActionResult> Add(int ID, string prevUrl) { Clothing c = await ClothingDB.GetClothingByID(ID, _context); if (c != null) { CartHelper.Add(c, _http); } // Use Redirect instead of RedirectToAction because prevUrl doesn't have an action tied to it return(Redirect(prevUrl)); }
/// <summary> /// Adds a single object to the cart. /// Quantity does not matter if same object added 5 times displayed 5 times. /// </summary> public async Task <IActionResult> AddToCart(int id, string prevUrl) { //Grab the clothing Object by Id. Clothing c = await ClothingDb.GetClothingByID(id, _context); //Add Clothing object to be stored in cookie. if (c != null) { CartHelper.Add(c, _http); } //redirect: sends you back to the url you were previously using return(Redirect(prevUrl)); }
public async Task <IActionResult> Add(int id) { VideoGame g = await VideoGameDb.GetGameById(id, _context); CartHelper.Add(_httpAccessor, g); return(RedirectToAction("Index", "Library")); //// Set up cookie //CookieOptions options = new CookieOptions() //{ // Secure = true, // MaxAge = TimeSpan.FromDays(365) // A whole year //}; //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); }
// Add the game to a cookie public async Task <IActionResult> Add(int id) { VideoGame g = await VideoGameDb.GetGameById(id, _context); CartHelper.Add(_httpAccessor, g); /* * string data = JsonConvert.SerializeObject(g); * CookieOptions options = new CookieOptions() * { * Secure = true, * MaxAge = TimeSpan.FromDays(14) * }; * * _httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); */ return(RedirectToAction("Index", "Library")); }
public async Task <JsonResult> AddJS(int id) { //Get id of clothing Clothing c = await ClothingDb.GetClothingById(id, _context); //Add clothing to the cart if (c == null) { //Return not found message } CartHelper.Add(c, _http); //Send success response JsonResult result = new JsonResult("Success"); result.StatusCode = 200; //Http ok return(result); }
public async Task <IActionResult> Add(int id) { //Get the game with the corresponding id VideoGame g = await VideoGameDb.GetGameById(id, _context); //Convert game to a string CartHelper.Add(_httpAccessor, g); //Set up cookie //CookieOptions options = new CookieOptions() //{ // Secure = true, // MaxAge = TimeSpan.FromDays(365) //The cookie data will last up to a year //}; //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); return(RedirectToAction("Index", "Library")); }
/// <summary> /// Add a single product to the cart. /// </summary> /// <returns></returns> public async Task <IActionResult> Add(int id, string prevUrl) { Clothing c = await ClothingDB.GetClothingById(id, _context); if (c != null) { var item = new ClothingCartViewModel() { ItemId = c.ItemID, Title = c.Title, Price = c.Price, DateAdded = DateTime.Now }; CartHelper.Add(item, _http); } TempData["Message"] = $"{c.Title}, ID#: {c.ItemID}, Added Successfully"; //return RedirectToAction("Index", "Home"); return(Redirect(prevUrl)); }
public async Task <IActionResult> Add(int ID) { //Get the game with the corresponding ID VideoGame g = await VideoGameDB.GetGameByID(ID, _context); //Convert game to string string data = JsonConvert.SerializeObject(g); CartHelper.Add(_httpAccessor, g); return(RedirectToAction("Index", "VideoGame")); //Set up cookie //CookieOptions options = new CookieOptions() //{ // Secure = true, // MaxAge = TimeSpan.FromDays(2 * DaysInWeek) //}; //THIS IS HOW YOU CREATE A COOKIE //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); }
public async Task <IActionResult> Add(int id) { VideoGame g = await VideoGameDb.GetGameById(id, _context); CartHelper.Add(_httpAccessor, g); return(RedirectToAction("Index", "Library")); // get game with the associated id, add the game to a cookie, // redirect to catalog, // convert object to string using Json.NET //string data = JsonConvert.SerializeObject(g); //// set up cookie //CookieOptions options = new CookieOptions() //{ // Secure = true, // MaxAge = TimeSpan.FromDays(14) // two weeks //}; //_httpAccessor.HttpContext.Response.Cookies.Append("CartCookie", data, options); }
public void AddItemToShoppingCart() { Stopwatch watch = Stopwatch.StartNew(); Profile profile = null; using (var context = new PetshopDataContext()) { profile = context.Profile.GetProfile(NAME); context.Profile.Detach(profile); } using (var context = new PetshopDataContext()) { CartHelper.Add(profile.ShoppingCart, ID, profile.UniqueID, true); } using (var context = new PetshopDataContext()) { Assert.IsTrue(context.Profile.GetProfile(NAME).ShoppingCart.Count == 1); } Console.WriteLine("Time: {0} ms", watch.ElapsedMilliseconds); }