public IActionResult Delete() { bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; ViewBag.error = "Still A viewbag CHANGE"; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin == "Yes") { ViewBag.username = QUToolsUtilities.QueryString("uid"); return(View()); } else { curPage.errorMsg = "You do not appear to be an Administrator. "; return(RedirectToAction("Index", "VideoBackend", curPage)); } }
public void EditPostEmptyMembershipProviderIdReturnsViewOnException() { var adminRepository = new LocalRepository <InsideUser>(); var userManager = new Mock <IIdentityMembershipProvider>(); var accountManagerInRepository = ModelHelper.TestAccountManager; accountManagerInRepository.Id = null; adminRepository.Add(accountManagerInRepository); var controller = new AccountManagerController(adminRepository, userManager.Object); var accountManager1 = new AccountManagerViewModel() { Name = accountManagerInRepository.Name, Id = accountManagerInRepository.Id, Password = "******", Email = "*****@*****.**" }; userManager.Setup(u => u.GetUsers()).Returns(adminRepository.All); userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository); userManager.Setup(u => u.Create(It.IsAny <InsideUser>(), "Test Edited")).Returns(false).Verifiable(); var result = controller.Edit(accountManager1) as ViewResult; Assert.IsTrue(controller.ModelState.Count > 0); }
public IActionResult Delete(string deluser) { bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin == "Yes") { curPage.errorMsg = AccountManager.delUser(deluser, curUser.userTable); TempData["error"] = curPage.errorMsg; return(RedirectToAction("UserPage", "VideoBackend", curPage)); } else { curPage.errorMsg = "You do not appear to be an Administrator. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } }
public void CreatePostReturnsToViewIfUserAlreadyExists() { var adminRepository = new Mock <LocalRepository <InsideUser> > { CallBase = true }; var userManager = new Mock <IIdentityMembershipProvider>(); var controller = new AccountManagerController(adminRepository.Object, userManager.Object); var accountManager1 = new AccountManagerViewModel() { Id = "Id1", Name = "Test AM", Email = "*****@*****.**", Password = "******" }; userManager.Setup(u => u.GetUsers()).Returns(adminRepository.Object.All); userManager.Setup(u => u.Create(It.IsAny <InsideUser>(), "Test")).Returns(false).Verifiable(); var result = controller.Create(accountManager1) as ViewResult; Assert.IsTrue(controller.ModelState.Count > 0); }
public void EditPostSavesDataForOkDataWithEmptyMembershipProviderId() { var adminRepository = new LocalRepository <InsideUser>(); var userManager = new Mock <IIdentityMembershipProvider>(); var accountManagerInRepository = ModelHelper.TestAccountManager; accountManagerInRepository.Id = null; accountManagerInRepository.PasswordHash = "HashedOldPassword"; adminRepository.Add(accountManagerInRepository); var controller = new AccountManagerController(adminRepository, userManager.Object); var accountManager1 = new AccountManagerViewModel() { Name = accountManagerInRepository.Name, Id = accountManagerInRepository.Id, Password = "******", Email = "*****@*****.**" }; userManager.Setup(u => u.GetUsers()).Returns(adminRepository.All); userManager.Setup(u => u.FindById(accountManagerInRepository.Id)).Returns(accountManagerInRepository); userManager.Setup(u => u.UpdatePassword(accountManagerInRepository.Id, "Test Edited")).Returns(true).Verifiable(); userManager.Setup(u => u.Create(accountManagerInRepository, "Test Edited")).Returns(true).Verifiable(); var result = controller.Edit(accountManager1) as ViewResult; /* userManager.Verify(u => u.RemovePassword(accountManagerInRepository.Id), Times.Once);*/ userManager.Verify(u => u.UpdatePassword(accountManagerInRepository.Id, "Test Edited"), Times.Never); userManager.Verify(u => u.Create(It.IsAny <InsideUser>(), "Test Edited"), Times.Once); Assert.AreEqual("*****@*****.**", adminRepository.All().First().Email); }
public IActionResult AddLink(string alltags, string title, string URL, string duration, DateTime datecompleted, string videotype, string description) { bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } bool _test1 = String.IsNullOrEmpty(title); bool _test2 = String.IsNullOrEmpty(URL); bool _test3 = String.IsNullOrEmpty(duration); bool _test4 = String.IsNullOrEmpty(videotype); bool _test5 = String.IsNullOrEmpty(description); if (_test1 || _test2 || _test3 || _test4 || _test5) { TempData["error"] = "It appears you missed a field. Make sure all fields are filled out"; return(RedirectToAction("AddLink", "VideoBackend")); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin != "Yes") { curPage.errorMsg = "An error has occured, please try again. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } VideoBackendViewModel videoMetaData = new VideoBackendViewModel(); VideoBackEnd VBM = new VideoBackEnd(); string[] tagArray; videoMetaData.VideoName = title; videoMetaData.URL = URL; videoMetaData.Duration = duration; videoMetaData.DateCompleted = datecompleted; videoMetaData.VideoType = videotype; videoMetaData.VideoDescription = description; tagArray = VBM.parseTags(alltags); string x = VBM.processEntry(videoMetaData, tagArray, curUser.username); TempData["error"] = x; return(RedirectToAction("AddLink", "VideoBackend", curPage)); }
public void CreatePostCanCreateNewAccountManager() { var adminRepository = new Mock <LocalRepository <InsideUser> > { CallBase = true }; var userManager = new Mock <IIdentityMembershipProvider>(); var controller = new AccountManagerController(adminRepository.Object, userManager.Object); var accountManager1 = new AccountManagerViewModel() { Id = "Id1", Name = "Test AM", Email = "*****@*****.**", Password = "******" }; userManager.Setup(u => u.GetUsers()).Returns(adminRepository.Object.All); userManager.Setup(u => u.Create(It.IsAny <InsideUser>(), "Test")).Returns(true).Verifiable(); var result = controller.Create(accountManager1) as ViewResult; //Assert.IsTrue(adminRepository.Object.All().Any(u => u.Id == guid)); userManager.Verify(um => um.Create(It.IsAny <InsideUser>(), "Test"), Times.Once); userManager.Verify(um => um.AddToRole(It.IsAny <string>(), "sales"), Times.Once); }
// GET: AccountManager, account manager home page public async Task <IActionResult> Index(AccountManagerViewModel accountManagerViewModel) { var accountSearchData = accountManagerViewModel.AccountSearch; var message = GetResultMsg(accountManagerViewModel.ResultStatus); return(View(await CreateAccountManagerViewModel(accountSearchData, message))); }
public AccountManagerViewModel setUserLevel(AccountManagerViewModel user) { AccountManagerViewModel myConn = user; try { using (SqlConnection con = new SqlConnection(QUToolsUtilities.GetConnectionString("internet"))) { con.Open(); string sqlstr = "UPDATE {0} SET userlevel=@ul"; sqlstr = String.Format(sqlstr, user.userTable); SqlCommand da = new SqlCommand(sqlstr, con); da.Parameters.AddWithValue("@ul", user.userlevel); da.ExecuteNonQuery(); } myConn.returnMsg = "User Level updated"; return(myConn); } catch (Exception e) { myConn.returnMsg = e.Message; return(myConn); } }
public IActionResult UserPage() { ViewData["user"] = login.returnUsername(); // Check Session ID & (eventually all databases for users) bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin == "Yes") { curUser = AccountManager.getUsers(curUser); return(View(curUser.userlist)); } else { TempData["error"] = "You do not appear to be an Administrator. "; return(RedirectToAction("Index", "VideoBackend")); } }
public void CreatePostReturnsErrorFroEmptyPassword() { var adminRepository = new Mock <IRepository <InsideUser> >(); var userManager = new Mock <IIdentityMembershipProvider>(); var controller = new AccountManagerController(adminRepository.Object, userManager.Object); var userPostData = new AccountManagerViewModel(); var result = controller.Create(userPostData) as ViewResult; Assert.IsTrue(controller.ModelState.Values.First().Errors.First().ErrorMessage == "Ange lösenord"); }
public IActionResult jayAdmin(string deleteThese) { #region login bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin != "Yes" && curUser.username == "jamunro") { curPage.errorMsg = "An error has occured, please try again. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } #endregion VideoBackendViewModel videodata = new VideoBackendViewModel(); VideoBackEnd videomethods = new VideoBackEnd(); string[] tags = deleteThese.Split('|'); foreach (var t in tags) { if (t != "") { videomethods.deletetag(t); } } TempData["error"] = " Deleted " + deleteThese; videodata = videomethods.jayAllTags(videodata); return(View(videodata)); }
public ActionResult MainMenu() { //checks if the session id is valid bool result = login.checkSession(); if (result == false) { TempData["error"] = login.connectionReturn; return(RedirectToAction("Index", "VideoBackend")); } curUser.username = login.returnUsername(); ViewData["user"] = curUser.username; curUser.userTable = userdb; if (result == false) { return(RedirectToAction("Index", "VideoBackend")); } string error = QUToolsUtilities.QueryString("errors"); if (error != null) { ViewBag.Error = error; } AccountManagerViewModel sqlStuff = new AccountManagerViewModel(); sqlStuff = AccountManager.checkUser(curUser); if (sqlStuff.userlevel == null) { curPage.errorMsg = "You do not appear to have rights to access this Tool. "; ViewBag.errorMsg = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } if (curUser.Admin != "Yes") { curPage.errorMsg = "You do not appear to be an Administrator. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } return(View()); }
} //end of checkAdmin() public AccountManagerViewModel checkUser(AccountManagerViewModel User) { AccountManagerViewModel myConn = User; string sqlCmd; try { using (SqlConnection connection = new SqlConnection(QUToolsUtilities.GetConnectionString("internet"))) { connection.Open(); string username = QUToolsUtilities.GetSession("QToolsUser"); sqlCmd = "select * from {0} where QU_User = @qun"; sqlCmd = String.Format(sqlCmd, User.userTable); SqlCommand command = new SqlCommand(sqlCmd, connection); command.Parameters.AddWithValue("@qun", User.username); //command.Parameters.AddWithValue("@db", User.userTable); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader["QU_User"].ToString() == username && reader["toolAdmin"].ToString() == "N") { myConn.Admin = "No"; myConn.username = username; myConn.userlevel = reader["userlevel"].ToString(); return(myConn); } else { myConn.Admin = "Yes"; myConn.username = username; myConn.userlevel = reader["userlevel"].ToString(); return(myConn); } } } connection.Close(); } } catch (Exception e) { myConn.returnMsg = e.Message; return(myConn); } return(myConn); } //end of checkUser()
public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userMembershipToDelete = userManager.FindById(id); if (userMembershipToDelete == null) { return(HttpNotFound()); } var accountManagerViewModel = new AccountManagerViewModel(userManager.GetRoles(User.Identity.GetUserId())); accountManagerViewModel.Name = userMembershipToDelete.Name; return(View(accountManagerViewModel)); }
public IActionResult UserPage(string QU_User, string QUID, string Admin, string PlacementLang, string PlacementMath, string PlacementMathCounts, string PlacementMathQuery) { ViewData["user"] = login.returnUsername(); bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; ViewBag.Msg = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (QU_User == "") { ViewBag.Msg = "Please enter QU Username"; return(View()); } if (QUID == "") { ViewBag.Msg = "Please enter QU ID"; return(View()); } AccountManager newuser = new AccountManager(); curUser.username = QU_User; curUser.quID = QUID; curUser.Admin = Admin; //curUser.userlevel = PX_Tools.PX_UserLevelReverse(PX_Attributes); Console.Write("d"); curUser = AccountManager.addUser(curUser); curUser = AccountManager.getUsers(curUser); ViewBag.Msg = curUser.returnMsg; return(View(curUser.userlist)); }
public ActionResult Create(AccountManagerViewModel admin) { if (String.IsNullOrEmpty(admin.Password)) { ModelState.AddModelError("password", "Ange lösenord"); } if (!ModelState.IsValid) { return(View(admin)); } try { var newAccountManager = new InsideUser { Email = admin.Email, UserName = admin.Email, /*LoweredUserName = admin.Name.ToLower(),*/ Name = admin.Name, ImageUrl = admin.ImageUrl, Phone = admin.Phone }; var newUserCreateSuccess = userManager.Create(newAccountManager, admin.Password); if (newUserCreateSuccess) { userManager.AddToRole(newAccountManager.Id, "sales"); } else { ModelState.AddModelError("Email", "Kontoansvarig finns redan."); return(View(admin)); } /* adminRepository.Add(newAccountManager); * adminRepository.SaveChanges();*/ return(RedirectToAction("Index")); } catch (Exception e) { ModelState.AddModelError("Email", "Kontoansvarig finns redan."); return(View(admin)); } }
public ActionResult Index() { var accountManagers = new AccountManagerListViewModel(userManager.GetRoles(User.Identity.GetUserId())); foreach (var admin in userManager.GetUsers().Where(u => u.Role.Any(r => r.Name == "sales"))) { var accountManagerViewModel = new AccountManagerViewModel { Id = admin.Id, Email = admin.Email, ImageUrl = admin.ImageUrl, Name = admin.Name, Phone = admin.Phone, IsLockedOut = admin.IsLockedOut }; accountManagers.Collection.Add(accountManagerViewModel); } return(View(accountManagers)); }
public IActionResult EditLink(string id) { bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin != "Yes") { curPage.errorMsg = "An error has occured, please try again. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } VideoBackendViewModel videodata = new VideoBackendViewModel(); VideoBackEnd videomethods = new VideoBackEnd(); videodata = videomethods.listVideos(id); videodata = videomethods.getAllTags(videodata); videodata.vidID = id; videodata = videomethods.getTagsForVideo(videodata); TempData["error"] = videodata.returnMsg; return(View(videodata)); }
public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var admin = userManager.FindById(id); if (admin == null) { return(HttpNotFound()); } var accountManagerViewModel = new AccountManagerViewModel(userManager.GetRoles(User.Identity.GetUserId())) { Name = admin.Name, Phone = admin.Phone, ImageUrl = admin.ImageUrl, Email = admin.Email, Password = "" }; return(View(accountManagerViewModel)); }
public IActionResult AddLink() { bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin != "Yes") { curPage.errorMsg = "An error has occured, please try again. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } VideoBackendViewModel taglist = new VideoBackendViewModel(); VideoBackEnd VBM = new VideoBackEnd(); taglist = VBM.getAllTags(taglist); return(View(taglist)); }
public AccountManagerViewModel getUsers(AccountManagerViewModel user) { AccountManagerViewModel users = user; users.userlist = new List <AccountManagerViewModel>(); try { using (SqlConnection con = new SqlConnection(QUToolsUtilities.GetConnectionString("internet"))) { con.Open(); string sqlcmd = "SELECT * FROM {0}"; sqlcmd = String.Format(sqlcmd, user.userTable); SqlCommand da = new SqlCommand(sqlcmd, con); using (SqlDataReader reader = da.ExecuteReader()) { while (reader.Read()) { users.userlist.Add(new AccountManagerViewModel { /// Note: Not sure why i'm using List_user quid etc... list_user = reader["QU_User"].ToString(), list_QUID = reader["QUID"].ToString(), list_admin = reader["toolAdmin"].ToString(), list_userlevel = reader["userlevel"].ToString() }); } return(users); } } } catch (Exception e) { users.returnMsg = e.Message; return(users); } }
public AccountManagerViewModel CheckAdmin(AccountManagerViewModel user) { AccountManagerViewModel myConn = user; //new AccountManager(); Login myLogin = new Login(); string sqlCmd; using (SqlConnection connection = new SqlConnection(QuToolsUtilities.GetConnectionString("internet"))) { connection.Open(); string username = myLogin.ReturnUsername(); sqlCmd = "select * from {0} where QU_User = @qun"; sqlCmd = String.Format(sqlCmd, user.UserTable); //, User.username); SqlCommand command = new SqlCommand(sqlCmd, connection); command.Parameters.AddWithValue("@qun", user.Username); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader["QU_User"].ToString() == username && reader["toolAdmin"].ToString() == "Y") { myConn.Admin = "Yes"; myConn.Userlevel = reader["userlevel"].ToString(); return(myConn); } } } connection.Close(); } return(myConn); } //end of checkAdmin()
public AddNewAccountCommand(AccountManagerViewModel viewModel) { _viewModel = viewModel; }
public IActionResult addTag(string alltags, string delTags) { bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin != "Yes") { curPage.errorMsg = "An error has occured, please try again. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } VideoBackendViewModel videoMetaData = new VideoBackendViewModel(); VideoBackEnd VBM = new VideoBackEnd(); if (delTags != "na") { string[] tags = delTags.Split('|'); foreach (var t in tags) { if (t != "") { VBM.deletetag(t); } } TempData["error"] = "Deleted Tags"; return(RedirectToAction("MainMenu", "VideoBackend", curPage)); } if (alltags == "na") { TempData["error"] = "No tags entered..."; return(RedirectToAction("MainMenu", "VideoBackend", curPage)); } string[] tagArray; tagArray = VBM.parseTags(alltags); string x = VBM.processNewTags(tagArray); TempData["error"] = "Success"; if (x != "Success") { TempData["error"] = "Unable to add. " + x; } return(RedirectToAction("MainMenu", "VideoBackend", curPage)); }
public IActionResult EditLink(string alltags, string vidID, string title, string URL, string duration, DateTime datecompleted, string videotype, string description, string delete) { bool result = login.checkSession(); if (result == false) { curPage.errorMsg = "Either you do not have access to these tools or your session has timed out..."; TempData["error"] = curUser.returnMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } AccountManager sqlStuff = new AccountManager(); login userInformation = new login(); curUser.username = login.returnUsername(); curUser.userTable = userdb; curUser = AccountManager.checkAdmin(curUser); if (curUser.Admin != "Yes") { curPage.errorMsg = "An error has occured, please try again. "; //AccountManager curUser = new AccountManager(); TempData["error"] = curPage.errorMsg; return(RedirectToAction("Index", "VideoBackend", curPage)); } VideoBackendViewModel videoMetaData = new VideoBackendViewModel(); VideoBackEnd VBM = new VideoBackEnd(); try { string[] tagArray; videoMetaData.VideoName = title; videoMetaData.URL = URL; videoMetaData.Duration = duration; videoMetaData.DateCompleted = datecompleted; videoMetaData.VideoType = videotype; videoMetaData.VideoDescription = description; videoMetaData.vidID = vidID; tagArray = VBM.parseTags(alltags); string y = VBM.cleanLinkEntrys(vidID); if (delete == "1") { TempData["error"] = y; return(RedirectToAction("ListLinks", "VideoBackend")); } if (y == "Success") { string x = VBM.processEntry(videoMetaData, tagArray, curUser.username); TempData["error"] = x; } return(RedirectToAction("ListLinks", "VideoBackend", curPage)); } catch (Exception e) { TempData["error"] = e.Message; return(RedirectToAction("ListLinks", "VideoBackend", curPage)); } }
public AccountManagerViewModel addUser(AccountManagerViewModel User) { //Add the user to DB AccountManagerViewModel returnMsg = User; string username = User.username.ToString(); username = username.ToLower(); string userTable = User.userTable.ToString(); string quID = User.quID.ToString(); string userlevel = "Z"; if (User.userlevel != null) { userlevel = User.userlevel.ToString(); } string admin_user; if (User.Admin == "Yes") { admin_user = "******"; } else { admin_user = "******"; } // Check to see if username is in datatel try { using (SqlConnection connection = new SqlConnection(QUToolsUtilities.GetConnectionString("datatel"))) { connection.Open(); string sqlCmd = "select * from person where NTLoginID = @un"; SqlCommand command = new SqlCommand(sqlCmd, connection); command.Parameters.AddWithValue("@un", username); using (SqlDataReader reader = command.ExecuteReader()) { if (!reader.HasRows) { returnMsg.returnMsg = "Invalid User"; return(returnMsg); } } connection.Close(); } } catch (Exception e) { returnMsg.returnMsg = e.ToString(); return(returnMsg); } // Check if user is already in database try { using (SqlConnection connection = new SqlConnection(QUToolsUtilities.GetConnectionString("internet"))) { connection.Open(); string sqlCmd = "select * from {0} where QU_User = @un"; sqlCmd = String.Format(sqlCmd, userTable); SqlCommand command = new SqlCommand(sqlCmd, connection); command.Parameters.AddWithValue("@un", username); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader["QU_User"].ToString() == User.username) { connection.Close(); returnMsg.returnMsg = "User already Exists."; return(returnMsg); } } } connection.Close(); } } catch (Exception e) { returnMsg.returnMsg = e.Message; return(returnMsg); } if (admin_user == "Y" && userlevel != "Z") { userlevel = "1111"; } // All went well... Lets add the user into the table. string template = "INSERT INTO {0} (QUID, toolAdmin, userlevel, QU_User) VALUES (@qID, @admin, @userlevel, @un)"; template = String.Format(template, User.userTable); try { using (SqlConnection connection = new SqlConnection(QUToolsUtilities.GetConnectionString("internet"))) { connection.Open(); using (SqlCommand command = new SqlCommand(template, connection)) { command.Parameters.AddWithValue("@qID", quID); command.Parameters.AddWithValue("@admin", admin_user); command.Parameters.AddWithValue("@userlevel", userlevel); command.Parameters.AddWithValue("@un", username); using (SqlDataReader reader = command.ExecuteReader()) connection.Close(); } } } catch (Exception e) { returnMsg.returnMsg = e.Message; return(returnMsg); } returnMsg.returnMsg = "Success"; return(returnMsg); }
public ActionResult Edit(AccountManagerViewModel admin) { if (!ModelState.IsValid) { return(View(admin)); } var changedAccountManager = userManager.FindById(admin.Id); changedAccountManager.Phone = admin.Phone; changedAccountManager.Email = admin.Email; changedAccountManager.ImageUrl = admin.ImageUrl; changedAccountManager.Name = admin.Name; if (!string.IsNullOrEmpty(admin.Password)) { if (!string.IsNullOrEmpty(changedAccountManager.Id)) { try { var changePasswordIdentityResult = userManager.UpdatePassword(changedAccountManager.Id, admin.Password); if (!changePasswordIdentityResult) { ModelState.AddModelError("password", "Misslyckades med att uppdatera lösenordet för" + admin.Name); return(View(admin)); } /*var addPasswordIdentityResult= userManager.AddPassword(changedAccountManager.Id, admin.Password); * if (!addPasswordIdentityResult.Succeeded) * { * ModelState.AddModelError("password", * "Misslyckades med att uppdatera lösenordet för" + admin.Name); * return View(admin); * }*/ } catch (MembershipPasswordException e) { ModelState.AddModelError("password", "Misslyckades med att uppdatera lösenordet för" + admin.Name); return(View(admin)); } } else { try { changedAccountManager.UserName = admin.Email; var newUserCreateSuccess = userManager.Create(changedAccountManager, admin.Password); if (newUserCreateSuccess) { userManager.AddToRole(changedAccountManager.Id, "sales"); return(RedirectToAction("Index")); } else { ModelState.AddModelError("password", "Misslyckades med att uppdatera lösenordet för" + admin.Name); return(View(admin)); } } catch (MembershipPasswordException e) { ModelState.AddModelError("password", "Misslyckades med att uppdatera lösenordet för" + admin.Name); return(View(admin)); } } } changedAccountManager.Name = admin.Name; userManager.Update(changedAccountManager); /*adminRepository.SetState(changedAccountManager, EntityState.Modified); * adminRepository.SaveChanges();*/ return(RedirectToAction("Index")); }
public ActionResult Create() { var accountManagers = new AccountManagerViewModel(userManager.GetRoles(User.Identity.GetUserId())); return(View(accountManagers)); }