Ejemplo n.º 1
0
 public AccountDTO AddAccountToCompany(int currentAccountId, AccountCreateDTO newaccount)
 {
     try {
         var current        = _accountRepository.GetAccount(currentAccountId);
         var currentcompany = current.Company;
         if (currentcompany != null)
         {
             if ((current.Type == eAccountType.Owner || current.Type == eAccountType.Administrator) && IsVatInDatabase(currentcompany.VAT) && !IsEmailInDatabase(newaccount.Email))
             {
                 Account account = Mapper.Map <AccountCreateDTO, Account>(newaccount);
                 Company company = currentcompany;
                 string  salt    = PasswordValidationService.GetInstance().GenerateSalt();
                 account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(newaccount.Password, salt);
                 account.Salt     = salt;
                 account.Company  = _companyRepository.AddNewCompany(company);
                 account          = _accountRepository.AddNewAccount(account);
                 var accountviewmodel = Mapper.Map <Account, AccountDTO>(account);
                 return(Mapper.Map <Account, AccountDTO>(current));
             }
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
     return(null);
 }
Ejemplo n.º 2
0
        public AccountDTO Login(string username, string pass)
        {
            AccountDTO accountViewModel = null;

            try
            {
                if (!string.IsNullOrWhiteSpace(username))
                {
                    Account account = _accountRepository.GetAccount(username);
                    if (PasswordValidationService.GetInstance().ValidatePassword(pass, account.Password, account.Salt))
                    {
                        //_log.LogLoginLogout(account.ID, eLoginType.Login);
                        accountViewModel = Mapper.Map <Account, AccountDTO>(account);
                        if (account.Company != null)
                        {
                            var company = Mapper.Map <Company, CompanyDTO>(account.Company);
                            accountViewModel.Company = company;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(accountViewModel);
        }
Ejemplo n.º 3
0
        public AccountDTO CreateNewAccount(AccountCreateDTO newaccount)
        {
            try {
                if (newaccount.Email.IsValidEmail() && !IsEmailInDatabase(newaccount.Email))
                {
                    Account account = Mapper.Map <AccountCreateDTO, Account>(newaccount);

                    string salt = PasswordValidationService.GetInstance().GenerateSalt();
                    account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(newaccount.Password, salt);
                    account.Salt     = salt;
                    account          = _accountRepository.AddNewAccount(account);
                    var accountviewmodel = Mapper.Map <Account, AccountDTO>(account);
                    return(accountviewmodel);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(null);
        }
Ejemplo n.º 4
0
 public bool UpdatePassword(AccountUpdatePasswordViewModel accountviewmodel)
 {
     try
     {
         var    account = _accountRepository.GetAccount(accountviewmodel.ID);
         string salt    = PasswordValidationService.GetInstance().GenerateSalt();
         string oldpass = PasswordValidationService.GetInstance().GenerateCryptedPassword(accountviewmodel.OldPassword, account.Salt);
         if (oldpass.Equals(account.Password) && accountviewmodel.NewPassword.Equals(accountviewmodel.ConfirmedPassword))
         {
             account.Password = PasswordValidationService.GetInstance().GenerateCryptedPassword(accountviewmodel.NewPassword, salt);
             account.Salt     = salt;
             _accountRepository.UpdateAccount(account);
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }