コード例 #1
0
        public bool AddBankUser(BankAppUserEntity bankUser)
        {
            // Lecture: Depending on the technology, the developer maybe responsible for assigning
            // the universally unique identifier (UUID) for each entity record.  The easier way to
            // do this is to use the date.  However, this may not be an option if you are
            // expecting multiple records being created at the same exact time, which is a very
            // common need in modern systems. Using one of the predefined UUID algorithm would
            // be better, specifically the UUID version 2.  If you are using a RDBMS, then use the
            // built-in capabilities instead of defining your own.

            // Assign key
            bankUser.EntityId = $"{UserTable}_{DateTime.UtcNow.ToString(FormatDefaults.UserFormat)}";

            var bankUsers = GetBankUsers();

            if (bankUsers.Contains(bankUser))
            {
                // Business Rule: Cannot add duplicate
                return(false);
            }

            return(_ds.AddOrUpdate(UserTable, bankUser));
        }