public PlaceOrderService( IRequestCookieCollection cookiesIn, IResponseCookies cookiesOut, IPlaceOrderBizLogic placeOrder) { _basketCookie = new BasketCookie(cookiesIn, cookiesOut); _placeOrder = placeOrder; }
/********************************************************* #A This action is called if a user clicks any of the "Buy n books" dropdown buttons. #B To isolate the CheckoutCookieService from the ASP.NET Core's HttpContext we have designed a BasketCookie that provides an interface that can be used in a unit test #C The CheckoutCookieService is created, with the content of the current basket Cookie, or null if no basket Cookie currently exists #D This method adds a new OrderLineItem entry to the CheckoutCookieService list of OrderLineItems #E This statement encodes the list of OrderLineItems into a string, ready to go out in the updated basket Cookie #F This method sets the basket cookie content to the encoded string #G Finally we go to the Checkout page which shows the user the books, quantities and prices of the books they have in their basket * ******************************************************/ public IActionResult DeleteLineItem(int lineNum) { var cookie = new BasketCookie(HttpContext.Request.Cookies, HttpContext.Response.Cookies); var service = new CheckoutCookieService(cookie.GetValue()); service.DeleteLineItem(lineNum); cookie.AddOrUpdateCookie(service.EncodeForCookie()); SetupTraceInfo(); return(RedirectToAction("Index")); }
public PlaceOrderServiceWithVal( IRequestCookieCollection cookiesIn, IResponseCookies cookiesOut, EfCoreContext context) { _basketCookie = new BasketCookie(cookiesIn, cookiesOut); _runner = new RunnerWriteDbWithValidation <PlaceOrderInDto, Order>( new PlaceOrderAction( new PlaceOrderDbAccess(context)), context); }
Errors => _runner.Errors; //#C public PlaceOrderService( //#D IRequestCookieCollection cookiesIn, //#D IResponseCookies cookiesOut, //#D EfCoreContext context) //#D { _basketCookie = new BasketCookie( //#E cookiesIn, cookiesOut); //#E _runner = new RunnerWriteDb <PlaceOrderInDto, Order>( //#F new PlaceOrderAction( //#F new PlaceOrderDbAccess(context)), //#F context); //#F }
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 PlaceOrderServiceTransact( IRequestCookieCollection cookiesIn, IResponseCookies cookiesOut, EfCoreContext context) { _basketCookie = new BasketCookie( cookiesIn, cookiesOut); _runner = new RunnerTransact2WriteDb //#B <PlaceOrderInDto, Part1ToPart2Dto, Order>( //#C context, //#D new PlaceOrderPart1( //#E new PlaceOrderDbAccess(context)), //#E new PlaceOrderPart2( //#F new PlaceOrderDbAccess(context))); //#F }
} //#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 }