public async Task SeedAsync(BusinessDbContext context, IHostingEnvironment env, IOptions <BusinessSettings> settings, ILogger <BusinessDbContextSeed> logger) { var policy = CreatePolicy(logger, nameof(BusinessDbContextSeed)); await policy.ExecuteAsync(async() => { var useCustomizationData = settings.Value.UseCustomizationData; var contentRootPath = env.ContentRootPath; var picturePath = env.WebRootPath; if (!context.Sites.Any()) { await context.Sites.AddRangeAsync(GetPreconfiguredSites()); await context.SaveChangesAsync(); } if (!context.Locations.Any()) { logger.LogDebug("Seeding locations ..."); await context.Locations.AddRangeAsync(GetLocationsFromFile(contentRootPath, context, logger)); await context.SaveChangesAsync(); context.Locations.UpdateRange(GetLocationsFromFile2(contentRootPath, context, logger)); context.SaveChanges(); //GetCatalogItemPictures(contentRootPath, picturePath); } }); }
public async Task SeedAsync(BusinessDbContext context, IHostingEnvironment env, IOptions <BusinessSettings> settings, ILogger <CatalogContextSeed> logger) { var policy = CreatePolicy(logger, nameof(CatalogContextSeed)); await policy.ExecuteAsync(async() => { var useCustomizationData = settings.Value.UseCustomizationData; var contentRootPath = env.ContentRootPath; var picturePath = env.WebRootPath; if (!context.ScheduleTypes.Any()) { await context.ScheduleTypes.AddRangeAsync(GetPreconfiguredScheduleTypes()); await context.SaveChangesAsync(); } if (!context.ServiceCategories.Any()) { await context.ServiceCategories.AddRangeAsync(GetPreconfiguredServiceCategories()); await context.SaveChangesAsync(); } }); }
public async Task <IActionResult> Create([Bind("Id,Name")] Category category) { if (ModelState.IsValid) { category.Id = Guid.NewGuid(); _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("Id,Name,Email,Phone,Description,Address,Zip,CityId,Site")] Investor investor) { if (ModelState.IsValid) { investor.Id = Guid.NewGuid(); _context.Add(investor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CityId"] = new SelectList(_context.City, "Id", "PrettyName", investor.CityId); return(View(investor)); }
public async Task <IActionResult> Create([Bind("Id,Name,Address,State,Zip,Description,Site,Phone,Email,CityId,CategoryId")] Business business) { if (ModelState.IsValid) { business.Id = Guid.NewGuid(); _context.Add(business); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", business.CategoryId); ViewData["CityId"] = new SelectList(_context.City, "Id", "PrettyName", business.CityId); return(View(business)); }
public async Task SaveLoginAttempt(bool isSuccess, string userName, string error, string tenantId, string companyId, string userId) { _context.LoginAttempts.Add(new LoginAttempt() { Id = Guid.NewGuid().ToString(), Active = true, Date = DateTime.Now, Status = isSuccess ? LoginAttemptStatus.Success : LoginAttemptStatus.Failed, Username = userName, Error = error, IpAddress = HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : null, Created = DateTime.Now, CreatedBy = userId, TenantId = tenantId, CompanyId = companyId, DeviceInfo = HttpContext.Current != null ? HttpContext.Current.Request.UserAgent : null, }); await _context.SaveChangesAsync(); }
public async Task SeedAsync(BusinessDbContext context, IHostingEnvironment env, IOptions <BusinessSettings> settings, ILogger <CategoryContextSeed> logger) { var policy = CreatePolicy(logger, nameof(CategoryContextSeed)); await policy.ExecuteAsync(async() => { var useCustomizationData = settings.Value.UseCustomizationData; var contentRootPath = env.ContentRootPath; var picturePath = env.WebRootPath; if (!context.Categories.Any()) { GetCategoriesFromFile(contentRootPath, logger); await context.Categories.AddRangeAsync(useCustomizationData ? _categories : GetPreconfiguredRootCategories()); await context.Subcategories.AddRangeAsync(useCustomizationData ? _subcategories : GetPreconfiguredSubcategories()); await context.SaveChangesAsync(); } }); }
public async Task <IActionResult> AddServiceItem([FromBody] ServiceItem schedulableCatalogItem) { var item = new ServiceItem(schedulableCatalogItem.SiteId, schedulableCatalogItem.Name, schedulableCatalogItem.Description, schedulableCatalogItem.DefaultTimeLength, schedulableCatalogItem.Price, schedulableCatalogItem.ServiceCategoryId, schedulableCatalogItem.IndustryStandardCategoryName, schedulableCatalogItem.IndustryStandardSubcategoryName); _catalogContext.ServiceItems.Add(item); await _catalogContext.SaveChangesAsync(); return(CreatedAtAction(nameof(FindServiceItemById), new { id = item.Id }, null)); }
public async Task <TEntity> Add(TEntity entity) { await _context.Set <TEntity>().AddAsync(entity); await _context.SaveChangesAsync(); return(entity); }
private async Task SaveEventAndBusinessDbContextChangesAsync(IEvent evt) { //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency await ResilientTransaction.New(_context) .ExecuteAsync(async() => { // Achieving atomicity between original ordering database operation and the IntegrationEventLog thanks to a local transaction await _context.SaveChangesAsync(); await _eventLogService.SaveEventAsync(evt, _context.Database.CurrentTransaction.GetDbTransaction()); }); }
public async Task <Site> ProvisionSite(Site site) { _businessDbContext.Sites.Add(site); await _businessDbContext.SaveChangesAsync(); return(site); }
public async Task <int> SaveChanges() { return(await Context.SaveChangesAsync()); }