/// <summary> /// /// </summary> /// <param name="shoppingCart"></param> /// <returns></returns> public async Task <ShoppingCart> AddItem(ShoppingCart shoppingCart) { try { await _dataBaseChanges.AddAsync(shoppingCart); await _dataBaseChanges.CommitAsync(); _logger.LogInformation("Successfully committed changes in Database"); } catch (Exception ex) { _logger.LogError($"An error occured during adding item to DB => {ex.InnerException}"); } return(new ShoppingCart { Message = $"Successfully added Item with Id:{shoppingCart.Id}" }); }
public async Task <IActionResult> CreateNewCustomer(Customer customer) { if (customer != null) { try { await _dataBaseChanges.AddAsync(customer); await _dataBaseChanges.CommitAsync(); return(new CreatedResult($"Successfully created customer with ID = {customer.id}", customer)); } catch (Exception e) { return(new BadRequestObjectResult($"Unable to create Customer due to exception: {e.InnerException}")); } } return(new BadRequestObjectResult("Customer object cannot be null")); }