Exemple #1
0
        private static int NewExpense()
        {
            int result = -1;

            try
            {
                var oExp = new Domain.Expense();
                oExp.ExpenseTitle      = "1nd This expense for a test";
                oExp.ExpensesAmount    = 20.10;
                oExp.ExpenseDate       = new DateTime(2019, 7, 24);
                oExp.PaymentMethod     = Domain.PaymentMethod.Card;
                oExp.PaymentType       = Domain.PaymentType.Refunded;
                oExp.CurrencyId        = 2;
                oExp.ExpenseCategoryId = 3;
                oExp.ExpenseDetail     = new Domain.ExpenseDetail {
                    Detail = "Dummy after audit-able columns"
                };
                _expContext.Add(oExp);
                result = _expContext.SaveChanges();
                if (result < 1)
                {
                    throw new Exception("Error: Expense has not been inserted into database");
                }
                else
                {
                    result = oExp.Id;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
        public async Task <int> NewExpensesAsync(Domain.Expense expense)
        {
            var result = -1;

            try
            {
                _expContext.Add(expense);
                result = await _expContext.SaveChangesAsync();

                if (result < 1)
                {
                    throw new Exception("Error occurred while adding new expense into database");
                }
                result = expense.Id;
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }