Пример #1
0
        public IActionResult FindUserById(int id)
        {
            var errors        = new List <string>();
            var appUserAccess = new AppUserAccess(_appConfiguration)
            {
                ExpenseConnection = _expenseConnection
            };
            var appUser = new AppUser();

            try
            {
                appUser = _expenseConnection.Get <AppUser>(id);
                _logger.LogInformation("User : {username} fetches the user id : {id}", LoggedInUser, id);
            }
            catch (Exception ex)
            {
                _logger.LogInformation("User : {username} gets expection while trying to fetch the userid : {id}", LoggedInUser, id);

                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 GetUsers()
        {
            var errors        = new List <string>();
            var appUserAccess = new AppUserAccess(_appConfiguration)
            {
                ExpenseConnection = _expenseConnection
            };
            IEnumerable <AppUser> userList = null;

            try
            {
                userList = appUserAccess.getAllUsers();
                _logger.LogInformation("User : {username} fetches all users", LoggedInUser);
            }
            catch (Exception ex)
            {
                _logger.LogInformation("User : {username} gets expection while trying to fetch all user", LoggedInUser);

                LogExecption(ex, _expenseConnection);

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

            return(Json(new
            {
                success = (errors.Count == 0),
                data = userList,
                loggedInId = GetLoggedUserId,
                error = errors
            }));
        }
Пример #3
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
            }));
        }
Пример #4
0
        public IActionResult EditUsers(AppUser appUser)
        {
            var errors        = new List <string>();
            var appUserAccess = new AppUserAccess(_appConfiguration)
            {
                ExpenseConnection = _expenseConnection
            };

            try
            {
                _expenseConnection.BeginTransaction();
                appUserAccess.Update(appUser);
                _expenseConnection.Commit();

                _logger.LogInformation("User : {username} updated  user '{appUsername}' details", LoggedInUser, appUser.Username);
            }
            catch (CustomExceptions Ex)
            {
                _logger.LogWarning("User : {username} get validation exception while updating 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 updating 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
            }));
        }
        public async Task <IActionResult> Login(AppUser appUser)
        {
            var errors = new List <string>();

            try
            {
                AppUserAccess appUserAccess = new AppUserAccess(_appConfiguration)
                {
                    ExpenseConnection = _expenseConnection
                };

                if (appUserAccess.VerifyUser(ref appUser))
                {
                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.Name, appUser.Username),
                        new Claim(ClaimTypes.PrimarySid, appUser.Id.ToString())
                    };

                    var userIdentity = new ClaimsIdentity(claims, "login");

                    ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
                    await HttpContext.SignInAsync(principal);

                    return(Json(new
                    {
                        success = true,
                        data = appUser,
                        error = errors
                    }));
                }
            }
            catch (Exception ex)
            {
                if (_expenseConnection.InTransaction)
                {
                    _expenseConnection.RollBack();
                }
            }
            return(Json(new { success = false, error = errors }));
        }