public List <UnpaidRental> GetUnpaid() { List <UnpaidRental> unpaidRentals = new List <UnpaidRental>(); Microsoft.EntityFrameworkCore.DbSet <Rental> rentals = context.Rentals; foreach (Rental rental in rentals.ToList()) { if (rental.TotalAmount > 0 && rental.RentalEnd != null && rental.Paid == false) { Customer customerFromDb = context.Customers.ToList().Find(c => c.CustomerId == rental.CustomerId); if (customerFromDb == null) { throw new CustomerNotExistingException(); } UnpaidRental ur = new UnpaidRental { CustomerId = customerFromDb.CustomerId, Firstname = customerFromDb.Firstname, Lastname = customerFromDb.Lastname, RentalId = rental.RentalId, RentalBegin = rental.RentalBegin, RentalEnd = rental.RentalEnd }; unpaidRentals.Add(ur); } } return(unpaidRentals); }
public static Page <T> GetPage <T>(this Microsoft.EntityFrameworkCore.DbSet <T> list, int page_index, int page_size, Func <T, object> order_by_selector) where T : class { //the given index and size are used to select the correct data //note the OrderBy which is necessary to ensure the selection in the //correct order var res = list.OrderBy(order_by_selector) .Skip(page_index * page_size) .Take(page_size) .ToArray(); //in case the query fails or the page size is zero a NotFOund is returned if (res == null || res.Length == 0) { return(null); } //we calculate once the total amonut of items of the unput list var tot_items = list.Count(); //we calculate the total amount of pages. incase the page size is greater than //the total amount of items we set the total pages to 1 var tot_pages = tot_items / page_size; if (tot_items < page_size) { tot_pages = 1; } //we group all the date and return then to the caller return(new Page <T>() { Index = page_index, Items = res, TotalPages = tot_pages }); }
/// <summary> /// Permet de purger les tables pour la fixtures /// </summary> /// <typeparam name="T">Model de classe</typeparam> /// <param name="table">Collection d'objets entités</param> public static void removeTable <T>(this Microsoft.EntityFrameworkCore.DbSet <T> table) where T : class { foreach (var item in table) { table.Remove(item); } }
public virtual void DeleteRange(IEnumerable <object> ids) { Microsoft.EntityFrameworkCore.DbSet <TEntity> dbSet = this.Context.Set <TEntity>(); foreach (object id in ids) { TEntity entity = dbSet.Find(id); dbSet.Remove(entity); } }
public virtual TEntity Delete(TEntity entity) { Microsoft.EntityFrameworkCore.DbSet <TEntity> dbSet = this.Context.Set <TEntity>(); if (this.Context.Entry <TEntity>(entity).State == EntityState.Detached) { dbSet.Attach(entity); } dbSet.Remove(entity); return(entity); }
public void SaveProdutos(List <Livro> livros) { foreach (var livro in livros) { Microsoft.EntityFrameworkCore.DbSet <Produto> dbSets = contexto.Set <Produto>(); if (!dbSets.Where(p => p.Codigo == livro.Codigo).Any()) { dbSet.Add(new Produto(livro.Codigo, livro.Nome, livro.Preco)); } } contexto.SaveChanges(); }
public virtual void DeleteRange(IEnumerable <TEntity> entities) { Microsoft.EntityFrameworkCore.DbSet <TEntity> dbSet = this.Context.Set <TEntity>(); foreach (TEntity entity in entities) { if (this.Context.Entry <TEntity>(entity).State == EntityState.Detached) { dbSet.Attach(entity); } dbSet.Remove(entity); } }
public static Page <T> GetPages <T>(this Microsoft.EntityFrameworkCore.DbSet <T> list, int index_page, int page_size, Func <T, object> order_by_selector) where T : class { var result = list.OrderBy(order_by_selector) //index = 1; page_size = 3 , skip pages = 3*1 =3 .Skip(index_page * page_size) .Take(page_size) .ToArray(); var total_items = list.Count(); var total_pages = total_items / page_size; return(new Page <T> { index = index_page, Items = result, TotalPages = total_pages }); }
public static Page <T> GetPages <T>(this Microsoft.EntityFrameworkCore.DbSet <T> list, int index_page, int page_size, Func <T, object> order_by_selector, params string[] relationsToInclude) where T : class { var result = list.IncludeMultiple(relationsToInclude).OrderBy(order_by_selector) .Skip(index_page * page_size) .Take(page_size) .ToArray(); var tot_items = list.Count(); var tot_pages = tot_items / page_size; return(new Page <T> { Index = index_page, Items = result, TotalPages = tot_pages }); }
/// <summary> /// Update item /// </summary> /// <param name="item">Item</param> /// <returns>True/False</returns> public bool Update(T item) { try { using (var db = new DBEntities.DBEntities()) { Microsoft.EntityFrameworkCore.DbSet <T> dbSet = db.Set <T>(); db.Entry(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified; db.SaveChanges(); return(true); } } catch { throw; } }
public static Page <T> GetPages <T>(this Microsoft.EntityFrameworkCore.DbSet <T> list, int index_page, int page_size, Func <T, object> order_by_selector, params string[] relationsToInclude) where T : class { var result = list.IncludeMultiple(relationsToInclude).OrderBy(order_by_selector) .Skip(index_page * page_size) .Take(page_size) .ToArray(); int tot_items = list.Count(); int tot_pages = (int)(Math.Ceiling((double)tot_items / (double)page_size)); // If there are no Items, there will still be 1 page if (tot_items < page_size) { tot_pages = 1; } return(new Page <T> { Index = index_page, Items = result, TotalPages = tot_pages }); }
public RepositoryGeneric(Data.ApplicationDbContext context) { Context = context; DbSet = Context.Set <T>(); }
public GenericRepository(EmployeeDBContext context) { this.context = context; this.dbSet = context.Set <TEntity>(); }
public EFCustumRepository(EFDBContext context) { this.context = context; _dbSet = context.Set <T>(); }
public GenericService(Data.ApplicationDbContext context) { Context = context ?? throw new System.ArgumentNullException($"Argument {nameof(context)} is null"); DbSet = Context.Set <TEntity>(); }
public GenericRepository(Context context) { Context = context; DbSet = Context.Set <TEntity>(); }
public ElanatService(ApplicationDbContext context) { _context = context; _entity = _context.Set <Elanat>(); }
public VMGenericRepository(HTVMDEVDB01Context context) { _context = context; _dbSet = context.Set <TEntity>(); }
public PostgresRepository(NOGContext context) { Db = context; DbSet = Db.Set <TEntity>(); }
public CompanyRepository(Microsoft.EntityFrameworkCore.DbContext dbContext) { _context = dbContext; _companies = _context.Set <Company>(); }
public BaseCRData(ApplicationDbContext context) { _context = context; entities = _context.Set <T>(); }
public GenericRepository(ApplicationDbContext context) { Context = context; DbSet = Context.Set <TEntity>(); }
public CouponsRepository(Microsoft.EntityFrameworkCore.DbContext dbContext) { _context = dbContext; _coupons = _context.Set <Coupon>(); }
public Repository(Microsoft.EntityFrameworkCore.DbContext dataContext) { DbSet = dataContext.Set <T>(); }
public BaseDataService(ApplicationDbContext context) { _context = context; entities = context.Set <T>(); }