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 LanguageItemViewModel(Language language, LanguagesRepository languagesRepository) : this() { _language = language; IsActive = language.IsActive; _languageRepository = languagesRepository; }
public async Task InitilizeAsync() { // "Idle.DataAccess" var languageImageProvider = new ImagesProvider(); var languagesFactory = new LanguagesFactory(languageImageProvider); var languageMigrator = new LanguageMigrator(languagesFactory); await languageMigrator.MigrateAsync(); var languagesRepository = new LanguagesRepository(); // "Idle.Services" var navigation = new Lazy <INavigation>(() => Application.Current.MainPage.Navigation); var navigationService = new NavigationService(navigation); // "Idle.Logic" and "Idle.Views" var mainPage = SetBindingContext(new MainPage(), new MainPageViewModel(navigationService)); navigationService.Register <MainPageViewModel>(() => mainPage); navigationService.Register <LanguagesViewModel>(() => SetBindingContext(new LanguagesPage(), new LanguagesViewModel(languagesRepository))); navigationService.Register <LanguageMarketViewModel>(() => SetBindingContext(new LanguageMarket(), new LanguageMarketViewModel(languagesRepository))); // Idle.Views MainPage = new NavigationPage(mainPage); }
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(); }
private List <StatisticViewModel> GetStatisticViewModels() { List <StatisticViewModel> result = new List <StatisticViewModel>(); LanguagesRepository languagesRepository = new LanguagesRepository(); LanguagesTranslationsRepository languagesTranslationsRepository = new LanguagesTranslationsRepository(); IEnumerable <Languages> languages = languagesRepository.GetAll(); List <int> languagesId = languages.Select(l => l.Id).ToList(); List <CategoryStatistic> categoryStatistics = FillCategory(); foreach (var languageId in languagesId) { IEnumerable <LanguageTranslations> languageTranslationsList = languagesTranslationsRepository.GetAll(); var id = languageId; string langName = languageTranslationsList .First(l => l.LangId == id && l.NativeLangId == _userLanguageId).Translation; List <CategoryStatistic> listToCopy = Helper.DeepClone(categoryStatistics); result.Add(new StatisticViewModel { LanguageName = langName, CategoryStatistics = listToCopy, LanguageId = languageId }); } StatisticViewModel[] statisticArray = new StatisticViewModel[result.Count]; for (int j = 0; j < statisticArray.Length; j++) { statisticArray[j] = FillResults(result[j]); } return(result); }
public IActionResult Languages() { IRepository <Languages> languagesRepository = new LanguagesRepository(); List <Languages> languagesList = languagesRepository.GetAll().ToList(); SelectList languages = new SelectList(languagesList, "Id", "Name"); return(View(languages)); }
private async Task <LanguagesRepository> SetupAsync() { var connection = new SQLiteAsyncConnection(":memory:"); var repo = new LanguagesRepository(connection); await repo.Connection.CreateTableAsync <Language>(); return(repo); }
private async Task <LanguagesRepository> SetupAsync() { var connection = new SQLiteAsyncConnection(":memory:"); var imagesProvider = new ImagesProvider(); var languagesFactory = new LanguagesFactory(imagesProvider); var migrator = new LanguageMigrator(languagesFactory, connection); await migrator.MigrateAsync(); var repo = new LanguagesRepository(connection); return(repo); }
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 IActionResult GetAllLanguages() { List <Languages> languages = new LanguagesRepository().GetAll().ToList(); List <LanguageTranslations> languageTranslations = new LanguagesTranslationsRepository().GetAll().ToList(); var result = (from language in languages join langTranslation in languageTranslations on language.Id equals langTranslation.LangId where langTranslation.NativeLangId == language.Id select new { Translation = langTranslation.Translation, Id = language.Id }).ToList(); string json = JsonConvert.SerializeObject(result); return(Ok(json)); }
//[Test] //public void EanLanguageCodesToIds_Result_IReadOnlyDictionary_Of_String_Integer() //{ // //Arrange // var type = typeof(IReadOnlyDictionary<string, int>); // var repository = CreateRepository(); // //Act // var result = repository.EanLanguageCodesToIds; // //Assert // Assert.IsInstanceOf(type,result); //} private static LanguagesRepository CreateRepository() { var dboContextMock = new Mock <Entity.GlobalizationDatabaseContext>(); //var dbSet = GetQueryableMockDbSet(new List<Language>() //{ // new Language() // { // EanLanguageCode = "", // Id = 0 // } //}); //dboContextMock.Setup(p => p.Languages).Returns(dbSet); var repository = new LanguagesRepository(dboContextMock.Object); return(repository); }
public MenuService(AppDbContext dbContext, People logedInPerson) : base(dbContext, logedInPerson) { this.MenusRepo = new MenusRepository(dbContext); this.LanguageRepo = new LanguagesRepository(dbContext); this.MenuLanguagesRepo = new MenuLanguagesRepository(dbContext); this.CurrencyRepo = new CurrenciesRepository(dbContext); this.MenuCurrencyRepo = new MenuCurrenciesRepository(dbContext); this.CategoriesRepo = new CategoriesRepository(dbContext); this.MenuCategoriesRepo = new MenuCategoriesRepository(dbContext); this.MenuItemRepo = new MenuItemsRepository(dbContext); this.MenuItemContentRepo = new MenuItemContentRepository(dbContext); this.MenuItemValueRepo = new MenuItemValueRepository(dbContext); }
//[Test] //public void EanLanguageCodesToIds_Result_IReadOnlyDictionary_Of_String_Integer() //{ // //Arrange // var type = typeof(IReadOnlyDictionary<string, int>); // var repository = CreateRepository(); // //Act // var result = repository.EanLanguageCodesToIds; // //Assert // Assert.IsInstanceOf(type,result); //} private static LanguagesRepository CreateRepository() { var dboContextMock = new Mock <TravelDbContext>(); //var dbSet = GetQueryableMockDbSet(new List<Language>() //{ // new Language() // { // ExpediaCode = "", // Id = 0 // } //}); //dboContextMock.Setup(p => p.Languages).Returns(dbSet); var repository = new LanguagesRepository(dboContextMock.Object); return(repository); }
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 LanguageController(LanguagesRepository languageRepository) { _repository = languageRepository; }
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 = 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 LanguagesBusiness(IUnitOfWork _unitOfWork) { unitOfWork = _unitOfWork; repository = new LanguagesRepository(unitOfWork); }
public LanguageMarketViewModel(LanguagesRepository languageRepository) { _languageRepository = languageRepository; }
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 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")); }