public IEnumerable <CajaOutput> ListAll() { var vRecords = _Manager.GetAllList(AbpSession.GetAgenciaId()).ToList(); List <CajaOutput> vResult = Mapper.Map <List <Caja>, List <CajaOutput> >(vRecords); return(vResult); }
public virtual async Task <ActionResult> Register(RegisterViewModel model) { try { CheckModelState(); //Create user var user = new User { Name = model.Name, Surname = model.Surname, EmailAddress = model.EmailAddress, IsActive = true }; //Get external login info if possible ExternalLoginInfo externalLoginInfo = null; if (model.IsExternalLogin) { externalLoginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); if (externalLoginInfo == null) { throw new ApplicationException("Can not external login!"); } user.Logins = new List <UserLogin> { new UserLogin { LoginProvider = externalLoginInfo.Login.LoginProvider, ProviderKey = externalLoginInfo.Login.ProviderKey } }; if (model.UserName.IsNullOrEmpty()) { model.UserName = model.EmailAddress; } model.Password = Authorization.Users.User.CreateRandomPassword(); if (string.Equals(externalLoginInfo.Email, model.EmailAddress, StringComparison.InvariantCultureIgnoreCase)) { user.IsEmailConfirmed = true; } } else { //Username and Password are required if not external login if (model.UserName.IsNullOrEmpty() || model.Password.IsNullOrEmpty()) { throw new UserFriendlyException(L("FormIsNotValidMessage")); } } user.UserName = model.UserName; user.Password = new PasswordHasher().HashPassword(model.Password); //Switch to the tenant _unitOfWorkManager.Current.EnableFilter(AbpDataFilters.MayHaveTenant); //TODO: Needed? _unitOfWorkManager.Current.SetTenantId(AbpSession.GetTenantId()); _unitOfWorkManager.Current.SetTenantId(AbpSession.GetTenantId()); _unitOfWorkManager.Current.SetFilterParameter(DataFilters.MustHaveAgency, DataFilters.MustHaveAgencyParam, AbpSession.GetAgenciaId()); //Add default roles user.Roles = new List <UserRole>(); foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync()) { user.Roles.Add(new UserRole { RoleId = defaultRole.Id }); } //Save user CheckErrors(await _userManager.CreateAsync(user)); await _unitOfWorkManager.Current.SaveChangesAsync(); //Directly login if possible if (user.IsActive) { AbpLoginResult <Tenant, User> loginResult; if (externalLoginInfo != null) { loginResult = await _logInManager.LoginAsync(externalLoginInfo.Login, GetTenancyNameOrNull()); } else { loginResult = await GetLoginResultAsync(user.UserName, model.Password, GetTenancyNameOrNull()); } if (loginResult.Result == AbpLoginResultType.Success) { await SignInAsync(loginResult.User, loginResult.Identity); return(Redirect(Url.Action("Index", "Home"))); } Logger.Warn("New registered user could not be login. This should not be normally. login result: " + loginResult.Result); } //If can not login, show a register result page return(View("RegisterResult", new RegisterResultViewModel { TenancyName = GetTenancyNameOrNull(), NameAndSurname = user.Name + " " + user.Surname, UserName = user.UserName, EmailAddress = user.EmailAddress, IsActive = user.IsActive })); } catch (UserFriendlyException ex) { ViewBag.IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled; ViewBag.ErrorMessage = ex.Message; return(View("Register", model)); } }