public ActionResult CreateDashboardUser(User userObj) { //assign phone number to object property userObj.PhoneNumber = userObj.PhoneNumber2; //assign user id to variable int currentUser = userData.UserId; // assign role to variable int roleId = userData.RoleId; //assign current user id to created by property userObj.CreatedBy = currentUser; //is delete property as false userObj.IsDelete = false; //encrypt password string passwordTemp = userObj.Password; UserAccess ua = new UserAccess(); DashBoardAccess da = new DashBoardAccess(); string newSalt = PasswordEncryption.RandomString(); userObj.Password = PasswordEncryption.encryptPassword(userObj.Password, newSalt); userObj.Email = userObj.NewEmail; //assign logged user's company id to created user's company id userObj.Company_Id = userData.Company_Id; //check user role is admin if (roleId == 2) { //assign logged user's branch id to created user's branch id userObj.BranchId = userData.BranchId; } //check created user is super admin and logged user is super admin if ((userObj.RoleId == 1)&&(userData.RoleId==1)) { //assign logged user's step status to created user's step status userObj.step_status = userData.step_status; } //check created user is admin else if (userObj.RoleId == 2) { //get step status for given branch id int step= ua.GetStepStatusByUserBranchId(userObj.BranchId); //check step is 0 or greater than 0 if(step>=0) { //assign step to created user's step status userObj.step_status = step; } } //check created user is user else if (userObj.RoleId == 3) { //check Session["LoanTitle"] is not null if (Session["LoanTitle"] != null) { //convert session to list List<Branch> loanList = (List<Branch>)Session["LoanTitle"]; for (var j = 0; j < loanList.Count; j++) { //check created user's loan id if (loanList[j].LoanId == userObj.LoanId) { foreach (Right rgt1 in userObj.UserRightsList) { //check title is needed to be tracked for created user's loan if (!loanList[j].IsTitleTrack && rgt1.rightId == "U02") { //assign title page rights as false if title is not needed to be tracked rgt1.active = false; } //check if there is atleast one fee for created user's loan if (!loanList[j].HasFee && rgt1.rightId == "U07") { //assign fee page rights as false if there is no atleast one fee rgt1.active = false; } } //check report rights according to the loan setup details foreach(Right rgt in userObj.ReportRightsList) { //check title need to be tracked and related right id if(!loanList[j].IsTitleTrack && rgt.rightId== "R04") { rgt.active = false; } //check loan has advance fee and related right id for advance fee invoice if (!loanList[j].HasAdvanceFee && rgt.rightId == "R07") { rgt.active = false; } //check loan has advance fee and related right id for advance fee receipt if (!loanList[j].HasAdvanceFee && rgt.rightId == "R08") { rgt.active = false; } //check loan has monthly fee and related right id for monthly fee invoice if (!loanList[j].HasMonthlyFee && rgt.rightId == "R09") { rgt.active = false; } //check loan has monthly fee and related right id for monthly fee receipt if (!loanList[j].HasMonthlyFee && rgt.rightId == "R10") { rgt.active = false; } //check loan has lot inspection fee and related right id for lot inspection fee invoice if (!loanList[j].HasLotFee && rgt.rightId == "R11") { rgt.active = false; } //check loan has lot inspection fee and related right id for lot inspection fee receipt if (!loanList[j].HasLotFee && rgt.rightId == "R12") { rgt.active = false; } } } } } //assign 1 for created user's step status userObj.step_status= 1; //assign selected branch id for created user's branch id userObj.BranchId = userObj.BranchIdUser; string[] arrList = new string[userObj.UserRightsList.Count]; string[] arrList2 = new string[userObj.ReportRightsList.Count]; int i = 0; int k = 0; //create user right list string by checking each right in right list active status foreach (var x in userObj.UserRightsList) { if (x.active) { arrList[i] = x.rightId; i++; } } //create user report right list string by checking each right in report right list active status foreach (var y in userObj.ReportRightsList) { if (y.active) { arrList2[k] = y.rightId; k++; } } arrList = arrList.Where(x => !string.IsNullOrEmpty(x)).ToArray(); userObj.UserRights = string.Join(",", arrList); //add report rights arrList2 = arrList2.Where(x => !string.IsNullOrEmpty(x)).ToArray(); userObj.ReportRights = string.Join(",", arrList2); } //Insert user details int res = da.InsertUserInDashboard(userObj); //check result of insert user function if (res > 0) { //update Companay Step States in incomplete Branches continued in dashboard StepAccess sa = new StepAccess(); sa.UpdateCompanySetupStep(userData.Company_Id, userObj.BranchId, 4); //if created user's status is active send email to inform his username and password if (userObj.Status) { string body = "Hi " + userObj.FirstName + "! <br /><br /> Your account has been successfully created. Below in your account detail." + "<br /><br /> User name: " + userObj.UserName + "<br /> Password : <b>" + passwordTemp + "<br /><br/> Thanks,<br /> Admin."; Email email = new Email(userObj.Email); email.SendMail(body, "Account details"); } string roleName = ""; //check created user is super admin if (userObj.RoleId == 1) { //assign role name as super admin roleName = "Super Admin"; } //check created user is admin else if (userObj.RoleId == 2) { //assign role name as admin roleName = "Admin"; } //check created user is user else if (userObj.RoleId == 3) { //assign role name as user roleName = "User"; } //insert log record Log log = new Log(userData.UserId, userData.Company_Id, userObj.BranchId, 0, "Create User", "Create "+roleName+" ,Username:"******"createUserResult"] = 1; //return RedirectToAction("CreateDashboardUser"); Session["LoanTitle"] = null; } else { TempData["createUserResult"] = 0; //return View(); } return RedirectToAction("CreateDashboardUser"); }