예제 #1
0
        static void Main(string[] args)
        {
            using var dbContext = new CardDBContext();

            //  dbContext.Database.EnsureCreated();  --> Tables "Card" and "Transaction" have been created in db "CardDb"
            var card1 = new Card()
            {
                CardNumber   = "1111111111111111",
                AvailBalance = 1500M
            };

            card1.Trn.Add(new Transaction()
            {
                TrnType         = TransactionType.Ecommerce,
                LimitAm0        = 200M,
                LimitAm1        = 0M,
                AggregateAmount = 200M,
                CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd")
            });

            card1.Trn.Add(new Transaction()
            {
                TrnType         = TransactionType.CardPresent,
                LimitAm0        = 200M,
                LimitAm1        = 700M,
                AggregateAmount = 900M,
                CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd")
            });


            dbContext.Add(card1);
            dbContext.SaveChanges();
        }
예제 #2
0
        public void Test1()
        {
            using var dbContext = new CardDBContext();

            var card1 = new Card();

            card1.CardNumber   = "1111111111111111";
            card1.AvailBalance = 1500M;

            dbContext.Add(card1);
            dbContext.SaveChanges();

            var Trn1 = new Transaction();

            Trn1.TrnType         = TransactionType.Ecommerce;
            Trn1.LimitAm0        = 200M;
            Trn1.LimitAm1        = 0M;
            Trn1.AggregateAmount = 200M;
            Trn1.CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd");

            card1.AvailBalance = card1.AvailBalance - Trn1.LimitAm0 - Trn1.LimitAm1;

            if (IsGreater(Trn1.LimitAm0, Trn1.LimitAm0, card1.AvailBalance))
            {
                dbContext.Add(Trn1);
                dbContext.SaveChanges();
            }


            var Trn2 = new Transaction();

            Trn2.TrnType         = TransactionType.CardPresent;
            Trn2.LimitAm0        = 200M;
            Trn2.LimitAm1        = 700M;
            Trn2.AggregateAmount = Trn2.LimitAm0 + Trn2.LimitAm1;
            Trn2.CreatedDate     = DateTimeOffset.Now.Date.ToString("yyyy-MM-dd");

            card1.AvailBalance = card1.AvailBalance - Trn2.LimitAm0 - Trn2.LimitAm1;
            dbContext.SaveChanges();

            if (IsGreater(Trn2.LimitAm0, Trn2.LimitAm0, card1.AvailBalance))
            {
                dbContext.Add(Trn2);
                dbContext.SaveChanges();
            }
        }
예제 #3
0
 public async Task <int> Create(Card card)
 {
     try {
         _context.Add(card);
         return(await _context.SaveChangesAsync());
     }
     catch (Exception ex)
     {
         return(-1);
     }
 }