示例#1
0
        private void EnsureDatabaseCreated()
        {
            var contextOptions = _container.GetInstance <DbContextOptions <GreetingContext> >();
            var context        = new GreetingContext(contextOptions);

            context.Database.EnsureCreated();
        }
示例#2
0
        public async Task RegreetAsync(Guid greetingId, CancellationToken ct = new CancellationToken())
        {
            Greeting greeting;

            using (var uow = new GreetingContext(_options))
            {
                greeting = await uow.Greetings.SingleOrDefaultAsync(g => g.Id == greetingId);
            }

            if (greeting == null)
            {
                Console.WriteLine("Received Greeting. Message Follows");
                Console.WriteLine("----------------------------------");
                Console.WriteLine("Could not read message}");
                Console.WriteLine("----------------------------------");
                Console.WriteLine("Greeting Id from Originator Follows");
                Console.WriteLine("----------------------------------");
                Console.WriteLine(greetingId.ToString());
                Console.WriteLine("----------------------------------");
                Console.WriteLine("Message Ends");
            }
            else
            {
                Console.WriteLine("Received Greeting. Message Follows");
                Console.WriteLine("----------------------------------");
                Console.WriteLine(greeting.Message);
                Console.WriteLine("----------------------------------");
                Console.WriteLine("Greeting Id from Originator Follows");
                Console.WriteLine("----------------------------------");
                Console.WriteLine(greetingId.ToString());
                Console.WriteLine("----------------------------------");
                Console.WriteLine("Message Ends");
            }
        }
示例#3
0
 public async Task DeleteAsync(Guid itemToDelete, CancellationToken cancellationToken = new CancellationToken())
 {
     using (var uow = new GreetingContext(_options))
     {
         var repository = new GreetingRepositoryAsync(uow);
         await repository.DeleteAsync(itemToDelete, cancellationToken);
     }
 }
示例#4
0
 public async Task AddAsync(Guid id, string message, CancellationToken cancellationToken = new CancellationToken())
 {
     using (var uow = new GreetingContext(_options))
     {
         var repository = new GreetingRepositoryAsync(uow);
         var savedItem  = await repository.AddAsync(new Greeting { Id = id, Message = message }, cancellationToken);
     }
 }
示例#5
0
        public async Task <GreetingsByIdResult> GetAsync(Guid id, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = new GreetingContext(_options))
            {
                var greeting = await uow.Greetings.SingleAsync(t => t.Id == id, cancellationToken : cancellationToken);

                return(new GreetingsByIdResult(greeting));
            }
        }
        public override async Task <GreetingsByIdResult> ExecuteAsync(GreetingsByIdQuery query, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = new GreetingContext(_options))
            {
                var greeting = await uow.Greetings.SingleAsync(t => t.Id == query.Id, cancellationToken : cancellationToken);

                return(new GreetingsByIdResult(greeting));
            }
        }
        public override async Task <DeleteGreetingCommand> HandleAsync(DeleteGreetingCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = new GreetingContext(_options))
            {
                var repository = new GreetingRepositoryAsync(uow);
                await repository.DeleteAsync(command.Id, cancellationToken);
            }


            return(await base.HandleAsync(command, cancellationToken));
        }
示例#8
0
 public ActionResult Index(string name)
 {
     using (GreetingContext dbContext = new GreetingContext())
     {
         dbContext.Greetings.Add(new Greeting {
             Name = name
         });
         dbContext.SaveChanges();
     }
     return(View((object)name));
 }
        public override async Task <AddGreetingCommand> HandleAsync(AddGreetingCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = new GreetingContext(_options))
            {
                var repository = new GreetingRepositoryAsync(uow);
                var savedItem  = await repository.AddAsync(
                    new Greeting { Id = command.Id, Message = command.Message },
                    cancellationToken
                    );
            }

            return(await base.HandleAsync(command, cancellationToken));
        }
示例#10
0
        public ActionResult List()
        {
            List <Greeting> greetings;

            using (GreetingContext dbContext = new GreetingContext())
            {
                greetings = dbContext.Greetings.ToList();
            }

            var viewModel = new ListViewModel(greetings);

            return(View(viewModel));
        }
        public override async Task <GreetingsAllResult> ExecuteAsync(GreetingsAllQuery query, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = new GreetingContext(_options))
            {
                var greetings = await uow.Greetings.ToArrayAsync(cancellationToken);

                var results = new GreetingsByIdResult[greetings.Length];
                for (var i = 0; i < greetings.Length; i++)
                {
                    results[i] = new GreetingsByIdResult(greetings[i]);
                }
                return(new GreetingsAllResult(results));
            }
        }
 public GreetingRepositoryAsync(GreetingContext uow)
 {
     _uow = uow;
 }
示例#13
0
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <GreetingContext>().Options;

            _context = new GreetingContext(options);
        }