Пример #1
0
        public static void EditExpenses()
        {
            var oExpenses = new MEMCore.Domain.Expense();

            oExpenses.ExpenseTitle      = "--Update this expenses";
            oExpenses.ExpensesAmount    = 7200.20;
            oExpenses.ExpenseDate       = new DateTime(2018, 5, 5, 5, 5, 5);
            oExpenses.CurrencyId        = 5;
            oExpenses.ExpenseCategoryId = 5;
            oExpenses.ExpenseDetail     = new MEMCore.Domain.ExpenseDetail {
                Detail = "-- just an update++"
            };
            oExpenses.Signature = "JS";

            MEMCore.Services.IExpenseRepository srv = new MEMCore.Services.ExpenseRepository();
            var asynCallGetExpenses = Task.Run(() => srv.EditExpensesAsync(oExpenses, 1));

            asynCallGetExpenses.Wait();

            var asynExp = asynCallGetExpenses.Result;

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine($"Number of row affected after upate: {asynExp}");
            Console.ResetColor();
        }
Пример #2
0
        public static void NewExpenses()
        {
            var oExpenses = new MEMCore.Domain.Expense();

            oExpenses.ExpenseTitle      = "++++ Added new expense async";
            oExpenses.ExpensesAmount    = 100.20;
            oExpenses.ExpenseDate       = new DateTime(2019, 7, 5, 10, 10, 10);
            oExpenses.CurrencyId        = 1;
            oExpenses.ExpenseCategoryId = 5;
            oExpenses.PaymentMethod     = PaymentMethod.DirectDeposit;
            oExpenses.PaymentType       = PaymentType.Refunded;
            oExpenses.ExpenseDetail     = new MEMCore.Domain.ExpenseDetail {
                Detail = "after enum testing & fixing"
            };
            oExpenses.Signature = "DK";

            MEMCore.Services.IExpenseRepository srv = new MEMCore.Services.ExpenseRepository();
            var asynCallGetExpenses = Task.Run(() => srv.NewExpensesAsync(oExpenses));

            asynCallGetExpenses.Wait();

            var asynExp = asynCallGetExpenses.Result;

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine($"Number of row affected: {asynExp}");
            Console.ResetColor();
        }
Пример #3
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);
        }
Пример #4
0
        private static int NewExpenseWithoutDetails()
        {
            int result = -1;

            try
            {
                var oExp = new Domain.Expense();
                oExp.ExpenseTitle      = "1st expense for a test";
                oExp.ExpensesAmount    = 191.10;
                oExp.ExpenseDate       = new DateTime(2019, 12, 18, 16, 20, 20);
                oExp.CurrencyId        = 1;
                oExp.ExpenseCategoryId = 1;
                oExp.PaymentMethod     = Domain.PaymentMethod.Others;
                oExp.PaymentType       = Domain.PaymentType.Reimbursed;
                _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);
        }
Пример #5
0
        private static Domain.Expense GetExpensesById(int id)
        {
            var result = new Domain.Expense();

            try
            {
                var quary = _expContext.Expenses.OrderByDescending(x => x.ExpenseDate)
                            .Include(s => s.Category)
                            .Include(s => s.Currency)
                            //.Include(s => s.ExpenseDetail);
                            .Where(x => x.Id == id).FirstOrDefault();

                if (quary != null)
                {
                    result = quary;
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
                Console.ResetColor();
            }
            return(result);
        }