예제 #1
0
  public void updateEntity(Sale sale, SaleEditDto editDto) {

    if (isNotNull(editDto.getContactId())) {
      Contact contact = contactsDao.findById(editDto.getContactId());
      sale.setContact(contact);
    }

    if (isNotNull(editDto.getStoreId())) {
      Store store = storesDao.findById(editDto.getStoreId());
      sale.setStore(store);
    }

    if (isNotEmpty(editDto.getLabel())) {
      sale.setLabel(editDto.getLabel());
    }

    if (isNotNull(editDto.getDateOut())) {
      sale.setDateOut(editDto.getDateOut());
    }

    if (isNotEmpty(editDto.getProductsToAdd())) {
      for (Long productToAdd : editDto.getProductsToAdd()) {
        Product product = productsDao.findById(productToAdd);
        sale.addProduct(product);
      }
    }

    if (isNotEmpty(editDto.getProductsToRemove())) {
      for (Long productId : editDto.getProductsToRemove()) {
        Product productToRemove = productsDao.findById(productId);

        sale.removeProduct(productToRemove);
      }
    }
  }
예제 #2
0
  public Sale toEntity(SaleAddDto dto) {
    Sale entity = new Sale();

    entity.setDateOut(dto.getDateOut());
    entity.setLabel(dto.getLabel());

    Contact contact = contactsDao.findById(dto.getContactId());
    Store store = storesDao.findById(dto.getStoreId());

    entity.setContact(contact);
    entity.setStore(store);

    for (Long productId : dto.getProductsIds()) {
      Product product = productsDao.findById(productId);
      entity.addProduct(product);
    }

    return entity;
  }