public async Task CreateRequestForCommandAsync <T>(Guid id) { var exists = await ExistAsync(id); var request = exists ? throw new ImsDomainException($"Request with {id} already exists") : new ClientRequest() { Id = id, Name = typeof(T).Name, Time = DateTime.UtcNow }; _context.Add(request); await _context.SaveChangesAsync(); }
public async Task SeedAsync(ImsContext context, IOptions <ApplicationSettings> settings, ILogger <ImsContextSeed> logger) { _logger = logger; var contentRootPath = Directory.GetCurrentDirectory(); var policy = CreatePolicy(logger, nameof(ImsContextSeed)); await policy.ExecuteAsync(async() => { var useCustomizationData = settings.Value.UseCustomizationData; using (context) { context.Database.Migrate(); foreach (var storeType in Enumeration.GetAll <StoreType>()) { if (!context.StoreTypes.Any(x => x.EnumId == storeType.EnumId)) { await context.StoreTypes.AddAsync(storeType); await context.SaveChangesAsync(); } } foreach (var accountType in Enumeration.GetAll <AccountType>()) { if (!context.AccountTypes.Any(x => x.EnumId == accountType.EnumId)) { await context.AccountTypes.AddAsync(accountType); await context.SaveChangesAsync(); } } foreach (var directionType in Enumeration.GetAll <DirectionType>()) { if (!context.DirectionTypes.Any(x => x.EnumId == directionType.EnumId)) { await context.DirectionTypes.AddAsync(directionType); await context.SaveChangesAsync(); } } foreach (var investmentToolType in Enumeration.GetAll <InvestmentToolType>()) { if (!context.InvestmentToolTypes.Any(x => x.EnumId == investmentToolType.EnumId)) { await context.InvestmentToolTypes.AddAsync(investmentToolType); await context.SaveChangesAsync(); } } foreach (var transactionType in Enumeration.GetAll <TransactionType>()) { if (!context.TransactionTypes.Any(x => x.EnumId == transactionType.EnumId)) { await context.TransactionTypes.AddAsync(transactionType); await context.SaveChangesAsync(); } } //ImportCurrencies(context); //ImportCountries(context); //ImportStocks(context); //ImportGolds(context); //ImportEmtias(context); } }); }
public async Task SaveAsync() { await _context.SaveChangesAsync(); }