public bool InitializeContext() { try { var actualUser = _accountService.GetLoggedUser(); if (actualUser == null) { return(false); } var context = new ContextModel { User = actualUser, AllLanguages = _userManagerService.GetLanguages().OrderBy(o => o.IdLanguage).ToList() }; context.ActualLanguage = context.User.Language == null?context.AllLanguages.FirstOrDefault() : _userManagerService.GetLanguages().FirstOrDefault(lan => lan.ID == context.User.Language.ID); SetContext(context); var userIdentity = new UserIdentityModel(actualUser.Username, new List <string> { actualUser.Role.ToString().SHA256Encript() }); HttpContext.Current.User = userIdentity; var cookie = new HttpCookie(actualUser.Username, actualUser.Role.ToString().SHA256Encript()); HttpContext.Current.Response.Cookies.Add(cookie); } catch (Exception ex) { LogService.WriteLog(ex.GetStringLog(), LogService.TypeLevel.Error, ex); } return(true); }
private void setInitialModel(LoginModel model) { model.AllLanguages = _userManagerService.GetLanguages().OrderBy(o => o.IdLanguage).ToList(); string lang = (string)Request.RequestContext.RouteData.Values["lang"]; if (lang != null) { foreach (var lingua in model.AllLanguages) { if (lingua.InitialsLanguage == lang) { model.ActualLanguage = lingua; break; } } } else { model.ActualLanguage = model.AllLanguages.FirstOrDefault(); } model.Faqs = _faqService.GetFaqs(); }
public UserManagerViewModel GetUsers(ContextModel context) { var userManager = new UserManagerViewModel(); string usernameCustomer = null; if (context.User.Role != enRole.Administrator && context.User.Role != enRole.Demo) { usernameCustomer = context.User.Username; } var usersModel = _userManagerService.GetUsers(usernameCustomer); if (context.User.Role == enRole.Demo) { usersModel = _userManagerService.FilterRoleUsers(context.User.Role, usersModel); } // users userManager.users = usersModel.Select(s => new UserViewModel { ID = s.ID, Username = s.Username, FirstName = s.FirstName, LastName = s.LastName, Email = s.Email, CustomerName = s.CustomerName, RoleCode = (int)s.Role, RoleName = LocalizationService.GetResource(s.Role.GetDescription()), LanguageId = s.Language.ID, LanguageName = s.Language.Name, Enabled = s.Enabled, MachineSerials = s.Machines.Select(sel => sel.Serial).ToList(), TimeZone = s.TimeZone }).ToList(); //roles var rolesModel = _userManagerService.GetRoles(); userManager.roles = rolesModel.Select(s => new UserRoleViewModel { Code = s.Code, Name = LocalizationService.GetResource(s.Name), status = s.status, enabled = s.enabled }).ToList(); //customers userManager.customers = _userManagerService.GetCustomerNames(); //machines if (context.User.Role == enRole.Customer) { var machinesModel = _userManagerService.GetCustomerMachines(usernameCustomer); userManager.machines = machinesModel.Select(s => new UserMachineViewModel { Id = s.Id, Serial = s.Serial, MachineName = s.MachineName }).ToList(); } //languages var languagesModel = _userManagerService.GetLanguages(); userManager.languages = languagesModel.Select(s => new UserLanguageViewModel { Id = s.ID, Name = s.Name }).ToList(); return(userManager); }