示例#1
0
        /// <summary>
        /// updates shared user data
        /// </summary>
        /// <param name="sam"> SharedAccount Model </param>
        public SharedAccount UpdateSharedAccount(SharedAccountModel sam)
        {
            try
            {
                SharedAccount sharedAccount = null;
                if (sam != null)
                {
                    using (var _ctx = new ChinmayaEntities())
                    {
                        sharedAccount = _ctx.SharedAccounts.Where(x => x.From_UserId == sam.From_UserId).FirstOrDefault();

                        if (sharedAccount != null)
                        {
                            sharedAccount.IsApproved        = sam.IsApproved;
                            sharedAccount.IsDeclined        = sam.IsDeclined;
                            sharedAccount.UpdatedDate       = DateTime.Now;
                            _ctx.Entry(sharedAccount).State = EntityState.Modified;
                            _ctx.SaveChanges();
                        }
                    }
                }
                return(sharedAccount);
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        public async Task <SharedAccount> CreateSharedAccountAsync(SharedAccountAddModel sharedAccountModel)
        {
            if (sharedAccountModel == null)
            {
                throw new ArgumentNullException(nameof(sharedAccountModel));
            }

            _dataProtectionService.Validate();

            var sharedAccount = new SharedAccount()
            {
                Name              = sharedAccountModel.Name,
                Urls              = Validation.VerifyUrls(sharedAccountModel.Urls),
                Apps              = sharedAccountModel.Apps,
                Login             = await ValidateAccountNameAndLoginAsync(sharedAccountModel.Name, sharedAccountModel.GetLogin()),
                LoginType         = sharedAccountModel.LoginType,
                Password          = _dataProtectionService.Encrypt(sharedAccountModel.Password),
                PasswordChangedAt = DateTime.UtcNow
            };

            if (!string.IsNullOrWhiteSpace(sharedAccountModel.OtpSecret))
            {
                Validation.VerifyOtpSecret(sharedAccountModel.OtpSecret);
                sharedAccount.OtpSecret          = _dataProtectionService.Encrypt(sharedAccountModel.OtpSecret);
                sharedAccount.OtpSecretChangedAt = DateTime.UtcNow;
            }

            return(await _sharedAccountRepository.AddAsync(sharedAccount));
        }
示例#3
0
        /// <summary>
        /// adds shared user data
        /// </summary>
        /// <param name="sam"> SharedAccount Model </param>
        public void PostSharedAccount(SharedAccountModel sam)
        {
            using (var _ctx = new ChinmayaEntities())
            {
                try
                {
                    var config = new MapperConfiguration(cfg =>
                    {
                        cfg.CreateMap <SharedAccountModel, SharedAccount>();
                    });
                    IMapper mapper = config.CreateMapper();

                    SharedAccount sa = new SharedAccount();
                    mapper.Map(sam, sa);

                    _ctx.SharedAccounts.Add(sa);
                    _ctx.SaveChanges();
                }

                catch
                {
                    throw;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Mapping db entity to updating account model
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public SharedAccountEditModel Initialize(SharedAccount account)
        {
            Id        = account.Id;
            Name      = account.Name;
            Urls      = account.Urls;
            Apps      = account.Apps;
            LoginType = account.LoginType;

            switch (LoginType)
            {
            case LoginType.WebApp:
                Login = account.Login;
                break;

            case LoginType.Local:
                Login = account.Login.Replace(@".\", "");
                break;

            case LoginType.Domain:
                Login  = account.Login.Split(@"\").LastOrDefault();
                Domain = account.Login.Split(@"\").FirstOrDefault();
                break;

            case LoginType.AzureAD:
                Login = account.Login.Replace(@"AzureAD\", "");
                break;

            case LoginType.Microsoft:
                Login = account.Login.Replace(@"@\", "");
                break;
            }

            return(this);
        }
示例#5
0
 /// <summary>
 /// Mapping account updating model to db entity
 /// </summary>
 /// <param name="account"></param>
 /// <returns></returns>
 public SharedAccount SetNewValue(SharedAccount account)
 {
     account.Name      = Name;
     account.Urls      = Urls;
     account.Apps      = Apps;
     account.LoginType = LoginType;
     account.Login     = GetLogin();
     return(account);
 }
示例#6
0
        public async Task <List <string> > EditSharedAccountOtpAsync(SharedAccount sharedAccount, AccountOtp accountOtp)
        {
            if (sharedAccount == null)
            {
                throw new ArgumentNullException(nameof(sharedAccount));
            }
            if (accountOtp == null)
            {
                throw new ArgumentNullException(nameof(accountOtp));
            }

            _dataProtectionService.Validate();

            Validation.VerifyOtpSecret(accountOtp.OtpSecret);

            // Update Shared Account
            sharedAccount.OtpSecret          = !string.IsNullOrWhiteSpace(accountOtp.OtpSecret) ? _dataProtectionService.Encrypt(accountOtp.OtpSecret) : null;
            sharedAccount.OtpSecretChangedAt = !string.IsNullOrWhiteSpace(accountOtp.OtpSecret) ? new DateTime?(DateTime.UtcNow) : null;

            // Get all accounts where used this shared account
            var accounts = await _accountService
                           .Query()
                           .Include(x => x.Employee.HardwareVaults)
                           .Where(x => x.SharedAccountId == sharedAccount.Id && x.Deleted == false)
                           .AsNoTracking()
                           .ToListAsync();

            List <HardwareVaultTask> tasks = new List <HardwareVaultTask>();

            foreach (var account in accounts)
            {
                account.UpdatedAt    = DateTime.UtcNow;
                account.OtpUpdatedAt = sharedAccount.OtpSecretChangedAt;

                foreach (var vault in account.Employee.HardwareVaults)
                {
                    tasks.Add(_hardwareVaultTaskService.GetAccountOtpUpdateTask(vault.Id, account.Id, sharedAccount.OtpSecret));
                }
            }

            using (TransactionScope transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                await _sharedAccountRepository.UpdateOnlyPropAsync(sharedAccount, new string[] { nameof(SharedAccount.OtpSecret), nameof(SharedAccount.OtpSecretChangedAt) });

                await _accountService.UpdateOnlyPropAsync(accounts, new string[] { nameof(Account.UpdatedAt), nameof(Account.OtpUpdatedAt) });

                await _hardwareVaultTaskService.AddRangeTasksAsync(tasks);

                transactionScope.Complete();
            }

            return(accounts.SelectMany(x => x.Employee.HardwareVaults.Select(s => s.Id)).ToList());
        }
示例#7
0
        public void Register(SharedAccount sAccount)
        {
            Debug.WriteLine(AccountProvider.GetFeaturesByAppId("tlwr"));
            Account account = Account.CreateAccount();

            account.UserName    = sAccount.name;
            account.DisplayName = sAccount.displayName;
            account.DomainName  = sAccount.domainName;
            account.EmailId     = sAccount.email;
            account.IconPath    = sAccount.iconPath;
            AccountService.AddAccount(account);
        }
示例#8
0
        protected override async Task OnInitializedAsync()
        {
            SheredAccountSevice            = ScopedServices.GetRequiredService <ISharedAccountService>();
            EmployeeService                = ScopedServices.GetRequiredService <IEmployeeService>();
            RemoteDeviceConnectionsService = ScopedServices.GetRequiredService <IRemoteDeviceConnectionsService>();

            var count = await SheredAccountSevice.GetSharedAccountsCountAsync(new DataLoadingOptions <SharedAccountsFilter>());

            SharedAccounts = await SheredAccountSevice.GetSharedAccountsAsync(new DataLoadingOptions <SharedAccountsFilter>
            {
                Take          = count,
                SortedColumn  = nameof(Employee.FullName),
                SortDirection = ListSortDirection.Ascending
            });

            SelectedSharedAccount = SharedAccounts.FirstOrDefault();
        }
示例#9
0
 public async Task UnchangedAsync(SharedAccount account)
 {
     await _sharedAccountRepository.UnchangedAsync(account);
 }
示例#10
0
 protected override void UpdateEntity(UpdateAccountDto updateItemDto, SharedAccount entity)
 {
     entity.Update(updateItemDto.FirstName, updateItemDto.LastName, updateItemDto.Email);
 }