예제 #1
0
        public IActionResult AddUsers(AppUser appUser)
        {
            var errors        = new List <string>();
            var appUserAccess = new AppUserAccess(_appConfiguration)
            {
                ExpenseConnection = _expenseConnection
            };
            var userPassword = System.Guid.NewGuid().ToString().Substring(0, 5);

            try
            {
                appUser.Password = userPassword;
                _expenseConnection.BeginTransaction();
                appUserAccess.Insert(appUser);
                _expenseConnection.Commit();

                _logger.LogInformation("User : {username} added new user '{appUsername}'", LoggedInUser, appUser.Username);
            }
            catch (CustomExceptions Ex)
            {
                _logger.LogWarning("User : {username} get validation exception while adding user with name '{appUsername}' ", LoggedInUser, appUser.Username);

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

                errors = (List <string>)Ex.Data["errors"];
            }
            catch (Exception Ex)
            {
                _logger.LogWarning("User : {username} get exception while adding appuser with name '{appUsername}' ", LoggedInUser, appUser.Username);

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

                LogExecption(Ex, _expenseConnection);

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

            return(Json(new
            {
                success = (errors.Count == 0),
                data = appUser,
                error = errors
            }));
        }
예제 #2
0
        public IActionResult CreateCategory(Category category)
        {
            var errors         = new List <string>();
            var categoryAccess = new CategoryAccess()
            {
                ExpenseConnection = _expenseConnection
            };

            try
            {
                _expenseConnection.BeginTransaction();
                categoryAccess.Insert(category);
                _expenseConnection.Commit();

                _logger.LogInformation("User : {username} added new category '{categoryname}'", LoggedInUser, category.Name);
            }
            catch (CustomExceptions Ex)
            {
                _logger.LogWarning("User : {username} get validation exception while adding category with name '{categoryname}' ", LoggedInUser, category.Name);

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

                errors = (List <string>)Ex.Data["errors"];
            }
            catch (Exception Ex)
            {
                _logger.LogWarning("User : {username} get exception while adding category with name '{categoryname}' ", LoggedInUser, category.Name);

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

                LogExecption(Ex, _expenseConnection);

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

            return(Json(new
            {
                success = (errors.Count == 0),
                data = category,
                error = errors
            }));
        }
예제 #3
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 }));
        }
예제 #4
0
        public IActionResult ChangePassword(ChangePassword changePassword)
        {
            var errors = new List <String>();
            var changePasswordAccess = new ChangePasswordAccess(_appConfiguration)
            {
                ExpenseConnection = _expenseConnection
            };

            try
            {
                _expenseConnection.BeginTransaction();
                changePasswordAccess.ChangePassword(changePassword);
                _expenseConnection.Commit();
            }
            catch (CustomExceptions Ex)
            {
                _logger.LogWarning("User : {username} get exception while changing the password", LoggedInUser);

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

                errors = (List <string>)Ex.Data["errors"];
            }
            catch (Exception Ex)
            {
                _logger.LogWarning("User : {username} get exception while changing the password", LoggedInUser);

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

                LogExecption(Ex, _expenseConnection);

                errors = new List <string>()
                {
                    Ex.Message
                };
            }

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