private async Task RegisterPageResults(EndedEventsPage eep) { if (eep?.Results == null) { return; } foreach (var result in eep.Results) { var containsGame = await _dbContext.Games.AnyAsync(g => g.Id == result.Id); if (containsGame) { continue; } var game = await ExtractGameFromResult(result); if (game == null) { continue; } Console.WriteLine($"Adding game with Id: {game.Id}"); _dbContext.Add(game); } await _dbContext.SaveChangesAsync(); }
Response ToResponseData(ResponseBase responseBase) { MessageEntity message = new MessageEntity() { InOrOut = "O", IsActive = true, Message = JsonConvert.SerializeObject(responseBase), CreatedTime = DateTime.Now }; _context.Add(message); _context.SaveChangesAsync(); return(new Response() { Message = responseBase.Message, ErrorMessage = responseBase.ErrorMessage, IsSuccess = responseBase.IsSuccess }); }
public async Task <IActionResult> Update(Guid id, [FromBody] Tenant tenant, CancellationToken cancellationToken = default(CancellationToken)) { if (tenant == null || !tenant.Id.Equals(id)) { return(BadRequest()); } try { cancellationToken.ThrowIfCancellationRequested(); var e = await dataSource.DbContext.FindAsync <Tenant>(new object[] { id }, cancellationToken); var options = configuration.GetSection("MultitenancyOptions"); var deploymentMode = options.GetValue <DeploymentModes>("DeploymentMode"); var connectionString = configuration.GetConnectionString(options.GetValue <string>("ConnectionString")); if (deploymentMode == DeploymentModes.Multi) { tenant.IsIsolated = true; } else if (deploymentMode == DeploymentModes.Single) { tenant.ConnectionString = connectionString; } tenant.DateModified = DateTime.UtcNow; dataSource.DbContext.Entry <Tenant>(e).CurrentValues.SetValues(tenant); await dataSource.DbContext.SaveChangesAsync(cancellationToken); /* * Update tenant in isolation mode */ if (tenant.IsIsolated) { DbContext dbContext = dataSource.DbContext; switch (tenant.Engine) { case DatabaseEngine.SqlServer: dbContext = new SqlServerDbContext(configuration, tenant, new DbContextOptions <SqlServerDbContext>()); break; case DatabaseEngine.MySql: dbContext = new MySqlDbContext(configuration, tenant, new DbContextOptions <MySqlDbContext>()); break; case DatabaseEngine.PostgreSql: dbContext = new PostgreSqlDbContext(configuration, tenant, new DbContextOptions <PostgreSqlDbContext>()); break; } try { var hostedTenant = await dbContext.Set <Tenant>() .Where(ht => ht.HostName == tenant.HostName) .FirstOrDefaultAsync(); if (hostedTenant != null) { dbContext.Entry <Tenant>(hostedTenant).State = EntityState.Modified; hostedTenant.Active = tenant.Active; hostedTenant.ConnectionString = tenant.ConnectionString; hostedTenant.DateCreated = tenant.DateCreated; hostedTenant.DateModified = tenant.DateModified; hostedTenant.DateDeleted = tenant.DateDeleted; hostedTenant.Deleted = tenant.Deleted; hostedTenant.DeploymentStatus = tenant.DeploymentStatus; hostedTenant.Description = tenant.Description; hostedTenant.Name = tenant.Name; hostedTenant.HostName = tenant.HostName; hostedTenant.Edition = tenant.Edition; hostedTenant.Engine = tenant.Engine; hostedTenant.IsIsolated = tenant.IsIsolated; hostedTenant.IsTenantAdministrator = tenant.IsTenantAdministrator; hostedTenant.SubscriptionId = tenant.SubscriptionId; hostedTenant.Theme = tenant.Theme; await dbContext.SaveChangesAsync(cancellationToken); } } catch (Exception ex) { return(new AcceptedResult(nameof(Update), ex.Message + ". " + ex.InnerException?.Message)); } } HttpContext.Response.Headers.Add("ConcurrencyStamp", Convert.ToBase64String(tenant.ConcurrencyStamp)); HttpContext.Response.Headers.Add("ConcurrencyTimeStamp", tenant.ConcurrencyTimeStamp.ToString()); } catch (DbUpdateException ex) { if (ex.InnerException != null) { return(StatusCode(StatusCodes.Status500InternalServerError, new { success = false, message = ex.InnerException.Message, details = ex.InnerException })); } return(StatusCode(StatusCodes.Status500InternalServerError, new { success = false, message = ex.Message, details = ex })); } catch (Exception ex) { if (ex.InnerException != null) { return(StatusCode(StatusCodes.Status500InternalServerError, new { success = false, message = ex.InnerException.Message, details = ex.InnerException })); } return(StatusCode(StatusCodes.Status500InternalServerError, new { success = false, message = ex.Message, details = ex })); } return(new NoContentResult()); }