Esempio n. 1
0
        /// <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();
        }
Esempio n. 2
0
        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;
            }
        }
Esempio n. 3
0
 public async Task UpdateAsync(Customer customer)
 {
     _context.Update(customer);
     await _context.SaveChangesAsync();
 }