public CustomerEntity Create(CustomerEntity customerEntity) { Customer customer = customerEntity.ToModel(); User User = new User(); User.Id = customerEntity.Id; User.Username = customerEntity.Username; User.Password = customerEntity.Password; smartDeliveryContext.User.Add(User); smartDeliveryContext.Customer.Add(customer); smartDeliveryContext.SaveChanges(); return(new CustomerEntity(customer)); }
public CustomerEntity Update(Guid CustomerId, CustomerEntity customerEntity) { Customer customer = smartDeliveryContext.Customer.Where(m => m.Id == CustomerId) .Include(u => u.IdNavigation) .FirstOrDefault(); if (customer == null) { throw new BadRequestException("Customer khong ton tai"); } customerEntity.ToModel(customer); smartDeliveryContext.Customer.Update(customer); smartDeliveryContext.SaveChanges(); return(new CustomerEntity(customer)); }