public static EntityResult Failed(params EntityError[] errors) { var result = new EntityResult { Succeeded = false }; if (errors != null) { result._errors.AddRange(errors); } return(result); }
public async Task <EntityResult> SaveFileMetadataAsync(FileMetadata metadata, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (metadata == null) { throw new ArgumentNullException(nameof(metadata)); } DbContext.Add(metadata); try { await DbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure())); } return(EntityResult.Success); }
public async Task <EntityResult> CreateAsync(Application app, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (app == null) { throw new ArgumentNullException(nameof(app)); } Context.Add(app); try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure())); } return(EntityResult.Success); }
public async Task <EntityResult> AddEventAsync(long appId, Event evt, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (evt == null) { throw new ArgumentNullException(nameof(evt)); } evt.ApplicationId = appId; Context.Add(evt); try { await Context.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException) { return(EntityResult.Failed(ErrorDescriber.ConcurrencyFailure())); } return(EntityResult.Success); }