public ActionResult Create() { if (!Authorized(RoleType.UsersManager)) return Error(Loc.Dic.error_no_permission); List<string> roleNames = GetRoleNames(); List<SelectListItemDB> ApprovalRoutesList = new List<SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.NoApprovalRoute } }; SelectList languagesList; using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRep = new LanguagesRepository()) { ApprovalRoutesList.AddRange( routesRep.GetList() .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name }) ); languagesList = new SelectList(languagesRep.GetList().ToList(), "Id", "Name"); } ViewBag.RolesList = roleNames; ViewBag.RoutesList = new SelectList(ApprovalRoutesList, "Id", "Name"); ViewBag.LanguagesList = languagesList; return View(); }
public ActionResult Settings(UserSettingsModel model) { if (!ModelState.IsValid) { using (UsersRepository userRepository = new UsersRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRepository = new LanguagesRepository()) { User user = userRepository.GetEntity(CurrentUser.UserId); model.NotificationsEmail = user.NotificationEmail; ViewBag.LanguagesList = new SelectList(languagesRepository.GetList().ToList(), "Id", "Name", user.LanguageId); } return(View(model)); } using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) { User user = usersRep.GetList().SingleOrDefault(x => x.Id == CurrentUser.UserId); user.LanguageId = model.LanguageId; user.NotificationEmail = String.IsNullOrEmpty(model.NotificationsEmail) ? null : model.NotificationsEmail; if (usersRep.Update(user) == null) { return(Error(Loc.Dic.error_database_error)); } CurrentUser.LanguageCode = user.Language.Code; CurrentUser.NotificationEmail = user.NotificationEmail; return(RedirectToAction("index", "Home")); } }
public ActionResult Settings() { UserSettingsModel model = new UserSettingsModel(); using (UsersRepository userRepository = new UsersRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRepository = new LanguagesRepository()) { User user = userRepository.GetEntity(CurrentUser.UserId); model.NotificationsEmail = user.NotificationEmail; ViewBag.LanguagesList = new SelectList(languagesRepository.GetList().ToList(), "Id", "Name", user.LanguageId); } return(View(model)); }
public ActionResult Create() { if (!Authorized(RoleType.UsersManager)) { return(Error(Loc.Dic.error_no_permission)); } List <string> roleNames = GetRoleNames(); List <SelectListItemDB> ApprovalRoutesList = new List <SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.NoApprovalRoute } }; SelectList languagesList; using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRep = new LanguagesRepository()) { ApprovalRoutesList.AddRange( routesRep.GetList() .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name }) ); languagesList = new SelectList(languagesRep.GetList().ToList(), "Id", "Name"); } ViewBag.RolesList = roleNames; ViewBag.RoutesList = new SelectList(ApprovalRoutesList, "Id", "Name"); ViewBag.LanguagesList = languagesList; return(View()); }
public ActionResult Create(User user, string[] roleNames) { if (!ModelState.IsValid) { List <string> allRoleNames = GetRoleNames(); List <SelectListItemDB> ApprovalRoutesList = new List <SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.NoApprovalRoute } }; SelectList languagesList; using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRep = new LanguagesRepository()) { ApprovalRoutesList.AddRange( routesRep.GetList() .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name }) ); languagesList = new SelectList(languagesRep.GetList().ToList(), "Id", "Name"); } ViewBag.RolesList = allRoleNames; ViewBag.RoutesList = new SelectList(ApprovalRoutesList, "Id", "Name"); ViewBag.LanguagesList = languagesList; return(View(user)); } if (user.DefaultApprovalRouteId == -1) { user.DefaultApprovalRouteId = null; } if (!Authorized(RoleType.SystemManager)) { return(Error(Loc.Dic.error_no_permission)); } int companyUserCount = 0; int companyUserLimit = 0; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { if (user.DefaultApprovalRouteId.HasValue) { var route = routesRep.GetEntity(user.DefaultApprovalRouteId.Value); if (route == null) { return(Error(Loc.Dic.error_invalid_form)); } } try { companyUserCount = usersRep.GetList().Where(x => x.IsActive).Count() + pendingUsersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count(); companyUserLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; } catch { return(Error(Loc.Dic.error_database_error)); } bool userExists = usersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); bool pendingUserExists = pendingUsersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); if (userExists || pendingUserExists) { return(Error(Loc.Dic.error_users_exist_error)); } } if (companyUserCount >= companyUserLimit) { return(Error(Loc.Dic.error_users_limit_reached)); } user.CompanyId = CurrentUser.CompanyId; user.CreationTime = DateTime.Now; RoleType combinedRoles = RoleType.None; List <RoleType> forbiddenRoles = GetForbiddenRoles(); if (roleNames == null || roleNames.Count() == 0) { return(Error(Loc.Dic.error_invalid_form)); } foreach (string roleName in roleNames) { RoleType role; if (!Enum.TryParse(roleName, out role) || forbiddenRoles.Contains(role)) { return(Error(Loc.Dic.error_invalid_form)); } combinedRoles = Roles.CombineRoles(combinedRoles, role); } user.Roles = (int)combinedRoles; user.DefaultApprovalRouteId = user.DefaultApprovalRouteId.HasValue && user.DefaultApprovalRouteId.Value == -1 ? null : user.DefaultApprovalRouteId; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) { if (!usersRep.Create(user)) { return(Error(Loc.Dic.error_users_create_error)); } } return(RedirectToAction("Index")); }
public ActionResult Settings(UserSettingsModel model) { if (!ModelState.IsValid) { using (UsersRepository userRepository = new UsersRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRepository = new LanguagesRepository()) { User user = userRepository.GetEntity(CurrentUser.UserId); model.NotificationsEmail = user.NotificationEmail; ViewBag.LanguagesList = new SelectList(languagesRepository.GetList().ToList(), "Id", "Name", user.LanguageId); } return View(model); } using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) { User user = usersRep.GetList().SingleOrDefault(x => x.Id == CurrentUser.UserId); user.LanguageId = model.LanguageId; user.NotificationEmail = String.IsNullOrEmpty(model.NotificationsEmail) ? null : model.NotificationsEmail; if (usersRep.Update(user) == null) return Error(Loc.Dic.error_database_error); CurrentUser.LanguageCode = user.Language.Code; CurrentUser.NotificationEmail = user.NotificationEmail; return RedirectToAction("index", "Home"); } }
public ActionResult Settings() { UserSettingsModel model = new UserSettingsModel(); using (UsersRepository userRepository = new UsersRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRepository = new LanguagesRepository()) { User user = userRepository.GetEntity(CurrentUser.UserId); model.NotificationsEmail = user.NotificationEmail; ViewBag.LanguagesList = new SelectList(languagesRepository.GetList().ToList(), "Id", "Name", user.LanguageId); } return View(model); }
public ActionResult Create(User user, string[] roleNames) { if (!ModelState.IsValid) { List<string> allRoleNames = GetRoleNames(); List<SelectListItemDB> ApprovalRoutesList = new List<SelectListItemDB>() { new SelectListItemDB() { Id = -1, Name = Loc.Dic.NoApprovalRoute } }; SelectList languagesList; using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (LanguagesRepository languagesRep = new LanguagesRepository()) { ApprovalRoutesList.AddRange( routesRep.GetList() .Select(x => new SelectListItemDB() { Id = x.Id, Name = x.Name }) ); languagesList = new SelectList(languagesRep.GetList().ToList(), "Id", "Name"); } ViewBag.RolesList = allRoleNames; ViewBag.RoutesList = new SelectList(ApprovalRoutesList, "Id", "Name"); ViewBag.LanguagesList = languagesList; return View(user); } if (user.DefaultApprovalRouteId == -1) user.DefaultApprovalRouteId = null; if (!Authorized(RoleType.SystemManager)) return Error(Loc.Dic.error_no_permission); int companyUserCount = 0; int companyUserLimit = 0; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) using (ApprovalRoutesRepository routesRep = new ApprovalRoutesRepository(CurrentUser.CompanyId)) using (PendingUsersRepository pendingUsersRep = new PendingUsersRepository()) using (CompaniesRepository companiesRep = new CompaniesRepository()) { if (user.DefaultApprovalRouteId.HasValue) { var route = routesRep.GetEntity(user.DefaultApprovalRouteId.Value); if (route == null) return Error(Loc.Dic.error_invalid_form); } try { companyUserCount = usersRep.GetList().Where(x => x.IsActive).Count() + pendingUsersRep.GetList().Where(x => x.CompanyId == CurrentUser.CompanyId).Count(); companyUserLimit = companiesRep.GetEntity(CurrentUser.CompanyId).UsersLimit; } catch { return Error(Loc.Dic.error_database_error); } bool userExists = usersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); bool pendingUserExists = pendingUsersRep.GetList().Any(x => x.CompanyId == CurrentUser.CompanyId && x.Email == user.Email); if (userExists || pendingUserExists) return Error(Loc.Dic.error_users_exist_error); } if (companyUserCount >= companyUserLimit) return Error(Loc.Dic.error_users_limit_reached); user.CompanyId = CurrentUser.CompanyId; user.CreationTime = DateTime.Now; RoleType combinedRoles = RoleType.None; List<RoleType> forbiddenRoles = GetForbiddenRoles(); if (roleNames == null || roleNames.Count() == 0) return Error(Loc.Dic.error_invalid_form); foreach (string roleName in roleNames) { RoleType role; if (!Enum.TryParse(roleName, out role) || forbiddenRoles.Contains(role)) return Error(Loc.Dic.error_invalid_form); combinedRoles = Roles.CombineRoles(combinedRoles, role); } user.Roles = (int)combinedRoles; user.DefaultApprovalRouteId = user.DefaultApprovalRouteId.HasValue && user.DefaultApprovalRouteId.Value == -1 ? null : user.DefaultApprovalRouteId; using (UsersRepository usersRep = new UsersRepository(CurrentUser.CompanyId)) { if (!usersRep.Create(user)) return Error(Loc.Dic.error_users_create_error); } return RedirectToAction("Index"); }