public async Task <IActionResult> SystemUsers(SystemUsersViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            var user = await _userManager.GetUserAsync(User);

            var branchStaff = await _systemAdminService.GetBranchStaff(string.Empty);

            if (!ModelState.IsValid)
            {
                ViewData["Branches"] = new SelectList(_setupService.GetBranchNames(user.UserName));
                ViewData["Roles"]    = new SelectList(_roleManager.Roles);
                ViewData["Staff"]    = new SelectList(branchStaff);
                return(View(model));
            }

            model.ActionBy = user.UserName;
            Result         = await _systemAdminService.CreateSystemUserAsync(model);

            if (Result == true)
            {
                StatusMessage = _config.GetSection("Messages")["Success"];
                return(RedirectToAction(nameof(SystemUsers)));
            }

            model = new SystemUsersViewModel {
                StatusMessage = "Error: Unable to create user account"
            };
            ViewData["Branches"] = new SelectList(_setupService.GetBranchNames(user.UserName));
            ViewData["Roles"]    = new SelectList(_roleManager.Roles);
            ViewData["Staff"]    = new SelectList(branchStaff);
            return(View(model));
        }
示例#2
0
        public bool MaintainSystemUser(SystemUsersViewModel model)
        {
            string userModel   = JsonConvert.SerializeObject(model);
            var    contentData = new StringContent(userModel, System.Text.Encoding.UTF8, "application/json");

            response = client.PostAsync("api.bankmodel/systemadmin/maintainsystemuser", contentData).Result;
            return(response.StatusCode == System.Net.HttpStatusCode.OK ? true : false);
        }
 public async Task<IActionResult> UpdateSystemUser(SystemUsersViewModel model)
 {
     var result = await _systemAdminRepository.UpdateSystemUserAsync(model);
     if (result == "Successful")
     {
         return Ok();
     }
     return BadRequest();
 }
示例#4
0
        protected async Task <bool> ValidateSystemUser(SystemUsersViewModel model)
        {
            //Check if the proposed Username exist already
            var userResult = await _userManager.FindByNameAsync(model.Username.ToLower());

            if (userResult != null)
            {
                _validationDictionary.AddError("", string.Format(_config.GetSection("Messages")["ObjectExist"], model.Username));
            }

            return(_validationDictionary.IsValid);
        }
        public async Task <string> CreateSystemUserAsync(SystemUsersViewModel model)
        {
            try
            {
                //Get the customer number from the name
                var customerNo = GetCustomerNoFromName(model.Staff);
                var profile    = _context.Profile.Where(p => p.ID == customerNo).Include(b => b.Branch).FirstOrDefault();

                string status     = "PENDING";
                string approvedBy = string.Empty;
                if (model.ActivateUser == true)
                {
                    status     = "ACTIVE";
                    approvedBy = model.ActionBy.ToUpper();
                }

                ApplicationUser newUser = new ApplicationUser
                {
                    ApprovedBy         = approvedBy,
                    Email              = profile.Email.ToLower(),
                    UserName           = model.Username,
                    PasswordExpiryDate = DateTime.UtcNow.Date.AddDays(GetPasswordValidityDays()),
                    PhoneNumber        = profile.PhoneNumber,
                    Profile            = profile,
                    TransactionLimit   = model.TransactionLimit,
                    ApprovalLimit      = model.ApprovalLimit,
                    Status             = status,
                    EmailConfirmed     = true,
                    PostedBy           = model.ActionBy.ToUpper(),
                    TransDate          = Convert.ToDateTime(GetTransactionDate())
                };
                var result = await _userManager.CreateAsync(newUser, _config.GetSection("AppInfo")["AdminPassword"]);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(newUser, model.Role);

                    //Add claims if user is a Head Office staff
                    if (profile.Branch.BranchCode == "00")
                    {
                        await _userManager.AddClaimAsync(newUser, new Claim("HeadOfficeStaff", "Yes"));
                    }
                }
                await _context.SaveChangesAsync();

                return("Succeeded");
            }
            catch { return("Failed"); }
        }
