Beispiel #1
0
        private static async Task CreateAsync(DatabaseAccessRequest databaseAccessRequest)
        {
            using (var context = new EfPocEntities(databaseAccessRequest))
            {
                using (var transaction = context.Database.BeginTransaction(IsolationLevel.RepeatableRead))
                {
                    try
                    {
                        var member = new Member
                        {
                            FirstName      = "FirstName",
                            LastName       = "LastName",
                            HIC            = "HIC0001",
                            PlanID         = "Plan",
                            PBP            = "PBP",
                            SegmentID      = "SEG",
                            CurrentEffDate = DateTime.Now
                        };
                        context.Members.Add(member);
                        await context.SaveChangesAsync();

                        var span = new Span
                        {
                            MemberId  = member.Id,
                            SpanType  = "SECD",
                            SpanValue = "123",
                            StartDate = DateTime.Now
                        };
                        context.Spans.Add(span);
                        await context.SaveChangesAsync();

                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        transaction.Rollback();
                    }
                }
            }
        }
Beispiel #2
0
        private static async Task DeleteAsync(DatabaseAccessRequest databaseAccessRequest)
        {
            using (var context = new EfPocEntities(databaseAccessRequest))
            {
                var firstMember = await context.Members.FirstOrDefaultAsync(m => m.HIC == "HIC0001");

                context.Members.Remove(firstMember);

                var span = await context.Spans.FirstOrDefaultAsync(m => m.MemberId == firstMember.Id);

                context.Spans.Remove(span);
                await context.SaveChangesAsync();
            }
        }
Beispiel #3
0
        private static async Task UpdateAsync(DatabaseAccessRequest databaseAccessRequest)
        {
            using (var context = new EfPocEntities(databaseAccessRequest))
            {
                var firstMember = await context.Members.FirstOrDefaultAsync(m => m.HIC == "HIC0001");

                Console.WriteLine($"Before Update: {firstMember.FirstName} {firstMember.LastName} {firstMember.HIC}");
                firstMember.FirstName = firstMember.FirstName + "_Updated";
                await context.SaveChangesAsync();

                firstMember = await context.Members.FirstOrDefaultAsync(m => m.HIC == "HIC0001");

                Console.WriteLine($"After Update: {firstMember.FirstName} {firstMember.LastName} {firstMember.HIC}");
            }
        }