/// <summary> /// Create instance on AccountDto information /// </summary> /// <param name="accountDto">AccountDto instance</param> /// <returns>new instance type Account</returns> public static Account Create(AccountViewDto accountViewDto) { AccountType type; try { type = (AccountType)Enum.Parse(typeof(AccountType), accountViewDto.AccountType); } catch (ArgumentException e) { throw new InvalidDataException(e.Message); } catch (OverflowException e) { throw new InvalidDataException(e.Message); } switch (type) { case AccountType.Base: return(new BaseAccount(accountViewDto)); case AccountType.Silver: return(new SilverAccount(accountViewDto)); case AccountType.Gold: return(new GoldAccount(accountViewDto)); case AccountType.Platinum: return(new PlatinumAccount(accountViewDto)); default: throw new InvalidOperationException($"Unknown type {accountViewDto} for create account"); } }
/// <summary> /// Create instance type account from accountViewDto /// </summary> /// <param name="accountViewDto"></param> internal Account(AccountViewDto accountViewDto) { this.Id = accountViewDto.Id; this.NumberOfAccount = accountViewDto.NumberOfAccount; this.Balance = accountViewDto.Balance; this.BenefitPoints = accountViewDto.BenefitPoints; this.IsClosed = accountViewDto.IsClosed; this.UserId = accountViewDto.UserId; }
/// <summary> /// Mapper from Account to AccountViewDto /// </summary> /// <param name="account">Account</param> /// <returns>instance type AccountDto after mapping</returns> private static AccountViewDto MapView(Account account) { var accountViewDto = new AccountViewDto(); accountViewDto.Id = account.Id; accountViewDto.AccountType = account.AccountType.ToString(); accountViewDto.Balance = account.Balance; accountViewDto.BenefitPoints = account.BenefitPoints; accountViewDto.IsClosed = account.IsClosed; accountViewDto.NumberOfAccount = account.NumberOfAccount; accountViewDto.UserId = account.UserId; return(accountViewDto); }
/// <summary> /// Mapper from Account to AccountViewDto /// </summary> /// <param name="account">Account</param> /// <returns>instance type AccountDto after mapping</returns> private static AccountViewDto MapView(AccountViewModel account) { var accountViewDto = new AccountViewDto { Id = account.Id, AccountType = account.AccountType, Balance = Convert.ToDecimal(account.Balance), BenefitPoints = Convert.ToInt32(account.BenefitPoints), IsClosed = account.IsClosed, NumberOfAccount = account.NumberOfAccount, UserId = account.UserId }; return(accountViewDto); }
/// <summary> /// Mapper from AccountViewDto to Account /// </summary> /// <param name="accountViewDto">instance AccountDto</param> /// <returns></returns> private static AccountViewModel MapView(AccountViewDto accountViewDto) { var accountViewModel = new AccountViewModel { Id = accountViewDto.Id, AccountType = accountViewDto.AccountType, Balance = accountViewDto.Balance.ToString("G"), BenefitPoints = accountViewDto.BenefitPoints.ToString("G"), IsClosed = accountViewDto.IsClosed, NumberOfAccount = accountViewDto.NumberOfAccount, UserId = accountViewDto.UserId }; return(accountViewModel); }
/// <summary> /// Method for delete account /// </summary> /// <param name="accountViewDto">account view dto for close</param> /// <returns>true if account is closed</returns> public bool Close(AccountViewDto accountViewDto) { Check.NotNull(accountViewDto); var account = Mapper <AccountViewDto, Account> .MapView(accountViewDto); account.CloseValidator(); account.Close(); var accountDto = Mapper <Account, AccountDto> .Map(account); var result = accountRepository.Update(accountDto); if (result == null || result.IsClosed != account.IsClosed) { throw new InvalidOperationException($"Update after Close Account is not valid"); } accountRepository.Commit(); return(account.IsClosed); }
internal BaseAccount(AccountViewDto accountViewDto) : base(accountViewDto) { }
internal PlatinumAccount(AccountViewDto accountViewDto) : base(accountViewDto) { }
internal SilverAccount(AccountViewDto accountViewDto) : base(accountViewDto) { }
internal GoldAccount(AccountViewDto accountViewDto) : base(accountViewDto) { }
/// <summary> /// Mapper from AccountViewDto to Account /// </summary> /// <param name="accountViewDto">instance AccountDto</param> /// <returns></returns> private static Account MapView(AccountViewDto accountViewDto) { var account = AccountFactory.Create(accountViewDto); return(account); }