public ImmutableList <CheckoutItemDto> GetCheckoutList() { var cookieHandler = new BasketCookie(_cookiesIn); var service = new CheckoutCookieService(cookieHandler.GetValue()); return(GetCheckoutList(service.LineItems)); }
//--------------------------------------------------------------- //private methods private string GetUserId(HttpContext httpContext) { var checkoutCookie = new CheckoutCookie(httpContext.Request.Cookies, httpContext.Response.Cookies); var cookieService = new CheckoutCookieService(checkoutCookie.GetValue()); return(cookieService.UserId); }
public void RemoveLineEncodeDecode() { //SETUP var service = new CheckoutCookieService((string)null); service.AddLineItem(new OrderLineItem { BookId = 1, NumBooks = 4 }); service.AddLineItem(new OrderLineItem { BookId = 2, NumBooks = 5 }); service.AddLineItem(new OrderLineItem { BookId = 3, NumBooks = 6 }); //ATTEMPT service.DeleteLineItem(1); //VERIFY service.LineItems.Count.ShouldEqual(2); service.LineItems[0].BookId.ShouldEqual(1); service.LineItems[0].NumBooks.ShouldEqual((short)4); service.LineItems[1].BookId.ShouldEqual(3); service.LineItems[1].NumBooks.ShouldEqual((short)6); }
private void ClearCheckoutCookie(HttpContext httpContext) { var checkoutCookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); var cookieService = new CheckoutCookieService(checkoutCookie.GetValue()); cookieService.ClearAllLineItems(); checkoutCookie.AddOrUpdateCookie(cookieService.EncodeForCookie()); }
/// <summary> /// This lists existing orders /// </summary> /// <returns></returns> public List <OrderListDto> GetUsersOrders(IRequestCookieCollection cookiesIn) { var cookie = new CheckoutCookie(cookiesIn); var service = new CheckoutCookieService(cookie.GetValue()); return(SelectQuery(_context.Orders.OrderByDescending(x => x.DateOrderedUtc) .Where(x => x.CustomerName == service.UserId)).ToList()); }
public IList <OrderListDto> GetUsersOrders(IRequestCookieCollection cookiesIn) { var checkoutCookieService = new CheckoutCookieService(cookiesIn); var userId = checkoutCookieService.UserId; var orders = dataContext.Orders.Where(order => order.CustomerName == userId).OrderByDescending(order => order.DateOrderedUtc); return(Select(orders).ToList()); }
public IActionResult AddToCart(OrderLineItem itemToBuy) { var cookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); var service = new CheckoutCookieService(cookie.GetValue()); service.AddLineItem(itemToBuy); cookie.AddOrUpdateCookie(service.EncodeForCookie()); return(RedirectToAction("Index")); }
public IActionResult ChooseCustomer(Guid customerKey) { var cookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); var service = new CheckoutCookieService(cookie.GetValue()); service.AddCustomer(customerKey); cookie.AddOrUpdateCookie(service.EncodeForCookie()); return(RedirectToAction("Index", "Items")); }
public IActionResult Buy(OrderItem itemToBuy) { var cookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); //create a new cookie var service = new CheckoutCookieService(cookie.GetValue()); //create a new List of OrderLineItem and add the items in the existing cookie to it service.AddLineItem(itemToBuy); //add itemto Buy to the List of OrderLineitems cookie.AddOrUpdateCookie(service.EncodeForCookie()); //update cookie return(RedirectToAction("Index")); }
public IActionResult DeleteLineItem(int lineNum) { var cookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); var service = new CheckoutCookieService(cookie.GetValue()); service.DeleteLineItem(lineNum); cookie.AddOrUpdateCookie(service.EncodeForCookie()); SetupTraceInfo(); return(RedirectToAction("Index")); }
public RedirectToActionResult ChooseItems(OrderLineItemDto modifiedDto) { var listService = new ListItemServices(_context); var cookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); var service = new CheckoutCookieService(cookie.GetValue()); service.AddLineItem(modifiedDto.RetriveOrderLineItemDto()); cookie.AddOrUpdateCookie(service.EncodeForCookie()); return(RedirectToAction("Index")); }
public void CreateNewCookie() { //SETUP //ATTEMPT var service = new CheckoutCookieService((string)null); //VERIFY service.UserId.ShouldNotEqual(Guid.Empty); service.LineItems.Count.ShouldEqual(0); }
public IActionResult Buy(OrderLineItem itemToBuy) { var cookie = new CheckoutCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); var service = new CheckoutCookieService(cookie.GetValue()); service.AddLineItem(itemToBuy); cookie.AddOrUpdateCookie(service.EncodeForCookie()); SetupTraceInfo(); return(RedirectToAction(nameof(Index))); }
public void EncodeDecodeNewCookie() { //SETUP var service = new CheckoutCookieService((string)null); var cString = service.EncodeForCookie(); var userId = service.UserId; //ATTEMPT service = new CheckoutCookieService(cString); //VERIFY service.UserId.ShouldEqual(userId); service.LineItems.Count.ShouldEqual(0); }
public IActionResult Buy(OrderLineItem itemToBuy) { var cookie = new BasketCookie( HttpContext.Request.Cookies, HttpContext.Response.Cookies); var service = new CheckoutCookieService(cookie.GetValue()); service.AddLineItem(itemToBuy); var cookieOutString = service.EncodeForCookie(); cookie.AddOrUpdateCookie(cookieOutString); SetupTraceInfo(); //Remove this when shown in book listing return(RedirectToAction("Index")); }
public int PlaceOrder(bool acceptTAndCs) { var checkoutService = new CheckoutCookieService(checkoutCookie.GetValue()); var placeOrderInDto = new PlaceOrderInDto(acceptTAndCs, checkoutService.UserId, checkoutService.LineItems); var order = runner.RunAction(placeOrderInDto); if (runner.HasErrors) { return(0); } checkoutService.ClearAllLineItems(); checkoutCookie.AddOrUpdateCookie(checkoutService.EncodeForCookie()); return(order.OrderId); }
public void AddLineItemEncodeDecode() { //SETUP var service = new CheckoutCookieService((string)null); service.AddLineItem(new OrderLineItem { BookId = 123, NumBooks = 456 }); var cString = service.EncodeForCookie(); //ATTEMPT service = new CheckoutCookieService(cString); //VERIFY service.LineItems.Count.ShouldEqual(1); service.LineItems[0].BookId.ShouldEqual(123); service.LineItems[0].NumBooks.ShouldEqual((short)456); }
} //#A public Guid GetUserId() { var httpContext = _httpAccessor.HttpContext; //#B if (httpContext == null) //#B { return(Guid.Empty); //#B } var cookie = new BasketCookie(httpContext.Request.Cookies); //#C if (!cookie.Exists()) //#C { return(Guid.Empty); //#C } var service = new CheckoutCookieService(cookie.GetValue()); //#D return(service.UserId); //#D }
/// <summary> /// This creates the order and, if successful clears the cookie /// </summary> /// <returns>Returns the OrderId, or zero if errors</returns> public int PlaceOrder(bool acceptTAndCs) { var checkoutService = new CheckoutCookieService( _basketCookie.GetValue()); var order = _runner.RunAction( new PlaceOrderInDto(acceptTAndCs, checkoutService.UserId, checkoutService.LineItems)); if (_runner.HasErrors) { return(0); } //successful so clear the cookie line items checkoutService.ClearAllLineItems(); _basketCookie.AddOrUpdateCookie( checkoutService.EncodeForCookie()); return(order.OrderId); }
/// <summary> /// This creates the order and, if successful clears the cookie /// </summary> /// <returns>Returns the OrderId, or zero if errors</returns> public int PlaceOrder(bool acceptTAndCs) //#G { var checkoutService = new CheckoutCookieService( //#H _checkoutCookie.GetValue()); //#H var order = _runner.RunAction( //#I new PlaceOrderInDto(acceptTAndCs, //#I checkoutService.UserId, //#I checkoutService.LineItems)); //#I if (_runner.HasErrors) { return(0); //#J } //successful so clear the cookie line items checkoutService.ClearAllLineItems(); //#K _checkoutCookie.AddOrUpdateCookie( //#K checkoutService.EncodeForCookie()); //#K return(order.OrderId); //#L }
/// <summary> /// This creates the order and, if successful clears the cookie /// </summary> /// <returns>Returns the OrderId, or zero if errors</returns> public async Task <IStatusGeneric <int> > PlaceOrderAndClearBasketAsync(bool acceptTAndCs) { var status = new StatusGenericHandler <int>(); var checkoutService = new CheckoutCookieService( _basketCookie.GetValue()); var bizStatus = await _placeOrder.CreateOrderAndSaveAsync( new PlaceOrderInDto(acceptTAndCs, checkoutService.UserId, checkoutService.LineItems)); if (status.CombineStatuses(bizStatus).HasErrors) { return(status); } //successful so clear the cookie line items checkoutService.ClearAllLineItems(); _basketCookie.AddOrUpdateCookie( checkoutService.EncodeForCookie()); return(status.SetResult(bizStatus.Result.OrderId)); }