Пример #1
0
        public IActionResult AddExpenses(Expenses expenses)
        {
            var errors        = new List <string>();
            var expenseAccess = new ExpensesAccess()
            {
                ExpenseConnection = _expenseConnection
            };

            try
            {
                expenses.AddedBy    = GetLoggedUserId;
                expenses.PostedDate = DateTime.Now;
                _expenseConnection.BeginTransaction();
                expenseAccess.Insert(expenses);
                _expenseConnection.Commit();

                _logger.LogInformation("User: { username}added new expense of '{category}'", LoggedInUser, expenses.Category);
            }
            catch (CustomExceptions ex)
            {
                _logger.LogInformation("User : {username} get validation exception while adding expenses of category '{categoryname}' ", LoggedInUser, expenses.Category);

                if (_expenseConnection.InTransaction)
                {
                    _expenseConnection.RollBack();
                }

                errors = (List <string>)ex.Data["errors"];
            }
            catch (Exception Ex)
            {
                _logger.LogInformation("User : {username} get exception while adding expenses of category '{categoryname}' ", LoggedInUser, expenses.Category);

                if (_expenseConnection.InTransaction)
                {
                    _expenseConnection.RollBack();
                }

                LogExecption(Ex, _expenseConnection);

                errors = new List <string>()
                {
                    _appConfiguration.Messages.InternalServerError
                };
            }

            return(Json(new { success = (errors.Count == 0), data = expenses, error = errors }));
        }
Пример #2
0
        public IActionResult DeleteExpense(int id)
        {
            var errors        = new List <String>();
            var expenseAccess = new ExpensesAccess()
            {
                ExpenseConnection = _expenseConnection
            };

            try
            {
                _expenseConnection.BeginTransaction();
                expenseAccess.Delete(id);
                _expenseConnection.Commit();
            }
            catch (Exception ex)
            {
                _logger.LogWarning("User : {username} get exception while deleting expenses.", LoggedInUser);

                if (_expenseConnection.InTransaction)
                {
                    _expenseConnection.RollBack();
                }

                LogExecption(ex, _expenseConnection);

                errors = new List <string>()
                {
                    _appConfiguration.Messages.InternalServerError
                };
            }

            return(Json(new
            {
                success = (errors.Count == 0),
                data = "",
                error = errors
            }));
        }