public Student AddStudent(Student student)
 {
     _dbContext.Set <Student>().Add(student);
     _dbContext.SaveChanges();
     this.whenStudentCreated.OnNext(student);
     return(student);
 }
        public void Run(IServiceProvider serviceProvider)
        {
            //configure console logging
            DbContext = serviceProvider.GetService <SchoolDbContext>();

            FiscalYears = DbContext.Set <FiscalYearEntity>().ToArray();
            Districts   = DbContext.Set <DistrictEntity>().ToArray();
            Budgets     = DbContext.Set <BudgetEntity>().ToArray();

            var fileRecords = ReadRecordsFromFile();

            CreateOrUpdateEntities(fileRecords);

            Console.WriteLine("Enter 'y' to continue...");
            if (Console.ReadLine().StartsWith("y"))
            {
                Console.WriteLine("Proceeding...");
                DbContext.SaveChanges();
            }
        }
Exemple #3
0
        public async Task <SchoolDbContext> GetMockContextAsync(IEnumerable <T> entities)
        {
            var options = new DbContextOptionsBuilder <SchoolDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var context = new SchoolDbContext(options);

            await context.Set <T>().AddRangeAsync(entities);

            context.SaveChanges();

            return(context);
        }
        public IActionResult Index()
        {
            var v = _schoolDbContext.Database.EnsureCreated();

            if (v)
            {
                _schoolDbContext.CreateDatabasescri();
            }
            _schoolDbContext.Set <Course>().Add(new Course()
            {
                Coursename = "MCA"
            });
            _schoolDbContext.SaveChanges();
            //_schoolDbContext.BaseEntities
            //DbInitilizer.Initialize(_schoolDbContext);
            //ViewBag.aa = _Student.Getsomestring();
            //ViewBag.bb = _course.courses();
            //var STU=_schoolDbContext.RegStudents.ToList();
            return(View());
        }
Exemple #5
0
        private DistrictEntity ChooseDistrict(SchoolDbContext dbContext)
        {
            var districts = dbContext.Set <DistrictEntity>().ToArray();

            while (true)
            {
                Console.WriteLine("Choose District");
                for (var index = 0; index < districts.Length; index++)
                {
                    Console.WriteLine($"{index} {districts[index].Name}");
                }
                var choice = Console.ReadLine();
                if (int.TryParse(choice, out var indexChosen) && indexChosen < districts.Length)
                {
                    var chosenDistrict = districts[indexChosen];
                    Console.Write($"Enter 'Y' to confirm district '{chosenDistrict.Name}': ");
                    if (Console.ReadLine().Equals("y", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(districts[indexChosen]);
                    }
                }
            }
        }
 public DbOperation(SchoolDbContext context)
 {
     _db   = context;
     DbSet = context.Set <TEntity>();
 }
 private Dictionary <int, BudgetEntity> GetBudgetByFiscalYearMapping(SchoolDbContext dbContext, DistrictEntity district)
 {
     return(dbContext.Set <BudgetEntity>()
            .Where(x => x.DistrictId == district.DistrictId)
            .ToDictionary(x => x.FiscalYearId, x => x));
 }
 public Task <List <SchoolClass> > GetSchoolClasses()
 {
     try
     {
         return(SchoolDbContext.Set <SchoolClass>().ToListAsync());
     }
     catch (Exception ex)
     {
         throw new Exception($"Couldn't retrieve classes: {ex.Message}");
     }
 }
 public Repository(SchoolDbContext context)
 {
     _context = context;
     _dbSet   = _context.Set <T>();
 }
Exemple #10
0
 public Repository(SchoolDbContext _context)
 {
     this._context = _context;
     table         = _context.Set <T>();
 }
 public async virtual Task <IEnumerable <T> > AllAsync()
 {
     return(await dbContext.Set <T>().ToListAsync());
 }
 public TotalEnrollmentEntity[] GetAll()
 {
     All = All ?? DbContext.Set <TotalEnrollmentEntity>().ToArray();
     return(All.ToArray());
 }
Exemple #13
0
 public MembersRepo(SchoolDbContext context)
 {
     _context = context;
     _dbset   = _context.Set <Member>();
 }
 public void Add(Department department)
 {
     _schoolDb.Set <Department>().Add(department);
     _schoolDb.SaveChanges();
 }
 public async Task DeleteAsync(TEntity entity)
 {
     _db.Set <TEntity>().Remove(entity);
     //await _db.SaveChanges();
 }
        private void ConvertToTotalEnrollmentEntity(BudgetPropertiesFileRecord fileRecord, FiscalYearEntity fiscalYear)
        {
            var district = Districts.SingleOrDefault(x => x.Name.Equals(fileRecord.District, StringComparison.InvariantCultureIgnoreCase));

            //skip record if we can't find district
            if (district == null)
            {
                Console.WriteLine($"Skipping Record... Unable to find district '{fileRecord.District}'");
                return;
            }

            var budget    = Budgets.SingleOrDefault(x => x.DistrictId == district.DistrictId && x.FiscalYearId == fiscalYear.FiscalYearId);
            var newBudget = false;

            if (budget == null)
            {
                newBudget = true;
                budget    = new BudgetEntity {
                    DistrictId = district.DistrictId, FiscalYearId = fiscalYear.FiscalYearId
                };
            }
            //get property value using reflection
            var columnName   = fiscalYear.Name.Replace("-", "");
            var rawValueText = (string)fileRecord.GetType().GetProperty(columnName).GetMethod.Invoke(fileRecord, null);

            if (string.IsNullOrWhiteSpace(rawValueText))
            {
                return;
            }

            if (fileRecord.Attribute.Contains("Assessed", StringComparison.InvariantCultureIgnoreCase))
            {
                if (long.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var assessed))
                {
                    budget.Assessed = assessed;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Homestead", StringComparison.InvariantCultureIgnoreCase))
            {
                if (int.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var homestead))
                {
                    budget.Homestead = homestead;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Tax Levy", StringComparison.InvariantCultureIgnoreCase))
            {
                if (int.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var taxLeavy))
                {
                    budget.TaxLevy = taxLeavy;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Collection", StringComparison.InvariantCultureIgnoreCase))
            {
                if (decimal.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var collectionRate))
                {
                    budget.CollectionRate = collectionRate;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }
            else if (fileRecord.Attribute.Contains("Millage", StringComparison.InvariantCultureIgnoreCase))
            {
                if (decimal.TryParse(rawValueText, NumberStyles.Any, CultureInfo.CurrentCulture, out var millage))
                {
                    budget.Millage = millage;
                }
                else
                {
                    Console.WriteLine($"Skipping Record... Unable to parse '{fileRecord.Attribute}' value '{rawValueText}'");
                }
            }

            if (newBudget)
            {
                Console.WriteLine("Adding New Budget");
                DbContext.Set <BudgetEntity>().Add(budget);
            }
        }
 public void AddCourse(Courses courses)
 {
     _schoolDb.Set <Courses>().Add(courses);
     _schoolDb.SaveChanges();
 }
Exemple #18
0
        public IQueryable <TEntity> Get()
        {
            var query = Db.Set <TEntity>().AsQueryable();

            return(query);
        }
Exemple #19
0
        public DistrictEntity[] GetAll()
        {
            All = All ?? DbContext.Set <DistrictEntity>().ToArray();

            return(All);
        }