Esempio n. 1
0
        private ExpenseDTO Create(ExpenseViewModel viewModel)
        {
            try
            {
                log.Debug(ExpenseViewModel.FormatExpenseViewModel(viewModel));

                ExpenseDTO expense = new ExpenseDTO();

                // copy values
                viewModel.UpdateDTO(expense, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                expense.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                expense.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_expenseService.AddExpense - " + ExpenseDTO.FormatExpenseDTO(expense));

                int id = _expenseService.AddExpense(expense);

                expense.ExpenseId = id;

                log.Debug("result: 'success', id: " + id);

                return(expense);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Esempio n. 2
0
        private ExpenseDTO Update(ExpenseViewModel viewModel)
        {
            try
            {
                log.Debug(ExpenseViewModel.FormatExpenseViewModel(viewModel));

                // get
                log.Debug("_expenseService.GetExpense - expenseId: " + viewModel.ExpenseId + " ");

                var existingExpense = _expenseService.GetExpense(viewModel.ExpenseId);

                log.Debug("_expenseService.GetExpense - " + ExpenseDTO.FormatExpenseDTO(existingExpense));

                if (existingExpense != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingExpense, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_expenseService.UpdateExpense - " + ExpenseDTO.FormatExpenseDTO(existingExpense));

                    _expenseService.UpdateExpense(existingExpense);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingExpense: null, ExpenseId: " + viewModel.ExpenseId);
                }

                return(existingExpense);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }