Exemplo n.º 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));
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 3
0
        public IActionResult Index(string sector, string source, int year, Decimal value)
        {
            AnnualEnergyConsumption DelRecord = _context.AnnualEnergyConsumption
                                                .Where(t => t.sector.SectorName == sector & t.energysource.SourceName == source & t.Year == year)
                                                .First();

            DeleteRecord DelRecord1 = new DeleteRecord();

            DelRecord1.Sector = sector;
            DelRecord1.Source = source;
            DelRecord1.Year   = year;
            DelRecord1.Value  = value;
            return(View(DelRecord1));
        }
Exemplo n.º 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());
            }
        }