public IUserAccount Update(IUserAccount account) { List <KeyValuePair <string, string> > accountFailedValidations = account.Validate(); if (accountFailedValidations.Any()) { throw new ValidationFailedException(accountFailedValidations); } IAccountDetail currentPerson = _accountsRepository.GetById(account.AccountId); if (currentPerson.Email.ToLower() != account.Email) { //Validate that the new email doesn't exist IPerson newEmailPerson = _personsRepository.GetByEmail(account.Email); if (newEmailPerson.Id != 0) { throw new EmailAlreadyInUseException($"Email '{account.Email}' is already in use"); } } _personsRepository.Update(new PersonDTO() { Name = account.Name, Email = account.Email, LastName = account.LastName }); _uow.Save(); IAccountDetail updatedUser = _accountsRepository.GetById(account.AccountId); return(new UserAccount(updatedUser)); }
public IAccountDetail GetByIdentityProviderId(string id) { IAccountDetail accountDb = _db.AccountDetails.FirstOrDefault(x => x.IdentityProviderId == id); accountDb ??= new NullAccountDetail(); return(accountDb); }
public IAccountDetail GetById(long id) { IAccountDetail accountDb = _db.AccountDetails.FirstOrDefault(x => x.AccountId == id); accountDb ??= new NullAccountDetail(); return(accountDb); }
public IUserAccount Delete(IUserAccount account) { _accountsRepository.DeleteById(account.AccountId); IAccountDetail disabledAccount = _accountsRepository.GetById(account.AccountId); return(new UserAccount(disabledAccount)); }
public UserAccount(IAccountDetail account) { AccountId = account.AccountId; IdentityProviderId = account.IdentityProviderId; Name = account.Name; LastName = account.LastName; Email = account.Email; PersonId = account.PersonId; AccountOwnerId = account.AccountOwnerId; IsActive = account.IsActive; AccountType = (AccountTypes)account.AccountTypeId; PersonType = (PersonTypes)account.PersonTypeId; }
/// <summary> /// 取得帐户信息,没有则创建(实时) /// </summary> /// <param name="account"></param> /// <param name="accountType"></param> /// <param name="transactionType"></param> /// <returns></returns> public IAccountDetail GetAccount(string account, int accountType, int transactionType) { var info = QueryItem(b => b.Account == account && b.TransactionType == transactionType && b.AccountType == accountType); if (info == null) { info = new IAccountDetail(); info.Account = account; info.AccountType = accountType; info.TransactionType = transactionType; CreateAccount(info); } return(info); }
//public static IAccountDetail GetAccount(string account, int transactionType) //{ // return GetAccount(account, 0, transactionType); //} /// <summary> /// 取得帐号信息,没有则创建(实时) /// </summary> /// <param name="account"></param> /// <param name="accountType"></param> /// <param name="transactionType"></param> /// <returns></returns> public static IAccountDetail GetAccount(string account, int accountType, int transactionType) { DBExtend helper = dbHelper; IAccountDetail info = helper.QueryItem <IAccountDetail>(b => b.Account == account && b.TransactionType == transactionType && b.AccountType == accountType); if (info == null) { info = new IAccountDetail(); info.Account = account; info.AccountType = accountType; info.TransactionType = transactionType; CreateAccount(info); } return(info); }
public IUserAccount Create(IUserAccount account) { List <KeyValuePair <string, string> > accountFailedValidations = account.Validate(); if (accountFailedValidations.Any()) { throw new ValidationFailedException(accountFailedValidations); } //Validate if email doesn't exist IPerson personWithEmail = _personsRepository.GetByEmail(account.Email); if (personWithEmail.Id != 0) { throw new EmailAlreadyInUseException($"Email '{account.Email}' is already in use"); } IPerson personDb = new PersonDTO() { Email = account.Email, PersonTypeId = (int)account.PersonType, Name = account.Name, LastName = account.LastName }; _personsRepository.Add(personDb); _uow.Save(); IPerson savedPerson = _personsRepository.GetByEmail(account.Email); IAccount accountDb = new AccountDTO() { IsActive = true, AccountTypeId = (int)account.AccountType, IdentityProviderId = account.IdentityProviderId, PersonId = savedPerson.Id }; _accountsRepository.Add(accountDb); _uow.Save(); IAccountDetail createdAccount = _accountsRepository.GetByIdentityProviderId(account.IdentityProviderId); return(new UserAccount(createdAccount)); }
public void ShouldReturnNullAccountIfIdDoesntExist() { //Arrange Account account = new Account() { PersonId = 1, AccountTypeId = 1 }; _db.Accounts.Add(account); _db.SaveChanges(); long expectedId = account.Id + 1; //Act IAccountDetail accountDb = _uow.AccountsRepository.GetById(expectedId); //Assert Assert.NotNull(accountDb); Assert.AreEqual(0, accountDb.AccountId); }
public void ShouldGetAccountById() { //Arrange Account account = new Account() { PersonId = 1, AccountTypeId = 1, IsActive = true }; _db.Accounts.Add(account); _db.SaveChanges(); long expectedId = account.Id; //Act IAccountDetail accountDb = _uow.AccountsRepository.GetById(expectedId); //Assert Assert.NotNull(accountDb); Assert.AreEqual(expectedId, accountDb.AccountId); }
public void ShouldReturnNullAccountIfIdentityProviderIdDoesntExist() { //Arrange Account account = new Account() { PersonId = 1, AccountTypeId = 1, IdentityProviderId = "000-000-000" }; _db.Accounts.Add(account); _db.SaveChanges(); long expectedId = 0; //Act IAccountDetail accountDb = _uow.AccountsRepository.GetByIdentityProviderId("111-111-111"); //Assert Assert.NotNull(accountDb); Assert.AreEqual(expectedId, accountDb.AccountId); }
/// <summary> /// 获取帐户详细信息,按帐户ID /// </summary> /// <param name="accountId"></param> /// <returns></returns> public IAccountDetail GetAccountFromCache(int accountId) { if (detailInfoCache.ContainsKey(accountId)) { return(detailInfoCache[accountId]); } IAccountDetail info = QueryItem(b => b.Id == accountId); if (info == null) { return(null); } lock (lockObj) { if (!detailInfoCache.ContainsKey(accountId)) { detailInfoCache.Add(accountId, info); } } return(info); }
/// <summary> /// 取得帐户ID(从缓存) /// </summary> /// <param name="account"></param> /// <param name="accountType">帐号类型,用以区分不同渠道用户</param> /// <param name="transactionType"></param> /// <returns></returns> public int GetAccountId(string account, int accountType, int transactionType) { int id = 0; foreach (var item in detailInfoCache.Values) { if (item.Account == account && item.AccountType == accountType && item.TransactionType == transactionType) { return(item.Id); } } IAccountDetail detail = GetAccount(account, accountType, transactionType); lock (lockObj) { if (!detailInfoCache.ContainsKey(detail.Id)) { detailInfoCache.Add(detail.Id, detail); } } return(detail.Id); }
//static Dictionary<string, int> accountCache = new Dictionary<string, int>(); /// <summary> /// 使用默认用户类型取得帐户ID /// </summary> /// <param name="account"></param> /// <param name="transactionType"></param> /// <returns></returns> //public static int GetAccountId(string account, int transactionType) //{ // return GetAccountId(account, 0, transactionType); //} /// <summary> /// 取得帐户ID(从缓存) /// </summary> /// <param name="account"></param> /// <param name="accountType">帐号类型,用以区分不同渠道用户</param> /// <param name="transactionType"></param> /// <returns></returns> public static int GetAccountId(string account, int accountType, int transactionType) { int id = 0; foreach (var item in detailInfoCache.Values) { if (item.Account == account && item.AccountType == accountType && item.TransactionType == transactionType) { return(item.Id); } } IAccountDetail detail = GetAccount(account, accountType, transactionType); lock (lockObj) { if (!detailInfoCache.ContainsKey(detail.Id)) { detailInfoCache.Add(detail.Id, detail); } } return(detail.Id); //string key = string.Format("{0}_{1}_{2}", account, accountType, transactionType); ////加入缓存机制 //if (accountCache.ContainsKey(key)) //{ // return accountCache[key]; //} //IAccountDetail item = GetAccount(account,accountType, transactionType); //if (!accountCache.ContainsKey(key)) //{ // lock (lockObj) // { // accountCache.Add(key, item.Id); // } //} //return item.Id; }
public IUserAccount GetById(long id) { IAccountDetail account = _accountsRepository.GetById(id); return(new UserAccount(account)); }
/// <summary> /// 创建帐户 /// </summary> /// <param name="info"></param> /// <returns></returns> public bool CreateAccount(IAccountDetail info) { Add(info); return(true); }
/// <summary> /// 控制器初始化 /// </summary> public override void Init() { ifrmAllAccount = (IFrmAllAccount)iBaseView["FrmAllAccount"]; iChargeDetail = (IChargeDetail)iBaseView["FrmChargeDetail"]; iAccountDetail = (IAccountDetail)iBaseView["FrmAccountDetail"]; }
/// <summary> /// 控制区初始化 /// </summary> public override void Init() { iAccountDetail = (IAccountDetail)DefaultView; }
public IUserAccount GetByGlobalId(string id) { IAccountDetail account = _accountsRepository.GetByIdentityProviderId(id); return(new UserAccount(account)); }