public NowRepository(TContext context) : base(context) { _context = context; Shifts = new EntityBaseRepository <TContext, Shift>(_context); ShiftDetails = new EntityBaseRepository <TContext, ShiftDetail>(_context); Schedules = new EntityBaseRepository <TContext, Schedule>(_context); }
void AttachInsert <TEntity>(EntityBaseRepository <TEntity> repository, DbContext db) where TEntity : EntityBase { object entityList; if (!_insertValues.TryGetValue(typeof(TEntity).Name, out entityList)) { return; } repository.InsertWithIdentity(db, (List <TEntity>)entityList); }
public void TestAddVehicle() { EntityBaseRepository <Vehicle> vehiclesRepository = new EntityBaseRepository <Vehicle>(new DbFactory()); Vehicle vehicle = new Vehicle { ChassisId = "aaa123", Color = "Blue", Type = VehicleType.Car }; vehiclesRepository.Add(vehicle); Assert.IsTrue(vehiclesRepository.FindBy(v => v.ChassisId == "aaa123").Any()); }
public BackgroundProcessingService(IConfigurationRoot configuration) { var dbContextOptionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>(); dbContextOptionsBuilder.UseNpgsql(configuration["Data:PostgresqlConnectionString"]); context = new ApplicationDbContext(dbContextOptionsBuilder.Options); portfolioRepository = new EntityBaseRepository <Portfolio>(context); securityPriceRepository = new SecurityPriceRepository(context); securityRepository = new EntityBaseRepository <Security>(context); holdingRepository = new EntityBaseRepository <Holding>(context); //parcelRepository = new EntityBaseRepository<Parcel>(context); //holdingTransactionRepository = new EntityBaseRepository<HoldingTransaction>(context); //yahooClient = new YahooFinanceClient(configuration["Yahoo:Cookie"], configuration["Yahoo:Crumb"]); avClient = new AlphaVantageClient(configuration["AlphaVantage:ApiKey"]); }
public void TestDeleteVehicle() { EntityBaseRepository <Vehicle> vehiclesRepository = new EntityBaseRepository <Vehicle>(new DbFactory()); Vehicle vehicle = new Vehicle { ChassisId = "bbb123", Color = "Blue", Type = VehicleType.Car }; vehiclesRepository.Add(vehicle); Vehicle vei = vehiclesRepository.FindBy(v => v.ChassisId == "bbb123").SingleOrDefault(); vehiclesRepository.Delete(vei); Assert.IsTrue(!vehiclesRepository.All.Any()); }
public void TestAddManyVehicles() { EntityBaseRepository <Vehicle> vehiclesRepository = new EntityBaseRepository <Vehicle>(new DbFactory()); Vehicle vehicle = new Vehicle { ChassisId = "aaa123", Color = "Blue", Type = VehicleType.Car }; Vehicle vehicle2 = new Vehicle { ChassisId = "bbb123", Color = "red", Type = VehicleType.Truck }; vehiclesRepository.Add(vehicle); vehiclesRepository.Add(vehicle2); Assert.IsTrue(vehiclesRepository.All.Count() > 1); }
public static User GetSingleByUsername(this EntityBaseRepository <User> userRepository, string username) { return(userRepository.GetAll().FirstOrDefault(x => x.Username == username)); }
void PrintCount <TEntity>(EntityBaseRepository <TEntity> repository) where TEntity : EntityBase { Console.WriteLine($"[{typeof(TEntity).Name}] has {repository.ForceGet().ToList().Count} rows."); }
public InputProcessor() { _vehicleRepository = new EntityBaseRepository <Vehicle>(new DbFactory()); }
public static void Main(string[] args) { Startup s = new Startup(new HostingEnvironment() { ContentRootPath = AppContext.BaseDirectory }); DbContextOptionsBuilder <EmployeeContext> optionsBuilder = new DbContextOptionsBuilder <EmployeeContext>(); optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=FuckYou;Trusted_Connection=True;MultipleActiveResultSets=True"); using (var db = new EmployeeContext(optionsBuilder.Options)) { LanguageRepository <EmployeeContext> lr = new LanguageRepository <EmployeeContext>(db); // add language; if (!lr.GetAll().Any(l => l.Code == "EE")) { lr.Add(new Language { Name = "Eesti", Code = "EE" }); } Language ll = lr.GetAll().Where(l => l.Code == "EE").FirstOrDefault(); EntityBaseRepository <EducationLevel, EmployeeContext> elr = new EntityBaseRepository <EducationLevel, EmployeeContext>(db); // add language; if (!elr.GetAll().Any(l => l.Code == "ah")) { elr.Add(new EducationLevel { Name = "Algharidus", Code = "ah" }); } EducationLevel el = elr.GetAll().Where(l => l.Code == "ah").FirstOrDefault(); Education edu = new Education(); edu.SchoolName = "Uus kool"; edu.YearCompleted = 2015; edu.NameOfDegree = "uu"; edu.Level = el; Employee EE = new Employee { Name = "Siim Aus", EmployeeId = "0203" }; ContactData cd = new ContactData(); EE.ContactData = cd; cd.Education.Add(edu); cd.FirstName = "Siim"; cd.LastName = "Aus"; cd.JobTitle = "IT Director"; cd.ContactLanguage = ll; edu.ContactData = cd; edu.ContactDataId = cd.Id; db.Employees.Add(EE); db.SaveChanges(); EmployeeRepository <EmployeeContext> er = new EmployeeRepository <EmployeeContext>(db); foreach (Employee ex in er.GetAll().Where(x => x.Id >= 9)) { //Include(c => c.ContactData).ThenInclude(e => ) string json = Newtonsoft.Json.JsonConvert.SerializeObject(ex, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore //, //PreserveReferencesHandling = PreserveReferencesHandling.Objects }); Console.WriteLine("{0} {1} {2}\n{3}", ex.Id, ex.Name, ex.EmployeeId, json); } } testSerialize(); Console.WriteLine("Hello World!"); }