public AddUserAccountViewModel(UsersAccounts userAccount)
 {
     this.UserId      = userAccount.UserId;
     this.AccountId   = userAccount.AccountId;
     this.UserName    = userAccount.User.Name;
     this.AccountName = userAccount.Account.Nickname;
 }
Example #2
0
        public async Task <UsersAccounts> AddAccountAsync(Guid userId, Guid accountId)
        {
            var userAccount = new UsersAccounts()
            {
                UserId    = userId,
                AccountId = accountId
            };

            await this.context.UsersAccounts.AddAsync(userAccount);

            await this.context.SaveChangesAsync();

            return(userAccount);
        }
Example #3
0
        public async Task <UsersAccounts> AddUserAccountAsync(Guid userId, Guid accountId)
        {
            var existUserAccount = await this.context.UsersAccounts
                                   .Where(ua => ua.UserId == userId)
                                   .SingleOrDefaultAsync(ua => ua.AccountId == accountId);

            if (existUserAccount != null)
            {
                throw new ArgumentException("This account is already registered for this user");
            }

            UsersAccounts userAccount = new UsersAccounts()
            {
                UserId    = userId,
                AccountId = accountId
            };

            await this.context.UsersAccounts.AddAsync(userAccount);

            await this.context.SaveChangesAsync();

            return(userAccount);
        }