public ActionResult UserAdmin(UserAdminView model) { if (Request.Form["resetbutton"] != null) { return(RedirectToAction("UserAdmin")); } if (ModelState.IsValid) { if (Request.Form["savebutton"] != null) { AppUserHelpers.UpdateAppUsers(db, model.UserAdminActiveView, true, User); return(RedirectToAction("Dashboard", "Home")); } if (Request.Form["addusersbutton"] != null) { AppUserHelpers.UpdateAppUsers(db, model.UserAdminActiveView, true, User); return(RedirectToAction("AddUser")); } if (Request.Form["saveinactivebutton"] != null) { AppUserHelpers.UpdateAppUsers(db, model.UserAdminNonActiveView, false, User); return(RedirectToAction("Dashboard", "Home")); } return(RedirectToAction("Dashboard", "Home")); } return(View(model)); }
}//CONSTRUCTOR //public IEnumerable<Role> getRole(int idUser) //{ // //var users = _context.Users; // var users_roles = _context.Users_Roles; // var roles = _context.Roles; // var result = from ur in users_roles // join r in roles on ur.IdRole equals r.IdRole // where ur.IdUser == idUser // select new Role // { // IdRole = ur.IdRole, // RoleName = r.RoleName // }; // return result; //} public IEnumerable <UserAdminView> GetAllUsers() { List <UserAdminView> userAdminViews = new List <UserAdminView>(); var result = from users in _context.Users join r_users in _context.Users_Roles on users.IdUser equals r_users.IdUser join roles in _context.Roles on r_users.IdRole equals roles.IdRole join d_users in _context.Users_Departments on users.IdUser equals d_users.IdUser join departments in _context.Departments on d_users.IdDepartment equals departments.IdDepartment join coleges in _context.Colleges on departments.IdCollege equals coleges.IdCollege select new UserAdminView { User = new User(users.IdUser, users.Username, users.FirstName, users.LastName, users.NrMatricol, users.Email, users.IsAccountActive), Role = new Role(roles.IdRole, roles.RoleName), Colleges = new List <College>() { new College(coleges.IdCollege, coleges.CollegeName) }, Departments = new List <Department>() { new Department(departments.IdDepartment, departments.DepartmentName, coleges.IdCollege) } }; foreach (var r in result) { if (!userAdminViews.Exists(u => u.User.IdUser == r.User.IdUser)) { UserAdminView userAdminView = new UserAdminView(); userAdminView.User = new User(r.User.IdUser, r.User.Username, r.User.FirstName, r.User.LastName, r.User.NrMatricol, r.User.Email, r.User.IsAccountActive); userAdminView.Role = new Role(r.Role.IdRole, r.Role.RoleName); userAdminView.Departments.Add(new Department(r.Departments[0].IdDepartment, r.Departments[0].DepartmentName, r.Departments[0].IdCollege)); userAdminView.Colleges.Add(new College(r.Colleges[0].IdCollege, r.Colleges[0].CollegeName)); userAdminViews.Add(userAdminView); } else { var u = userAdminViews.Find(u => u.User.IdUser == r.User.IdUser); if (!u.Colleges.Exists(d => d.IdCollege == r.Colleges[0].IdCollege)) { UserAdminView userAdminView = new UserAdminView(); userAdminView.Colleges.Add(new College(r.Colleges[0].IdCollege, r.Colleges[0].CollegeName)); } if (!u.Departments.Exists(d => d.IdDepartment == r.Departments[0].IdDepartment)) { UserAdminView userAdminView = new UserAdminView(); userAdminView.Departments.Add(new Department(r.Departments[0].IdDepartment, r.Departments[0].DepartmentName, r.Departments[0].IdCollege)); } } } return(userAdminViews); }
public static UserAdminView GetUserAdminView(ApplicationDbContext db, Guid organisationId) { List <UserAdminDetailsView> UserAdminActiveView = GetUserAdminDetailsView(db, organisationId, EntityStatusEnum.Active); List <UserAdminDetailsView> UserAdminPasswordChangeView = GetUserAdminDetailsView(db, organisationId, EntityStatusEnum.PasswordResetRequired); List <UserAdminDetailsView> UserAdminNonActiveView = GetUserAdminDetailsView(db, organisationId, null); UserAdminView view = new UserAdminView() { UserAdminActiveView = UserAdminActiveView, UserAdminPasswordChangeView = UserAdminPasswordChangeView, UserAdminNonActiveView = UserAdminNonActiveView }; return(view); }
//poate sa faca upd daca userul nu si a activat contul,daca e activat pate sa mod facultatea,dep,rol public void UpdateUsersForAdmin(UserAdminView userAdminView) { _userRepo.Update(new User(userAdminView.User.IdUser, userAdminView.User.Username, userAdminView.User.FirstName, userAdminView.User.LastName, userAdminView.User.NrMatricol, userAdminView.User.Email, false)); //poate mai avea si mai multe roluri AddToKeylessTable.UpdateTable_User_Role(userAdminView.User.IdUser, userAdminView.Role.IdRole); foreach (var department in userAdminView.Departments) { AddToKeylessTable.UpdateTable_User_Department(userAdminView.User.IdUser, department.IdDepartment); } _context.SaveChanges(); }
//poate sa adauge si numele,prenumele etc... public void AddUsers(UserAdminView userAdminView) { User user = new User(userAdminView.User.Username, userAdminView.User.FirstName, userAdminView.User.LastName, userAdminView.User.NrMatricol, userAdminView.User.Email, false); _userRepo.Insert(user); AddToKeylessTable.AddToTable_User_Role(user.IdUser, userAdminView.Role.IdRole); foreach (var department in userAdminView.Departments) { //User_Department user_Department = new User_Department(user.IdUser,department.IdDepartment); AddToKeylessTable.AddToTable_User_Department(user.IdUser, department.IdDepartment); } _context.SaveChanges(); }
public void ConstructorTest() { #region Init variables string name = "testname"; string surname = "surname"; string address = "*****@*****.**"; string roleName = "testRoleName"; #endregion UserAdminView userAdminView = new UserAdminView { Name = name, Surname = surname, Address = address, RoleName = roleName }; #region Tests Assert.NotNull(userAdminView); Assert.Equal(userAdminView.Name, name); Assert.Equal(userAdminView.Surname, surname); Assert.Equal(userAdminView.Address, address); Assert.Equal(userAdminView.RoleName, roleName); #endregion }
public static List <UserAdminView> GetUserAdminViewListForUser(ApplicationDbContext db, IPrincipal user) { List <UserAdminView> userAdminViewListForUser = new List <UserAdminView>(); List <UserAdminRelatedBranchesView> relatedBranches = new List <UserAdminRelatedBranchesView>(); AppUser appUser = AppUserHelpers.GetAppUser(db, user); BranchUser branchUser = BranchUserHelpers.GetBranchUser(db, appUser.AppUserId, appUser.CurrentBranchId); switch (user.Identity.GetCurrentUserRole()) { case "SuperUser": case "Admin": //Get all users for the company of this user var branchUsersForCompany = (from b in db.BranchUsers join a in db.AppUsers on b.UserId equals a.AppUserId where (b.CompanyId == branchUser.CompanyId && b.EntityStatus == EntityStatusEnum.Active) select new { AppUserId = b.UserId, BranchId = b.BranchId, BranchUserId = b.BranchUserId, CurrentBranchId = a.CurrentBranchId, UserRole = b.UserRole }).Distinct().ToList(); foreach (var branchUserForCompany in branchUsersForCompany) { UserAdminRelatedBranchesView relatedBranch = new UserAdminRelatedBranchesView(); relatedBranch.AppUserId = branchUserForCompany.AppUserId; relatedBranch.BranchId = branchUserForCompany.BranchId; relatedBranch.BranchUserId = branchUserForCompany.BranchUserId; relatedBranch.UserRole = branchUserForCompany.UserRole; //relatedBranch.BranchUserDetails = BranchUserHelpers.GetBranchUser(db, branchUserForCompany.BranchUserId); Branch branchDetails = BranchHelpers.GetBranch(db, branchUserForCompany.BranchId); relatedBranch.BranchName = branchDetails.BranchName; relatedBranch.AddressLine1 = branchDetails.AddressLine1; relatedBranch.AddressTownCity = branchDetails.AddressTownCity; relatedBranch.AddressPostcode = branchDetails.AddressPostcode; if (branchUserForCompany.BranchId == branchUserForCompany.CurrentBranchId) { relatedBranch.CurrentBranch = true; } else { relatedBranch.CurrentBranch = false; } relatedBranches.Add(relatedBranch); } List <AppUser> appUsersForCompany = (from b in branchUsersForCompany join a in db.AppUsers on b.AppUserId equals a.AppUserId select a).Distinct().ToList(); foreach (AppUser appUserForCompany in appUsersForCompany) { UserAdminView userAdminView = new UserAdminView(); userAdminView.AppUserId = appUserForCompany.AppUserId; userAdminView.FirstName = appUserForCompany.FirstName; userAdminView.LastName = appUserForCompany.LastName; userAdminView.AppUserEntityStatus = appUserForCompany.EntityStatus; userAdminView.CurrentBranchId = appUserForCompany.CurrentBranchId; userAdminView.LoginEmail = appUserForCompany.LoginEmail; userAdminView.RelatedBranches = (from rb in relatedBranches where (rb.AppUserId == appUserForCompany.AppUserId) select rb).ToList(); userAdminViewListForUser.Add(userAdminView); } break; case "Manager": //Get all users for the branches of this user as manager (manager) var branchList = (from bu in db.BranchUsers where (bu.UserId == appUser.AppUserId && bu.UserRole == UserRoleEnum.Manager) select new { BranchId = bu.BranchId }).Distinct().ToList(); //var branchUsersForBranch = (from b in db.BranchUsers // join a in db.AppUsers on b.UserId equals a.AppUserId // join c in branchList on b.BranchId equals c.BranchId // where (b.BranchId == appUser.CurrentBranchId && b.EntityStatus == EntityStatusEnum.Active) // select new { AppUserId = b.UserId, BranchId = b.BranchId, BranchUserId = b.BranchUserId, CurrentBranchId = a.CurrentBranchId, UserRole = b.UserRole }).Distinct().ToList(); var branchUsersForBranchList = (from bl in branchList join bu in db.BranchUsers on bl.BranchId equals bu.BranchId join au in db.AppUsers on bu.UserId equals au.AppUserId where (bu.CompanyId == branchUser.CompanyId && bu.EntityStatus == EntityStatusEnum.Active) select new { AppUserId = bu.UserId, BranchId = bu.BranchId, BranchUserId = bu.BranchUserId, CurrentBranchId = au.CurrentBranchId, UserRole = bu.UserRole }).Distinct().ToList(); foreach (var branchUserForBranch in branchUsersForBranchList) { UserAdminRelatedBranchesView relatedBranch = new UserAdminRelatedBranchesView(); relatedBranch.AppUserId = branchUserForBranch.AppUserId; relatedBranch.BranchId = branchUserForBranch.BranchId; relatedBranch.BranchUserId = branchUserForBranch.BranchUserId; relatedBranch.UserRole = branchUserForBranch.UserRole; //relatedBranch.BranchUserDetails = BranchUserHelpers.GetBranchUser(db, branchUserForBranch.BranchUserId); Branch branchDetails = BranchHelpers.GetBranch(db, branchUserForBranch.BranchId); relatedBranch.BranchName = branchDetails.BranchName; relatedBranch.AddressLine1 = branchDetails.AddressLine1; relatedBranch.AddressTownCity = branchDetails.AddressTownCity; relatedBranch.AddressPostcode = branchDetails.AddressPostcode; if (branchUserForBranch.BranchId == branchUserForBranch.CurrentBranchId) { relatedBranch.CurrentBranch = true; } else { relatedBranch.CurrentBranch = false; } relatedBranches.Add(relatedBranch); } List <AppUser> appUsersForBranchList = (from b in branchUsersForBranchList join a in db.AppUsers on b.AppUserId equals a.AppUserId select a).Distinct().ToList(); foreach (AppUser appUserForBranch in appUsersForBranchList) { UserAdminView userAdminView = new UserAdminView(); userAdminView.AppUserId = appUserForBranch.AppUserId; userAdminView.FirstName = appUserForBranch.FirstName; userAdminView.LastName = appUserForBranch.LastName; userAdminView.AppUserEntityStatus = appUserForBranch.EntityStatus; userAdminView.CurrentBranchId = appUserForBranch.CurrentBranchId; userAdminView.LoginEmail = appUserForBranch.LoginEmail; userAdminView.RelatedBranches = (from rb in relatedBranches where (rb.AppUserId == appUserForBranch.AppUserId) select rb).ToList(); userAdminViewListForUser.Add(userAdminView); } break; } return(userAdminViewListForUser); }
public static IList <UserAdminView> GetFilteredUsers(ObjectForUsersFilter objectForUsersFilter) { using (SqlConnection con = new SqlConnection("Server=DESKTOP-RPNBQ1M;Integrated Security=true;Database=VotingApp;")) { con.Open(); List <UserAdminView> userAdminViews = new List <UserAdminView>(); using (SqlCommand command = new SqlCommand(CreateQueryString(objectForUsersFilter), con)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int IdUser = reader.GetInt32(0); string Username = reader.GetString(1); string FirstName = reader.GetString(2); string LastName = reader.GetString(3); string NrMatricol = reader.GetString(4); string Email = reader.GetString(5); bool IsAccountActive = reader.GetBoolean(6); int IdRole = reader.GetInt32(7); string RoleName = reader.GetString(8); int IdCollege = reader.GetInt32(9); string CollegeName = reader.GetString(10); int IdDepartment = reader.GetInt32(11); string DepartmentName = reader.GetString(12); if (!userAdminViews.Exists(u => u.User.IdUser == IdUser)) { UserAdminView userAdminView = new UserAdminView(); userAdminView.User = new User(IdUser, FirstName, LastName, Username, NrMatricol, Email, IsAccountActive); userAdminView.Role = new Role(IdRole, RoleName); userAdminView.Departments.Add(new Department(IdDepartment, DepartmentName, IdCollege)); userAdminView.Colleges.Add(new College(IdCollege, CollegeName)); userAdminViews.Add(userAdminView); } else { var u = userAdminViews.Find(u => u.User.IdUser == IdUser); if (!u.Colleges.Exists(d => d.IdCollege == IdCollege)) { UserAdminView userAdminView = new UserAdminView(); userAdminView.Colleges.Add(new College(IdCollege, CollegeName)); } if (!u.Departments.Exists(d => d.IdDepartment == IdDepartment)) { UserAdminView userAdminView = new UserAdminView(); userAdminView.Departments.Add(new Department(IdDepartment, DepartmentName, IdCollege)); } } } } con.Close(); return(userAdminViews); } }
public static string GetListAllItemView(long pageNo, long itemsPerPage, long dataIndex, string templateSuffix, bool asyncLoading, long filterInfoCategoryId, string filterInfoPage, bool filterInfoPagePublic, long filterCreatedUserId, bool hideFilter) { string message = ""; if (itemsPerPage == 0) { itemsPerPage = UtilsGeneric.DefaultItemsPerPage; } long totalPages; long totalItems; string htmlTextItemList = ""; string htmlAddItemList = ""; string htmlFilterItemList = ""; //if ((filterInfoCategoryId > 0) || (filterInfoPage.Trim().Length > 0) || (filterInfoPagePublic == true)) hideFilter = false; #region Filter Section List <TemplateInfoPageListDetailFilter.ShowPublicChecked> showPublicCheckedList = new List <TemplateInfoPageListDetailFilter.ShowPublicChecked>(); List <TemplateInfoPageListDetailFilter.ShowPublicUnChecked> showPublicUnCheckedList = new List <TemplateInfoPageListDetailFilter.ShowPublicUnChecked>(); if (filterInfoPagePublic == true) { showPublicCheckedList.Add(new TemplateInfoPageListDetailFilter.ShowPublicChecked { DataIndex = dataIndex.ToString(), PageNo = pageNo.ToString(), ItemsPerPage = itemsPerPage.ToString(), TemplateSuffix = templateSuffix, AsyncLoading = asyncLoading.ToString().ToLower() }); } else { showPublicUnCheckedList.Add(new TemplateInfoPageListDetailFilter.ShowPublicUnChecked { DataIndex = dataIndex.ToString(), PageNo = pageNo.ToString(), ItemsPerPage = itemsPerPage.ToString(), TemplateSuffix = templateSuffix, AsyncLoading = asyncLoading.ToString().ToLower() }); } #region Get Info Category List List <LTD_InfoCategory> ltdInfoCategoryList = DataInfoList.GetAllActiveLtdInfoCategory(); bool firstRecord = true; List <TemplateInfoPageListDetailFilter.InfoCategoryItem> infoCategoryItemList = new List <TemplateInfoPageListDetailFilter.InfoCategoryItem>(); if (ltdInfoCategoryList.Count == 0) { infoCategoryItemList.Add(new TemplateInfoPageListDetailFilter.InfoCategoryItem { InfoCategoryText = "No Info Category Found", InfoCategoryValue = "1", InfoCategorySelected = true }); } else { infoCategoryItemList.Add(new TemplateInfoPageListDetailFilter.InfoCategoryItem { InfoCategoryText = "Select Category Filter", InfoCategoryValue = "0", InfoCategorySelected = (filterInfoCategoryId == 0) }); if (filterInfoCategoryId == 0) { firstRecord = false; } } if (filterInfoCategoryId != 0) { LTD_InfoCategory ltdInfoCategory = DataInfoList.GetLtdInfoCategory(filterInfoCategoryId); if (ltdInfoCategory != null) { infoCategoryItemList.Add(new TemplateInfoPageListDetailFilter.InfoCategoryItem { InfoCategoryText = ltdInfoCategory.InfoCategoryName, InfoCategoryValue = ltdInfoCategory.InfoCategoryID.ToString(), InfoCategorySelected = true, }); firstRecord = false; } } foreach (LTD_InfoCategory ltdInfoCategory in ltdInfoCategoryList) { if (ltdInfoCategory.InfoCategoryID != filterInfoCategoryId) { if ((filterInfoCategoryId == 0) && (firstRecord == true)) { infoCategoryItemList.Add(new TemplateInfoPageListDetailFilter.InfoCategoryItem { InfoCategoryText = ltdInfoCategory.InfoCategoryName, InfoCategoryValue = ltdInfoCategory.InfoCategoryID.ToString(), InfoCategorySelected = true }); } else { infoCategoryItemList.Add(new TemplateInfoPageListDetailFilter.InfoCategoryItem { InfoCategoryText = ltdInfoCategory.InfoCategoryName, InfoCategoryValue = ltdInfoCategory.InfoCategoryID.ToString(), InfoCategorySelected = false, }); } } firstRecord = false; } #endregion long selectedUserId = 0; string selectUserDetailsHtml = ""; string userSelectNameId = "infoPageUserFilter"; if (UtilsSecurity.HaveAdminRole() == true) { selectedUserId = UtilsSecurity.GetUserId(); if (filterCreatedUserId > 0) { selectedUserId = filterCreatedUserId; } #region User Select View long userViewDataIndex = dataIndex + 5; string showFunctionScript = ""; string selectChangeCallback = " filterInfoPageList(" + pageNo + "," + itemsPerPage + "," + dataIndex + ",'" + templateSuffix + "'," + asyncLoading.ToString().ToLower() + ") "; selectUserDetailsHtml = UserAdminView.GetUserSelectView(userViewDataIndex, 1, 25, templateSuffix, selectedUserId, false, showFunctionScript, "", userSelectNameId, selectChangeCallback, out selectedUserId); #endregion } TemplateInfoPageListDetailFilter listDetailFilter = new TemplateInfoPageListDetailFilter { InfoPageListFilterHidden = hideFilter, ShowPublicCheckedList = showPublicCheckedList, ShowPublicUnCheckedList = showPublicUnCheckedList, InfoCategoryItemList = infoCategoryItemList, InfoPageFilter = filterInfoPage, DataIndex = dataIndex.ToString(), PageNo = pageNo.ToString(), ItemsPerPage = itemsPerPage.ToString(), TemplateSuffix = templateSuffix, AsyncLoading = asyncLoading.ToString().ToLower(), UserSelect = selectUserDetailsHtml, }; htmlFilterItemList = listDetailFilter.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message); #endregion #region Add Link List <TemplateInfoPageSaveAdd.AddAction> addActionList = new List <TemplateInfoPageSaveAdd.AddAction>(); if (UtilsSecurity.HaveAuthorRoleEnabled() == true) { addActionList.Add(new TemplateInfoPageSaveAdd.AddAction { DataIndex = dataIndex.ToString(), PageNo = pageNo.ToString(), ItemsPerPage = itemsPerPage.ToString(), TemplateSuffix = templateSuffix, }); } TemplateInfoPageSaveAdd templateSaveAdd = new TemplateInfoPageSaveAdd { AddActionList = addActionList, }; htmlAddItemList = templateSaveAdd.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message); #endregion #region Get Fill List #region Get Paged Data List <LTD_InfoPage> ltdInfoPageList = new List <LTD_InfoPage>(); if (UtilsSecurity.IsAuthenticated() == true) { if (filterInfoPagePublic == true) { ltdInfoPageList = DataInfoList.GetPublicPagedLtdInfoPage(filterInfoCategoryId, filterInfoPage, selectedUserId, pageNo, itemsPerPage, out totalPages, out totalItems); } else { if (UtilsSecurity.HaveAdminRole() == true) { ltdInfoPageList = DataInfoList.GetPagedLtdInfoPage(filterInfoCategoryId, filterInfoPage, selectedUserId, pageNo, itemsPerPage, out totalPages, out totalItems); } else { ltdInfoPageList = DataInfoList.GetUserPagedLtdInfoPage(filterInfoCategoryId, filterInfoPage, pageNo, itemsPerPage, out totalPages, out totalItems); } long commonTotalPages = 0; long commonTotalItems = 0; List <LTD_InfoPage> commonltdInfoPageList = DataInfoList.GetCommonPagedLtdInfoPage(filterInfoCategoryId, filterInfoPage, pageNo, itemsPerPage, out commonTotalPages, out commonTotalItems); if (commonltdInfoPageList.Count > 0) { ltdInfoPageList.AddRange(commonltdInfoPageList); totalItems = totalItems + commonTotalItems; if (commonTotalPages > 1) { totalPages = totalPages + commonTotalPages - 1; } } } } else { ltdInfoPageList = DataInfoList.GetPublicPagedLtdInfoPage(filterInfoCategoryId, filterInfoPage, selectedUserId, pageNo, itemsPerPage, out totalPages, out totalItems); } #endregion if (ltdInfoPageList.Count > 0) { #region Get Pager Details string topPagerDetails = UtilsGeneric.GetItemPagerView(pageNo, itemsPerPage, dataIndex, templateSuffix, totalPages, RefreshListFunctionName, asyncLoading.ToString().ToLower()); string bottomPagerDetails = UtilsGeneric.GetLinkPagerView(pageNo, itemsPerPage, dataIndex, templateSuffix, totalPages, totalItems, RefreshListFunctionName, asyncLoading.ToString().ToLower(), false); #endregion #region Append Top Pager if (topPagerDetails.Trim().Length > 0) { htmlTextItemList += topPagerDetails; } #endregion #region Append Items int index = 0; for (; index < ltdInfoPageList.Count; index++) { LTD_InfoPage ltdInfoPage = ltdInfoPageList[index]; string htmlTextItemTemplate = GetListSingleItemView(ltdInfoPage, pageNo, itemsPerPage, dataIndex, templateSuffix, index, asyncLoading); htmlTextItemList += htmlTextItemTemplate; } #endregion #region Append Bottom Pager if (bottomPagerDetails.Trim().Length > 0) { htmlTextItemList += bottomPagerDetails; } #endregion } #endregion #region Set Fill List if (htmlTextItemList.Length == 0) { TemplateInfoPageListDetailEmpty templateListDetailEmpty = new TemplateInfoPageListDetailEmpty { DataIndex = dataIndex.ToString(), PageNo = pageNo.ToString(), ItemsPerPage = itemsPerPage.ToString(), TemplateSuffix = templateSuffix, AsyncLoading = asyncLoading.ToString().ToLower() }; htmlTextItemList = templateListDetailEmpty.GetFilled(templateSuffix, UtilsGeneric.Validate, UtilsGeneric.ThrowException, out message); } #endregion return(htmlFilterItemList + htmlAddItemList + htmlTextItemList); }
public ActionResult UserAdmin() { UserAdminView model = AppUserViewHelpers.GetUserAdminView(db, AppUserHelpers.GetOrganisationIdFromUser(db, User)); return(View(model)); }