示例#1
0
 public bool UserExists(Func <UserSummary, bool> predicate)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         return(db.UserSummaries.Any(predicate));
     }
 }
示例#2
0
        public void InsertAccount(Guid tenantId, Guid accountId, string accountCode, string accountStatus, Guid personId)
        {
            using (var db = new QueryDbContext(DatabaseConnectionString))
            {
                var account = new AccountSummary
                {
                    TenantIdentifier  = tenantId,
                    AccountIdentifier = accountId,
                    AccountCode       = accountCode,
                    AccountStatus     = accountStatus,
                    OwnerIdentifier   = personId
                };
                db.AccountSummaries.Add(account);
                db.SaveChanges();

                if (accountStatus == "Open")
                {
                    var person = db.PersonSummaries.Single(x => x.PersonIdentifier == personId);
                    person.OpenAccountCount++;
                    db.SaveChanges();
                }

                Denormalize();
            }
        }
示例#3
0
 /// <summary>
 /// Executes a stored procedure responsible for denormalization of query table rows. We try to avoid joins in
 /// the query database tables so that projections are as simple as possible, and so that search functions are
 /// as fast as possible. The Denormalized stored procedure is expected to fill in any blanks or mismatches.
 /// </summary>
 /// <example>
 /// Suppose we have a query table storing Account records. It contains a ContactIdentifier column and a
 /// ContactName column. The event that inserts new Account records has a ContactIdentifier but not a
 /// ContactName. We rely on the Denormalize procedure to update the ContactName after the Account row is
 /// inserted.
 /// </example>
 private void Denormalize()
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         db.Database.ExecuteSqlCommand("EXEC queries.Denormalize");
     }
 }
示例#4
0
 public UserSummary SelectUserSummary(Guid user)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         return(db.UserSummaries.SingleOrDefault(x => x.UserIdentifier == user));
     }
 }
示例#5
0
 public PersonSummary SelectPersonSummary(Guid personId)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         return(db.PersonSummaries.Single(x => x.PersonIdentifier == personId));
     }
 }
示例#6
0
 public AccountSummary SelectAccountSummary(Guid accountId)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         return(db.AccountSummaries.Single(x => x.AccountIdentifier == accountId));
     }
 }
示例#7
0
 public void DeletePerson(Guid personId)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         var p = db.PersonSummaries.Single(x => x.PersonIdentifier == personId);
         db.PersonSummaries.Remove(p);
         db.SaveChanges();
     }
 }
示例#8
0
 public void UpdateUserStatus(Guid user, string status)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         var summary = db.UserSummaries.Single(x => x.UserIdentifier == user);
         summary.UserRegistrationStatus = status;
         db.SaveChanges();
     }
 }
示例#9
0
 public void UpdateTransfer(Guid aggregateIdentifier, string status, string activity)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         var summary = db.TransferSummaries.Single(x => x.TransferIdentifier == aggregateIdentifier);
         summary.TransferStatus   = status;
         summary.TransferActivity = activity;
         db.SaveChanges();
     }
 }
示例#10
0
        public void UpdatePersonName(Guid personId, string personName)
        {
            using (var db = new QueryDbContext(DatabaseConnectionString))
            {
                var person = db.PersonSummaries.Single(x => x.PersonIdentifier == personId);
                person.PersonName = personName;
                db.SaveChanges();

                Denormalize();
            }
        }
示例#11
0
        public void IncreaseAccountBalance(Guid accountId, decimal amount)
        {
            using (var db = new QueryDbContext(DatabaseConnectionString))
            {
                var account = db.AccountSummaries.Single(x => x.AccountIdentifier == accountId);
                account.AccountBalance += amount;

                var person = db.PersonSummaries.Single(x => x.PersonIdentifier == account.OwnerIdentifier);
                person.TotalAccountBalance += amount;

                db.SaveChanges();
            }
        }
示例#12
0
 public void InsertUser(Guid user, string name, string password, string status)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         var summary = new UserSummary
         {
             UserIdentifier         = user,
             LoginName              = name,
             LoginPassword          = password,
             UserRegistrationStatus = status
         };
         db.UserSummaries.Add(summary);
         db.SaveChanges();
     }
 }
示例#13
0
 public void InsertPerson(Guid tenantId, Guid personId, string personName, DateTimeOffset personRegistered)
 {
     using (var db = new QueryDbContext(DatabaseConnectionString))
     {
         var summary = new PersonSummary
         {
             TenantIdentifier = tenantId,
             PersonIdentifier = personId,
             PersonName       = personName,
             PersonRegistered = personRegistered
         };
         db.PersonSummaries.Add(summary);
         db.SaveChanges();
     }
 }
示例#14
0
        public void UpdateAccountStatus(Guid accountId, string accountStatus)
        {
            using (var db = new QueryDbContext(DatabaseConnectionString))
            {
                var account = db.AccountSummaries.Single(x => x.AccountIdentifier == accountId);
                account.AccountStatus = accountStatus;

                if (accountStatus != "Open")
                {
                    var person = db.PersonSummaries.Single(x => x.PersonIdentifier == account.OwnerIdentifier);
                    person.OpenAccountCount--;
                }

                db.SaveChanges();
            }
        }
示例#15
0
        public void InsertTransfer(Guid tenant, Guid transfer, string status, Guid fromAccount, Guid toAccount, decimal amount)
        {
            using (var db = new QueryDbContext(DatabaseConnectionString))
            {
                var summary = new TransferSummary
                {
                    TenantIdentifier      = tenant,
                    TransferIdentifier    = transfer,
                    TransferStatus        = status,
                    TransferAmount        = amount,
                    FromAccountIdentifier = fromAccount,
                    ToAccountIdentifier   = toAccount
                };
                db.TransferSummaries.Add(summary);
                db.SaveChanges();
            }

            Denormalize();
        }