Пример #1
0
        public async Task <IActionResult> Index(string SectorName, string SourceName, string Year, string Value)
        {
            CreationConfirmation confirmation = new CreationConfirmation();

            confirmation.Heading       = "New Record Successfully Created";
            confirmation.WasSuccessful = true;

            try
            {
                Sector                  sector       = _context.Sector.Where(s => s.SectorName == SectorName).First();
                EnergySource            energySource = _context.EnergySource.Where(e => e.SourceName == SourceName).First();
                AnnualEnergyConsumption newRecord    = new AnnualEnergyConsumption();
                newRecord.sector       = sector;
                newRecord.energysource = energySource;
                newRecord.Year         = Convert.ToInt32(Year);
                newRecord.Value        = Convert.ToDecimal(Value);
                _context.AnnualEnergyConsumption.Add(newRecord);
                await _context.SaveChangesAsync();

                AnnualEnergyConsumption confirmRecord = _context.AnnualEnergyConsumption.Where(c => c.sector.SectorName == SectorName & c.energysource.SourceName == SourceName & c.Year == Convert.ToInt32(Year) & c.Value == Convert.ToDecimal(Value)).First();
                confirmation.ConsumptionData = confirmRecord;
            }
            catch (Exception e)
            {
                confirmation.Heading       = "Record Creation Failed";
                confirmation.WasSuccessful = false;
            }

            return(View(confirmation));
        }
Пример #2
0
        public async Task <IActionResult> Index(string sector, string source, int year, Decimal?value, string?valueStr)
        {
            AnnualEnergyConsumption modRecord = _context.AnnualEnergyConsumption
                                                .Where(t => t.sector.SectorName == sector & t.energysource.SourceName == source & t.Year == year)
                                                .First();

            if (modRecord.Value == value)
            {
                UpdateRecord updRecord = new UpdateRecord();
                updRecord.Sector    = sector;
                updRecord.Source    = source;
                updRecord.Year      = year;
                updRecord.Value     = (Decimal)value;
                updRecord.origValue = value;
                return(View(updRecord));
            }
            else
            {
                modRecord.Value = Convert.ToDecimal(valueStr);
                _context.AnnualEnergyConsumption.Update(modRecord);
                await _context.SaveChangesAsync();

                UpdateRecord updRecord = new UpdateRecord();
                updRecord.Sector = sector;
                updRecord.Source = source;
                updRecord.Year   = year;
                updRecord.Value  = _context.AnnualEnergyConsumption
                                   .Where(t => t.sector.SectorName == sector & t.energysource.SourceName == source & t.Year == year)
                                   .Select(v => v.Value)
                                   .First();
                updRecord.origValue = value;
                return(View(updRecord));
            }
        }
Пример #3
0
        public async Task <IActionResult> Index(string county, string population, int?value, string?valueStr)
        {
            Demographic modRecord = dbContext.Demographics
                                    .Where(d => d.county.CountyName == county & d.population.PopTypeName == population)
                                    .First();

            if (modRecord.Value == value)
            {
                UpdateRecord updRecord = new UpdateRecord();
                updRecord.County     = county;
                updRecord.Population = population;
                updRecord.Value      = (int)value;
                updRecord.origValue  = value;
                return(View(updRecord));
            }
            else
            {
                modRecord.Value = Convert.ToInt32(valueStr);
                dbContext.Demographics.Update(modRecord);
                await dbContext.SaveChangesAsync();

                UpdateRecord updRecord = new UpdateRecord();
                updRecord.County     = county;
                updRecord.Population = population;
                updRecord.Value      = dbContext.Demographics
                                       .Where(d => d.county.CountyName == county & d.population.PopTypeName == population)
                                       .Select(v => v.Value)
                                       .First();
                updRecord.origValue = value;
                return(View(updRecord));
            }
        }
Пример #4
0
        public async Task <IActionResult> DelConfirm(string sector, string source, int year, Decimal value, string confirmation)
        {
            AnnualEnergyConsumption DelRecord = _context.AnnualEnergyConsumption
                                                .Where(t => t.sector.SectorName == sector & t.energysource.SourceName == source & t.Year == year)
                                                .First();

            if (confirmation == "Yes")
            {
                _context.AnnualEnergyConsumption.Remove(DelRecord);
                await _context.SaveChangesAsync();

                return(View(DelRecord));
            }
            else
            {
                return(View());
            }
        }
Пример #5
0
        public async Task <IActionResult> DelConfirm(string county, string population, int value, string confirmation)
        {
            Demographic DelRecord = dbContext.Demographics
                                    .Where(d => d.county.CountyName == county & d.population.PopTypeName == population)
                                    .First();

            if (confirmation == "Yes")
            {
                dbContext.Demographics.Remove(DelRecord);
                await dbContext.SaveChangesAsync();

                return(View(DelRecord));
            }
            else
            {
                return(View());
            }
        }