public void Create(CreateProductViewModel model) { using (ITransaction transaction = _session.BeginTransaction()) { try { var product = new Product(model.Name, new Money(model.Price)); _productRepository.Add(product); } catch (MoneyWithMoreThanTwoDecimalPlacesException m1) { throw new ApplicationException(String.Format("Invalid product price: {0}", m1.Value)); } catch (MoneyCannotBeNegativeException m2) { throw new ApplicationException(String.Format("Product price can't be negative: {0}", m2.Value)); } catch (InvalidProductNameException p1) { throw new ApplicationException(String.Format("Invalid product name")); } transaction.Commit(); } }
public void Add(Product product) { _session.Save(product); }