/// <summary>
 /// Inserts an expense row.
 /// </summary>
 /// <param name="expense">An Expense object.</param>
 public void Create(ExpenseReview review)
 {
     using (ExpenseDataContext ctx = new ExpenseDataContext())
     {
         ctx.AddObject(ENTITY_SET_NAME, review);
         ctx.SaveChanges();
     }
 }
        /// <summary>
        /// Inserts an expense row.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        public Expense Create(Expense expense)
        {
            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                ctx.Expenses.AddObject(expense);
                ctx.SaveChanges();
            }

            return expense;
        }
        public List<ExpenseReview> SelectByExpenseID(long expenseID)
        {
            List<ExpenseReview> resultsList = null;

            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                resultsList =
                     (from review in ctx.ExpenseReviews
                      where review.Expense.ExpenseID == expenseID
                      orderby review.DateApproved
                      select review).ToList();
            }

            return resultsList;
        }
        public List<ExpenseLog> SelectByExpenseID(long expenseID)
        {
            List<ExpenseLog> resultsList = null;

            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                resultsList =
                     (from log in ctx.ExpenseLogs
                      where log.Expense.ExpenseID == expenseID
                      orderby log.DateCreated
                      select log).ToList();
            }

            return resultsList;
        }
        public List<Expense> SelectActive()
        {
            List<Expense> resultsList = null;

            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                resultsList =
                    (from expense in ctx.Expenses
                     where expense.IsCompleted == false
                     orderby expense.DateSubmitted descending
                     select expense).ToList();
            }

            return resultsList;
        }
        public void Purge()
        {
            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                List<Expense> resultList =
                    (from expense in ctx.Expenses
                     select expense).ToList();

                foreach (Expense expense in resultList)
                {
                    ctx.DeleteObject(expense);
                }

                ctx.SaveChanges();
            }
        }
        public List<Expense> SelectForApproval(string reviewer)
        {
            List<Expense> resultsList = null;

            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                resultsList =
                    (from expense in ctx.Expenses
                     where expense.AssignedTo == reviewer && expense.IsCompleted == false
                     orderby expense.DateSubmitted descending
                     select expense).ToList();
            }

            return resultsList;
        }
        /// <summary>
        /// Updates an Expense row.
        /// </summary>
        /// <param name="expense">A Expense object.</param>
        public void Update(Expense expense)
        {
            EntityKey key = null;
            object original = null;

            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                key = ctx.CreateEntityKey(ENTITY_SET_NAME, expense);
                if (ctx.TryGetObjectByKey(key, out original))
                {
                    ctx.ApplyCurrentValues(key.EntitySetName, expense);
                }
                ctx.SaveChanges();
            }
        }
        /// <summary>
        /// Returns a set of Expenses that belongs to an employee
        /// </summary>
        /// <param name="employeeID">An EmployeeID.</param>
        /// <returns>A List of expenses.</returns>
        public List<Expense> SelectForEmployee(string employee)
        {
            List<Expense> resultsList = null;

            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                resultsList =
                    (from expense in ctx.Expenses
                     where expense.Employee == employee
                     orderby expense.DateSubmitted descending
                     select expense).ToList();
            }

            return resultsList;
        }