public ActionResult Create(CreateAgentViewModel createAgentViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var isUser = _iUserMaster.CheckUsernameExists(createAgentViewModel.UserName);

                    if (createAgentViewModel.CategoryId == null)
                    {
                        ModelState.AddModelError("", "Select Category");
                    }
                    else if (isUser)
                    {
                        ModelState.AddModelError("", "Username already exists");
                    }
                    else
                    {
                        var usermaster = AutoMapper.Mapper.Map <Usermaster>(createAgentViewModel);
                        usermaster.Status       = true;
                        usermaster.CreateDate   = DateTime.Now;
                        usermaster.UserId       = 0;
                        usermaster.CreatedBy    = Convert.ToInt32(_sessionHandler.UserId);
                        usermaster.IsFirstLogin = true;

                        var salt           = GenerateRandomNumbers.RandomNumbers(20);
                        var saltedpassword = GenerateHashSha512.Sha512(createAgentViewModel.Password, salt);

                        var savedAssignedRoles = new SavedAssignedRoles()
                        {
                            RoleId         = Convert.ToInt16(StatusMain.Roles.Agent),
                            AssignedRoleId = 0,
                            Status         = true,
                            CreateDate     = DateTime.Now
                        };

                        var result = _iUserMaster.AddAgent(usermaster, saltedpassword, savedAssignedRoles, createAgentViewModel.CategoryId, salt);

                        if (result > 0)
                        {
                            TempData["MessageCreateUsers"] = "Agent Created Successfully";
                            return(RedirectToAction("Create", "CreateAgent"));
                        }
                        else
                        {
                            return(View(createAgentViewModel));
                        }
                    }

                    createAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    return(View("Create", createAgentViewModel));
                }
                else
                {
                    createAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    return(View("Create", createAgentViewModel));
                }
            }
            catch
            {
                throw;
            }
        }