public virtual void SaveExpense(Model.Expense expense)
        {
            Guard.ArgumentNotNull(expense, "expense");

            this.ValidateFromRuleset(expense);

            exManager.Process(() =>
            {
                AExpenseEvents.Log.SaveExpenseStarted(expense.Id, expense.Title);
                ProcessInContext <object>((db) =>
                {
                    AExpenseEvents.Log.SaveExpenseInsertStarted(expense.Id, expense.Title);
                    var entity = expense.ToEntity();
                    db.Expenses.InsertOnSubmit(entity);

                    foreach (var detail in expense.Details)
                    {
                        var detailEntity = detail.ToEntity(expense);
                        db.ExpenseDetails.InsertOnSubmit(detailEntity);
                    }

                    this.retryPolicy.ExecuteAction(() => db.SubmitChanges());

                    AExpenseEvents.Log.SaveExpenseInsertFinished(expense.Id, expense.Title);
                    return(null);
                });

                UpdateCache(expense);
                AExpenseEvents.Log.SaveExpenseFinished(expense.Id, expense.Title);
            },
                              Constants.NotifyPolicy);
        }
        public virtual void SaveExpense(Model.Expense expense)
        {
            Guard.ArgumentNotNull(expense, "expense");

            this.ValidateFromRuleset(expense);

            exManager.Process(() =>
            {
                ProcessInContext <object>((db) => {
                    var entity = expense.ToEntity();
                    db.Expenses.InsertOnSubmit(entity);

                    foreach (var detail in expense.Details)
                    {
                        var detailEntity = detail.ToEntity(expense);
                        db.ExpenseDetails.InsertOnSubmit(detailEntity);
                    }

                    db.SubmitChanges();
                    return(null);
                });

                UpdateCache(expense);
            },
                              Constants.NotifyPolicy);
        }
 public static void CreateExpense(string databaseConnectionString, Model.Expense expense)
 {
     using (var db = new ExpensesDataContext(databaseConnectionString))
     {
         db.Expenses.InsertOnSubmit(expense.ToEntity());
         db.SubmitChanges();
     }
 }