public static async Task SeedDataAsync(ITemplateDbContext context)
        {
            if (context.Customers.Any())
            {
                return;
            }
            await SeedValuesAsync(context);
            await SeedOrdersAsync(context);
            await SeedCustomersAsync(context);

            await context.SaveChangesAsync(CancellationToken.None);
        }
예제 #2
0
        private async Task SeedManagersAsync(CancellationToken cancellationToken)
        {
            var managers = new[]
            {
                new Manager {
                    Id = Guid.NewGuid().ToString(), FirstName = "Ivan", LastName = "Ivanov", ReceptionDay = WeekDay.Monday, CreatedOn = DateTime.UtcNow
                },
                new Manager {
                    Id = Guid.NewGuid().ToString(), FirstName = "Petar", LastName = "Petrov", ReceptionDay = WeekDay.Monday, CreatedOn = DateTime.UtcNow
                },
                new Manager {
                    Id = Guid.NewGuid().ToString(), FirstName = "Sasho", LastName = "Trifonov", ReceptionDay = WeekDay.Monday, CreatedOn = DateTime.UtcNow
                },
                new Manager {
                    Id = Guid.NewGuid().ToString(), FirstName = "Lambi", LastName = "Kostov", ReceptionDay = WeekDay.Monday, CreatedOn = DateTime.UtcNow
                },
                new Manager {
                    Id = Guid.NewGuid().ToString(), FirstName = "Simeon", LastName = "Atanasov", ReceptionDay = WeekDay.Monday, CreatedOn = DateTime.UtcNow
                }
            };

            context.Managers.AddRange(managers);
            await context.SaveChangesAsync(cancellationToken);
        }
        public async Task <Unit> Handle(CreateTemplateEntityCommand request, CancellationToken cancellationToken)
        {
            if (_context.TemplateEntities.Any(t => t.Name == request.Name))
            {
                throw new BadRequestException("Duplicate name provided");
            }

            _context.TemplateEntities.Add(new TemplateEntity()
            {
                Name = request.Name
            });

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
        private async Task SeedTemplateEntitiesAsync(CancellationToken cancellationToken)
        {
            var templateEntities = new[]
            {
                new TemplateEntity {
                    Name = "test1"
                },
                new TemplateEntity {
                    Name = "test2"
                },
                new TemplateEntity {
                    Name = "test3"
                }
            };

            await _context.TemplateEntities.AddRangeAsync(templateEntities, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);
        }
        public async Task <Response <int> > Handle(CreateValueCommand request, CancellationToken cancellationToken)
        {
            var entity = new Value(request.ValueNumber);

            _context.Values.Add(entity);

            var success = await _context.SaveChangesAsync(cancellationToken) > 0;

            if (success.IsNotTrue())
            {
                throw new Exception("Problem saving changes");
            }

            //Publish
            //wait for all to finish
            //await _mediator.Publish(new NotificationMessage("*****@*****.**", "*****@*****.**", "Body here","Subject"));

            //Fire and forget (Only use it if you 101% you sure is what you want)
            //_ = Task.Run(() => _mediator.Publish(new NotificationMessage("*****@*****.**", "*****@*****.**", "Body here", "Subject")));
            return(new Response <int>(entity.ValueId));
        }