public TuskDbContext( IWebHostEnvironment env, IGetClaimsProvider userData) { _env = env; _userId = userData?.UserId; }
public async Task <Payload <Book> > AddBookByIsbnAsync( AddBookByIsbnInput input, [Service] IGetClaimsProvider claimsProvider, [Service] IBookApiService apiService, [ScopedService] BookRefDbContext context) { if (context.Books.Any(e => e.Identifier == input.Isbn)) { return(new Payload <Book>(BuildSingleError(new BookException($"Book with isbn '{input.Isbn}' already in database.")))); } var apiResult = apiService.FindBook(input.Isbn); if (apiResult.IsNone) { return(new Payload <Book>(BuildSingleError(new BookException($"{input.Isbn} not found in service")))); } apiResult = new BookService().MatchAuthors(context.Authors.ToList(), apiResult); var book = apiResult.IfNone(new Book("", "", "")); var validationResult = new BookValidator().Validate(book); if (!validationResult.IsValid) { return(new Payload <Book>(BuildErrorList(validationResult.Errors))); } context.Books.Add(book); await context.SaveChangesAsync(); return(new Payload <Book>(book)); }
public _AppDbContext(DbContextOptions <_AppDbContext> options , IGetClaimsProvider userData) : base(options) { _companyId = parseInt(userData.CompanyId).Match(c => c, () => 0); _userId = userData.UserId; }
public async Task <Payload <BookRecommedation> > UpdateNoteAsync( UpdateNoteInput input, [ScopedService] BookRefDbContext context, [Service] IGetClaimsProvider claimsProvider) { var library = context.Libraries.First(e => e.Id == claimsProvider.LibraryId); var recommedation = library.UpdateRecommendationNote(input.noteId, input.content); await context.SaveChangesAsync(); return(new Payload <BookRecommedation>(recommedation)); }
public async Task <Payload <bool> > RemoveAsync( RemoveFromLibraryInput input, [ScopedService] BookRefDbContext context, [Service] IGetClaimsProvider claimsProvider) { var library = context.Libraries.First(e => e.Id == claimsProvider.LibraryId); var pl = library.RemoveBook(input.PersonalBookId); await context.SaveChangesAsync(); return(new Payload <bool>(true)); }
public async Task <Payload <PersonalBook> > ChangeColorCodeAsync( ChangeColorCodeInput input, [ScopedService] BookRefDbContext context, [Service] IGetClaimsProvider claimsProvider) { var library = context.Libraries.First(e => e.Id == claimsProvider.LibraryId); var pb = library.ChangeColorCode(input.PersonalBookId, input.ColorCode); await context.SaveChangesAsync(); return(new Payload <PersonalBook>(pb)); }
public async Task <IQueryable <PersonalBook> > GetBooksAsync( PersonalBookByIdDataLoader dataLoader, [Service] IGetClaimsProvider claimsProvider, [ScopedService] BookRefDbContext context, CancellationToken cancellationToken) { var ids = context.Libraries .Include(e => e.MyBooks) .First(e => e.Id == claimsProvider.LibraryId) .MyBooks.Select(e => e.Id); return((await dataLoader.LoadAsync(ids.ToArray(), cancellationToken)).AsQueryable()); }
public async Task <MyRecommendations> GetRecommendationsForBook( [ID(nameof(Book))] long id, BookByIdDataLoader dataLoader, [Service] IGetClaimsProvider claimsProvider, [ScopedService] BookRefDbContext context, CancellationToken cancellationToken) { var library = context.Libraries .First(e => e.Id == claimsProvider.LibraryId); var result = new MyRecommendations(); var source = await dataLoader.LoadAsync(id, cancellationToken); result.SourceBook = source; result.BookRecommedations = library.BookRecommedations.Where(e => e.SourceBookId == source.Id).ToList(); result.PersonRecommedations = library.PersonRecommedations.Where(e => e.SourceBookId == source.Id).ToList(); return(result); }
public async Task <Payload <PersonalBook> > MoveBookInLibraryAsync( MoveBookToLibraryInput input, [ScopedService] BookRefDbContext context, [Service] IGetClaimsProvider claimsProvider) { var library = context.Libraries.First(e => e.Id == claimsProvider.LibraryId); var book = context.Books.Find(input.BookId); try { library.AddNewBook(book, input.Status, input.ColorCode); } catch (LibraryException ex) { return(new Payload <PersonalBook>(BuildSingleError(ex))); } await context.SaveChangesAsync(); return(new Payload <PersonalBook>(library.MyBooks.Last())); }
public async Task <Payload <Book> > AddBookAsync( AddBookInput input, [Service] IGetClaimsProvider claimsProvider, [ScopedService] BookRefDbContext context) { var book = new Book(input.Identifier, input.Title, claimsProvider.Username) { Subtitle = input.Subtitle }; var validationResult = new BookValidator().Validate(book); if (!validationResult.IsValid) { return(new Payload <Book>(BuildErrorList(validationResult.Errors))); } context.Books.Add(book); await context.SaveChangesAsync(); return(new Payload <Book>(book)); }
public async Task <Payload <PersonRecommedation> > AddPersonRecommendationAsync( AddPersonRecommendationInput input, [ScopedService] BookRefDbContext context, [Service] IGetClaimsProvider claimsProvider) { var library = context.Libraries.First(e => e.Id == claimsProvider.LibraryId); var source = context.Books.First(e => e.Id == input.SourceBookId); var target = context.Authors.First(e => e.Id == input.TargetPersonId); try { library.AddPersonRecommendation(source, target, input.Note != null ? input.Note : ""); } catch (LibraryException ex) { return(new Payload <PersonRecommedation>(BuildSingleError(ex))); } await context.SaveChangesAsync(); return(new Payload <PersonRecommedation>(library.PersonRecommedations.Last())); }
public ExpenseManagerDbContext(DbContextOptions <ExpenseManagerDbContext> options, IGetClaimsProvider claimsProvider) : base(options) { _claimsProvider = claimsProvider; }
public CompanyCrudHandler(CompanyRepository companyRepository , CountryRepository countryRepository , AuthUserCrudHandler authUserCrud , IGetClaimsProvider userData , UserManager <User> userManager) => (_companyRepository
public CVideoContext(DbContextOptions options, IGetClaimsProvider userData) : base(options) { _userId = userData.UserId; }
public CompanyDbContext(DbContextOptions <CompanyDbContext> options, IGetClaimsProvider claimsProvider) : base(options) { DataKey = claimsProvider.DataKey; }
public MultiTenantDbContext(DbContextOptions <MultiTenantDbContext> options, IGetClaimsProvider userData) : base(options) { ShopKey = userData.ShopKey; DistrictManagerId = userData.DistrictManagerId; }
public PersonalDbContext(DbContextOptions <PersonalDbContext> options, IGetClaimsProvider userData) : base(options) { _userId = userData.UserId; }