예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="itemId"></param>
        /// <returns></returns>
        public async Task <ShoppingCart> RemoveItem(int itemId)
        {
            try
            {
                var results = await _context.ShoppingCarts
                              .FindAsync(itemId);

                if (results == null)
                {
                    return(new ShoppingCart
                    {
                        Message = $"User with Id: {itemId} does not exist in shopping cart"
                    });
                }

                _dataBaseChanges.Remove(results);
                await _dataBaseChanges.CommitAsync();

                _logger.LogInformation("Successfully removed and committed changes in Database");
            }
            catch (Exception ex)
            {
                _logger.LogError($"An error occured during getting item from DB => {ex.Message}");
            }

            return(new ShoppingCart
            {
                Message = $"Successfully removed User with Id:{itemId}"
            });
        }
예제 #2
0
        public async Task <IActionResult> DeletCustomer(int id)
        {
            if (id != 0)
            {
                try
                {
                    var resultsCustomerID = await _customerShoppingCartContext.Customers.FindAsync(id);

                    if (resultsCustomerID == null)
                    {
                        return(new NotFoundObjectResult($"No Customer with id = {id} was found in the database"));
                    }

                    _dataBaseChanges.Remove(resultsCustomerID);
                    await _dataBaseChanges.CommitAsync();

                    return(new OkObjectResult($"Successfully deleted Customer with id = {id}"));
                }
                catch (Exception e)
                {
                    return(new BadRequestObjectResult($"Unable to delete Customer due to exception: {e.InnerException}"));
                }
            }
            return(new BadRequestObjectResult("Customer id cannot be null"));
        }