示例#6
0
        public async Task <bool> UpdateSystemUserAsync(SystemUsersViewModel model)
        {
            var result = await ValidateSystemUser(model);

            if (!result)
            {
                return(false);
            }

            string userModel   = JsonConvert.SerializeObject(model);
            var    contentData = new StringContent(userModel, System.Text.Encoding.UTF8, "application/json");

            response = client.PutAsync("api.bankmodel/systemadmin/updatesystemuser", contentData).Result;
            return(response.StatusCode == System.Net.HttpStatusCode.OK ? true : false);
        }
        public async Task <string> UpdateSystemUserAsync(SystemUsersViewModel model)
        {
            try
            {
                var user = _context.ApplicationUser.Where(u => u.Id == model.ID).FirstOrDefault();
                user.TransactionLimit = model.TransactionLimit;
                user.ApprovalLimit    = model.ApprovalLimit;
                user.UserName         = model.Username.ToUpper();
                user.TransDate        = user.TransDate;
                user.Status           = "PENDING";
                user.PostedBy         = model.ActionBy.ToUpper();
                await _userManager.UpdateAsync(user);

                await _context.SaveChangesAsync();

                return("Succeeded");
            }
            catch { return("Failed"); }
        }
        public async Task <IActionResult> SystemUsers()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            ViewData["Branches"] = new SelectList(_setupService.GetBranchNames(user.UserName));
            ViewData["Roles"]    = new SelectList(_roleManager.Roles);
            var branchStaff = await _systemAdminService.GetBranchStaff(string.Empty);

            ViewData["Staff"] = new SelectList(branchStaff);

            var model = new SystemUsersViewModel {
                StatusMessage = StatusMessage
            };

            return(View(model));
        }
        public string MaintainSystemUser(SystemUsersViewModel model)
        {
            try
            {
                var user = _context.ApplicationUser.Where(u => u.UserName == model.Username).Include(p => p.Profile).Include(b => b.Profile.Branch).FirstOrDefault();
                if (user != null)
                {
                    if (model.MaintenanceType == "RESET PASSWORD")
                    {
                        _userManager.ResetPasswordAsync(user, "", _config.GetSection("AppInfo")["AdminPassword"]);
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " PASSWORD RESET", "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "UPDATE TRANSACTION LIMIT")
                    {
                        decimal oldLimit = user.ApprovalLimit;
                        user.TransactionLimit = model.LimitField;
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " TRANSACTION LIMIT UPDATED FROM " + oldLimit + " TO " + model.LimitField.ToString("#,##0.00"), "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "UPDATE APPROVAL LIMIT")
                    {
                        decimal oldLimit = user.ApprovalLimit;
                        user.ApprovalLimit = model.LimitField;
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " APPROVAL LIMIT UPDATED FROM " + oldLimit + " TO " + model.LimitField.ToString("#,##0.00"), "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "CLEAR LOGIN")
                    {
                        user.UserOnline = false;
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " CLEARED FROM LOGIN", "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "MAKE PASSWORD EXPIRE")
                    {
                        user.PasswordExpiryDate = DateTime.Now.Date;
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " PASSWORD SET TO EXPIRE ON " + DateTime.Now.Date, "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "DISABLE USER")
                    {
                        user.Status = "DISABLED";
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " DISABLED", "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "ENABLE USER")
                    {
                        user.Status = "ACTIVE";
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " ENABLED", "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "CHANGE BRANCH")
                    {
                        var    branch        = _context.Branch.Where(b => b.BranchDesc == model.NewBranch).FirstOrDefault();
                        string oldBranchCode = user.Profile.Branch.BranchCode;
                        user.Profile.Branch = branch;
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " BRANCH CHANGED FROM " + oldBranchCode + " TO " + user.BranchCode, "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }

                    if (model.MaintenanceType == "EXTEND PASSWORD EXPIRY")
                    {
                        user.PasswordExpiryDate = user.PasswordExpiryDate.AddDays(model.PasswordDays);
                        _context.SaveChanges();
                        //UpdateAuditLog(postedBy.ToUpper(), model.AppUser + " PASSWORD EXTENDED BY " + model.PasswordDays + " DAYS", "SYSTEM ADMIN", "MAINTENANCE", clientIP, "999", DateTime.Now);
                    }
                }
                return("Succeeded");
            }
            catch { return("Failed"); }
        }