public virtual async Task <IActionResult> Post([FromBody] TEntity entity, CancellationToken cancellationToken) { this.OnCreating(entity); if (!this.ModelState.IsValid) { return(BadRequest(ModelState)); } try { var dbSet = this.Context.Set <TEntity>(); await dbSet.AddAsync(entity, cancellationToken); await this.Context.SaveChangesAsync(cancellationToken); return(Created(entity)); } catch (DbUpdateException ex) { if (ArchiveDbContext.IsUserError(ex, out var message)) { return(BadRequest(new ProblemDetails { Type = "archive-site:database-error/invalid-create", Title = "The requested update was not valid.", Detail = message })); } else { throw; } } }
public virtual async Task <IActionResult> Put([FromODataUri] Int64 key, [FromBody] TEntity entity, CancellationToken cancellationToken) { var dbSet = this.Context.Set <TEntity>(); var existing = await dbSet.SingleOrDefaultAsync(e => e.Id == key, cancellationToken); if (existing == null) { return(NotFound()); } this.OnUpdating(key, entity); entity.CopyTo(existing); try { await this.Context.SaveChangesAsync(cancellationToken); return(Ok(existing)); } catch (DbUpdateException ex) { if (ArchiveDbContext.IsUserError(ex, out var message)) { return(BadRequest(new ProblemDetails { Type = "archive-site:database-error/invalid-update", Title = "The requested update was not valid.", Detail = message })); } else { throw; } } }
protected async Task <IActionResult> TrySaveChanges( TEntity entity, Func <TEntity, Task <IActionResult> > onSuccess, String operation, CancellationToken cancellationToken) { try { await this.DbContext.SaveChangesAsync(cancellationToken); var result = await onSuccess(entity); if (this.transaction != null) { await this.transaction.CommitAsync(cancellationToken); } return(result); } catch (DbUpdateException ex) { if (ArchiveDbContext.IsUserError(ex, out var message)) { return(BadRequest(new ProblemDetails { Type = $"archive-site:database-error/invalid-{operation}", Title = $"The requested {operation} was not valid.", Detail = message })); } else { throw; } } }
public CognitiveServiceController(ILogger <CognitiveServiceController> logger, ArchiveDbContext archiveDbContext, CognitiveService cognitiveService) { Logger = logger; ArchiveDbContext = archiveDbContext; CognitiveService = cognitiveService; }
public EntityFrameworkEventRepository(ProductionDbContext context, ArchiveDbContext archive) : base(context) { _archive = archive; var actionLogRepository = new EntityFrameworkActionLogRepository(context, archive); _actionLogRepository = actionLogRepository; }
protected void UploadButton_OnClick(object sender, EventArgs e) { if (this.FileControl.HasFile) { var filename = Path.GetFileName(this.FileControl.FileName); if (filename != null && filename.EndsWith(".zip")) { byte[] fileData = null; if (this.FileControl.HasFile) { var length = this.FileControl.PostedFile.ContentLength; fileData = new byte[length + 1]; var fileStream = this.FileControl.PostedFile.InputStream; fileStream.Read(fileData, 0, length); } if (fileData != null) { var ds = new ArchiveDbContext(); using (var inputStream = new MemoryStream(fileData)) { using (var zip = ZipFile.Read(inputStream)) { foreach (var zipEntry in zip.Entries.Where(entry => entry.FileName.EndsWith(".txt"))) { using (var outputStream = new MemoryStream()) { zipEntry.Extract(outputStream); outputStream.Position = 0; var sr = new StreamReader(outputStream); var fileContents = sr.ReadToEnd(); var file = new File() { FileName = zipEntry.FileName, ArchiveName = filename, Content = fileContents }; ds.Files.Add(file); } } } } ds.SaveChanges(); } } else { this.Notification.Text = "Please select a valid .zip file!"; this.Notification.Visible = true; } } else { this.Notification.Text = "Please select a file!"; this.Notification.Visible = true; } }
public InitializeCommand( IOptions <ArchiveDbConfiguration> dbConfiguration, ArchiveDbContext context, ILogger <InitializeCommand> logger) { this.dbConfiguration = (dbConfiguration ?? throw new ArgumentNullException(nameof(dbConfiguration))).Value; this.context = context ?? throw new ArgumentNullException(nameof(context)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public static ArchiveDbContext GetArchiveDbContext(string db) { var options = new DbContextOptionsBuilder <ArchiveDbContext>() .UseInMemoryDatabase(databaseName: db) .Options; var context = new ArchiveDbContext(options); // Make sure we clear the database before each run context.Database.EnsureDeleted(); return(context); }
public DbLoginLogger(ArchiveDbContext dbContext) { this.dbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); }
public EntityFrameworkCommentRepository(ProductionDbContext context, ArchiveDbContext archive) : base(context) { _archive = archive; }
public DocumentImageController(ILogger <DocumentImageController> logger, ArchiveDbContext archiveDbContext) { this.logger = logger; this.archiveDbContext = archiveDbContext; }
public EntityFrameworkAdditionalInfoRepository(ProductionDbContext context, ArchiveDbContext archive) : base(context) { _archive = archive; }