/// <summary> /// Updates Customer /// </summary> /// <param name="id">Id</param> /// <param name="dto">Customer Dto</param> public async Task UpdateCustomer(int id, CustomerDto dto) { var customer = _dbContext.Customers.Find(id); customer.FirstName = dto.FirstName; customer.LastName = dto.LastName; customer.DOB = Convert.ToDateTime(dto.DateOfBirth); _dbContext.Update(customer); await SaveAsync(); }
public async Task <int> UpdateAsync(CustomerDto customerDto) { try { Customer customer = await GetCustomerByIdAsync(customerDto?.Id ?? 0); if (customer == null) { throw new EntityNotFoundException($"There is no Customer with Title {customerDto?.Title}"); } Customer customerToUpdate = _mapper.Map <Customer>(customerDto); _dbContext.Update(customerToUpdate); return(await _dbContext.SaveChangesAsync()); } catch (Exception ex) { _logger.LogError(ex, "Error occurred"); throw; } }
public async Task UpdateAsync(Customer customer) { _context.Update(customer); await _context.SaveChangesAsync(); }