示例#1
0
 public TuskDbContext(
     IWebHostEnvironment env,
     IGetClaimsProvider userData)
 {
     _env    = env;
     _userId = userData?.UserId;
 }
示例#2
0
        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));
        }
示例#3
0
 public _AppDbContext(DbContextOptions <_AppDbContext> options
                      , IGetClaimsProvider userData)
     : base(options)
 {
     _companyId = parseInt(userData.CompanyId).Match(c => c, () => 0);
     _userId    = userData.UserId;
 }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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));
        }
示例#7
0
        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());
        }
示例#8
0
        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);
        }
示例#9
0
        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()));
        }
示例#10
0
        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));
        }
示例#11
0
        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()));
        }
示例#12
0
 public ExpenseManagerDbContext(DbContextOptions <ExpenseManagerDbContext> options, IGetClaimsProvider claimsProvider) : base(options)
 {
     _claimsProvider = claimsProvider;
 }
示例#13
0
 public CompanyCrudHandler(CompanyRepository companyRepository
                           , CountryRepository countryRepository
                           , AuthUserCrudHandler authUserCrud
                           , IGetClaimsProvider userData
                           , UserManager <User> userManager)
 => (_companyRepository
示例#14
0
 public CVideoContext(DbContextOptions options, IGetClaimsProvider userData) : base(options)
 {
     _userId = userData.UserId;
 }
 public CompanyDbContext(DbContextOptions <CompanyDbContext> options, IGetClaimsProvider claimsProvider)
     : base(options)
 {
     DataKey = claimsProvider.DataKey;
 }
示例#16
0
 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;
 }