/// <summary> /// Update a customer as well as its reviews. /// </summary> /// <param name="customer">The customer with changed values</param> public void UpdateCustomer(BusinessBears.Library.Customer customer) { _logger.LogInformation("Updating customer with ID {customerId}", customer.Id); // calling Update would mark every property as Modified. // this way will only mark the changed properties as Modified. Customer currentEntity = _dbContext.Customer.Find(customer.Id); Customer newEntity = Mapper.Map(customer); _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity); }
/// <summary> /// Add a customer, including any associated reviews. /// </summary> /// <param name="customer">The customer</param> public void AddCustomer(BusinessBears.Library.Customer Customer) { if (Customer.Id != 0) { _logger.LogWarning("Customer to be added has an ID ({customerId}) already: ignoring.", Customer.Id); } _logger.LogInformation($"Adding customer"); Customer entity = Mapper.Map(Customer); entity.CustomerId = 0; _dbContext.Add(entity); }