예제 #1
0
        public async Task <ActionResult <BasketLine> > Put(Guid basketId,
                                                           Guid basketLineId,
                                                           [FromBody] BasketLineForUpdate basketLineForUpdate)
        {
            if (!await _basketRepository.BasketExists(basketId))
            {
                return(NotFound());
            }

            var basketLineEntity = await _basketLinesRepository.GetBasketLineById(basketLineId);

            if (basketLineEntity == null)
            {
                return(NotFound());
            }

            // map the entity to a dto
            // apply the updated field values to that dto
            // map the dto back to an entity
            _mapper.Map(basketLineForUpdate, basketLineEntity);

            _basketLinesRepository.UpdateBasketLine(basketLineEntity);
            await _basketLinesRepository.SaveChanges();

            return(Ok(_mapper.Map <BasketLine>(basketLineEntity)));
        }
        public async Task <IActionResult> UpdateLine(BasketLineForUpdate basketLineUpdate)
        {
            var basketId = Request.Cookies.GetCurrentBasketId(settings);
            await basketService.UpdateLine(basketId, basketLineUpdate);

            return(RedirectToAction("Index"));
        }
예제 #3
0
        public async Task <IActionResult> UpdateLine(BasketLineForUpdate basketLineUpdate)
        {
            var domain = $"{ HttpContext.Request.Scheme}://{HttpContext.Request.Host}";

            _basketService.SetBaseUri(domain);
            ViewBag.Domain = domain;

            var basketId = Request.Cookies.GetCurrentBasketId(settings);
            await _basketService.UpdateLine(basketId, basketLineUpdate);

            return(RedirectToAction("Index"));
        }
 public async Task <IActionResult> UpdateLine(BasketLineForUpdate basketLineForUpdate)
 {
     if (string.IsNullOrWhiteSpace(basketLineForUpdate.LineId))
     {
         HandleException(new ArgumentNullException(nameof(basketLineForUpdate.LineId)));
     }
     else
     {
         var basketId = Request.Cookies.GetCurrentBasketId(_settings);
         await _basketService.UpdateLine(basketId, basketLineForUpdate);
     }
     return(RedirectToAction("Index"));
 }
예제 #5
0
        public async Task UpdateLine(string basketId, BasketLineForUpdate basketLineForUpdate)
        {
            CustomerBasket basket = await GetBasket(basketId);

            var basketItem = basket?.Items?.FirstOrDefault(bi => bi.Id == basketLineForUpdate.LineId);

            if (basketItem != null)
            {
                basketItem.Quantity = basketLineForUpdate.Quantity;
                var response = await _client.PostAsJson($"api/v1/basket", basket);

                if (!response.IsSuccessStatusCode)
                {
                    _logger.LogError($"{response.ReasonPhrase}");
                }
            }
            else
            {
                _logger.LogWarning($"No basket item found with id of {basketLineForUpdate.LineId}");
            }
        }
예제 #6
0
 public async Task UpdateLine(Guid basketId, BasketLineForUpdate basketLineForUpdate)
 {
     await client.PutAsJson($"/api/baskets/{basketId}/basketLines/{basketLineForUpdate.LineId}", basketLineForUpdate);
 }
예제 #7
0
 public async Task UpdateLine(Guid basketId, BasketLineForUpdate basketLineForUpdate)
 {
     client.SetBearerToken(await httpContextAccessor.HttpContext.GetTokenAsync("access_token"));
     await client.PutAsJson($"/api/baskets/{basketId}/basketLines/{basketLineForUpdate.LineId}", basketLineForUpdate);
 }