public ActionResult Checkout() { GetCustomerRequest customerRequest = new GetCustomerRequest() { CustomerIdentityToken = _formsAuthentication.GetAuthenticationToken() }; GetCustomerResponse customerResponse = _customerService.GetCustomer(customerRequest); CustomerView customerView = customerResponse.Customer; if (customerView.DeliveryAddressBook.Count() > 0) { OrderConfirmationView orderConfirmationView = new OrderConfirmationView(); GetBasketRequest getBasketRequest = new GetBasketRequest() { BasketId = base.GetBasketId() }; GetBasketResponse basketResponse = _basketService.GetBasket(getBasketRequest); orderConfirmationView.Basket = basketResponse.Basket; orderConfirmationView.DeliveryAddresses = customerView.DeliveryAddressBook; return(View("ConfirmOrder", orderConfirmationView)); } return(AddDeliveryAddress()); }
public async Task <IActionResult> Checkout() { GetCustomerRequest customerRequest = new GetCustomerRequest { CustomerEmail = _cookieAuthentication.GetAuthenticationToken() }; GetCustomerResponse customerResponse = _customerService.GetCustomer(customerRequest); if (customerResponse.CustomerFound) { CustomerView customerView = customerResponse.Customer; if (customerView.DeliveryAddressBook.Any()) { OrderConfirmationView orderConfirmationView = new OrderConfirmationView(); GetBasketRequest getBasketRequest = new GetBasketRequest { BasketId = GetBasketId() }; GetBasketResponse basketResponse = _basketService.GetBasket(getBasketRequest); orderConfirmationView.Basket = basketResponse.Basket; orderConfirmationView.DeliveryAddresses = customerView.DeliveryAddressBook; return(View("ConfirmOrder", orderConfirmationView)); } return(AddDeliveryAddress()); } else { await _cookieAuthentication.SignOut(); return(RedirectToAction("Register", "AccountRegister")); } }
public GetBasketResponse GetProductsOfUser(int id) { GetBasketResponse response = new GetBasketResponse(); using (MyDb db = new MyDb()) { try { List <Basket> basket = db.Baskets.Where(x => x.User_ID == id).ToList(); foreach (var item in basket) { item.Product = db.Products.FirstOrDefault(x => x.ID == item.Product_ID); } response.Baskets = basket; response.Count = basket.Count; if (response.Baskets == null) { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.NOTFOUND); } else { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SUCCESSFUL); } } catch (Exception ex) { response.SetError(Common.SystemConstant.SystemConstants.ERRORS.SYSTEMERROR); } return(response); } }
public OrderConfirmationView getOrderConfirmationView() { GetCustomerRequest customerRequest = new GetCustomerRequest() { CustomerIdentityToken = _formsAuthentication.GetAuthenticationToken() }; GetCustomerResponse customerResponse = _customerService.GetCustomer(customerRequest); CustomerView customerView = customerResponse.Customer; OrderConfirmationView orderConfirmationView = new OrderConfirmationView(); GetBasketRequest getBasketRequest = new GetBasketRequest() { BasketId = base.GetBasketId() }; GetBasketResponse basketResponse = _basketService.GetBasket(getBasketRequest); orderConfirmationView.Basket = basketResponse.Basket; orderConfirmationView.DeliveryAddresses = customerView.DeliveryAddressBook; return(orderConfirmationView); }
public async Task <GetBasketResponse> GetBasketsAsync() { var response = new GetBasketResponse(); response.BasketItems = await _basketService.GetBasketsAsync(); return(response); }
public ActionResult Detail(int id) { HomePageViewModel model = new HomePageViewModel(); HttpClient client2 = new HttpClient(); client2.BaseAddress = new Uri(SystemConstants.webApiBaseAddress); HttpResponseMessage result2 = client2.PostAsJsonAsync("api/Basket/List", (Session["User"] as User) == null ? new User { ID = 0 } : (Session["User"] as User)).Result; if (result2.StatusCode == HttpStatusCode.OK) { string resultString = result2.Content.ReadAsStringAsync().Result; if (resultString != "{\"Products\":null}") { GetBasketResponse basketResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <GetBasketResponse>(resultString); if (basketResponse.Code == 1 || basketResponse.Code == 2) { model.BasketResponse = basketResponse; } else { return(View("SystemError")); } } } HttpClient client = new HttpClient(); client.BaseAddress = new Uri(SystemConstants.webApiBaseAddress); HttpResponseMessage result = client.PostAsJsonAsync("api/Product/Detail", new Product { ID = id }).Result; if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString != "{\"Product\":null}") { ProductDetailResponse product = Newtonsoft.Json.JsonConvert.DeserializeObject <ProductDetailResponse>(resultString); model.ProductDetailResponse = product; if (product.Code == 1) { return(View("Detail", model)); } if (product.Code == 2) { return(View("NotFound")); } } } return(View("SystemError")); }
public ActionResult <GetBasketResponse> GetBasket() { if (!ValidateRequest()) { return(BadRequest(new GetBasketResponse() { Failure = new RequestFailure(Error) })); } GetBasketResponse response = new GetBasketResponse() { Items = this.Basket.GetBasketItems(), TotalPrice = Basket.Products.Sum(x => x.Price) }; return(Ok(response)); }
public IActionResult Detail() { BasketDetailView basketView = new BasketDetailView(); Guid basketId = GetBasketId(); GetBasketRequest basketRequest = new GetBasketRequest() { BasketId = basketId }; GetBasketResponse basketResponse = _basketService.GetBasket(basketRequest); GetAllDispatchOptionsResponse dispatchOptionsResponse = _basketService.GetAllDispatchOptions(); basketView.Basket = basketResponse.Basket; basketView.Categories = GetCategories(); basketView.BasketSummary = GetBasketSummaryView(); basketView.DeliveryOptions = dispatchOptionsResponse.DeliveryOptions; return(View("View", basketView)); }
/// <summary> /// Returns the basket of the current user. The basket will be in the form of a Dictionary int,int where the client product id number is the key and the /// item quantity is the value. /// </summary> /// <returns></returns> public Dictionary <int, int> GetBasket() { using (HttpClient client = GetHttpClient()) { var result = client.GetAsync(ApiUrls.Basket).Result; GetBasketResponse response = JsonConvert.DeserializeObject <GetBasketResponse>(result.Content.ReadAsStringAsync().Result); this.ItemDictionary = response.Items; this.TotalPrice = response.TotalPrice; if (!string.IsNullOrEmpty(response.Failure?.ReasonForFailure)) { throw new Exception(response.Failure.ReasonForFailure); } return(response.Items); } }
public async void Get_should_return_OK_result() { var basketService = new Mock <IBasketService>(); basketService.Setup(x => x.GetContents(It.IsAny <Guid>())).Returns(Task.FromResult(new GetBasketResponse { Items = new List <BasketItem>() })); _sut = new BasketController(basketService.Object); SetupCookies(); var result = await _sut.Get(); var expectedResult = new GetBasketResponse { Items = new List <BasketItem>() }; var okObjectResult = result as OkObjectResult; Assert.Equal(expectedResult, okObjectResult.Value as GetBasketResponse); }
public GetBasketResponse GetBasket(GetBasketRequest basketRequest) { GetBasketResponse response = new GetBasketResponse(); Basket basket = _basketRepository.FindBy(basketRequest.BasketId); BasketView basketView = null; if (basket != null) { basketView = _mapper.Map <Basket, BasketView>(basket); } else { basketView = new BasketView(); } response.Basket = basketView; return(response); }
public GetBasketResponse GetBasket(GetBasketRequest request) { GetBasketResponse response = new GetBasketResponse(); Basket basket = _basketRepository.FindBy(request.BasketId); BasketView basketView; if (basket != null) { basketView = basket.ConvertToBasketView(); } else { basketView = new BasketView(); } response.Basket = basketView; return(response); }
public async Task <GetBasketResponse> GetContents(Guid sessionId) { var policy = _pollyPolicyProvider.BasketStorePolicy(); var result = await policy.ExecuteAndCaptureAsync(async() => { var items = await _basketStore.GetAll(sessionId); return(items.Select(model => new BasketItem { ProductId = model.ProductId.ToString(), Quantity = model.Quantity }).ToList()); }); if (result.Outcome == OutcomeType.Failure) { //LOG var response = new GetBasketResponse(); response.AddError(result.FinalException.Message); return(response); } return(new GetBasketResponse { Items = result.Result }); }
public GetBasketResponse GetBasket(GetBasketRequest request) { var response = new GetBasketResponse(); var basket = _basketRepository.FindBy(request.BasketId); BasketView basketView; if (basket == null) { throw new BasketDoesNotExistException(); } basketView = basket.ToBasketView(); //if (basket != null) // basketView = basket.ToBasketView(); //else // basketView = new BasketView(); response.Basket = basketView; return(response); }
private async Task IGetTheBasket() { _getBasketResponse = await _client.GetAsync <GetBasketResponse>($"/basket/{_basketId}"); }
// GET: Home public ActionResult Index() { HomePageViewModel model = new HomePageViewModel(); if (Session["User"] != null) { HttpClient client2 = new HttpClient(); client2.BaseAddress = new Uri(SystemConstants.webApiBaseAddress); HttpResponseMessage result2 = client2.PostAsJsonAsync("api/Basket/List", (Session["User"] as User)).Result; if (result2.StatusCode == HttpStatusCode.OK) { string resultString = result2.Content.ReadAsStringAsync().Result; if (resultString != "{\"Products\":null}") { GetBasketResponse basketResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <GetBasketResponse>(resultString); if (basketResponse.Code == 1 || basketResponse.Code == 2) { model.BasketResponse = basketResponse; } else { return(View("SystemError")); } } } HttpClient client = new HttpClient(); client.BaseAddress = new Uri(SystemConstants.webApiBaseAddress); HttpResponseMessage result = client.PostAsync("api/Product/List", null).Result; if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString != "{\"Products\":null}") { ProductListResponse product = Newtonsoft.Json.JsonConvert.DeserializeObject <ProductListResponse>(resultString); if (product.Code == 1 || product.Code == 2) { model.ProductList = product; return(View(model)); } } } return(View("SystemError")); } else { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(SystemConstants.webApiBaseAddress); HttpResponseMessage result = client.PostAsync("api/Product/List", null).Result; if (result.StatusCode == HttpStatusCode.OK) { string resultString = result.Content.ReadAsStringAsync().Result; if (resultString != "{\"Products\":null}") { ProductListResponse product = Newtonsoft.Json.JsonConvert.DeserializeObject <ProductListResponse>(resultString); if (product.Code == 1 || product.Code == 2) { model.ProductList = product; return(View(model)); } return(View("SystemError")); } } return(RedirectToAction("Index", "Home")); } }