示例#1
0
        public IActionResult EnergyGenerationAdjustment(string[] keys, int[] adjustments)
        {
            List <Data> data = _context.Data.ToList();

            for (int i = 0; i < data.Count; i++)
            {
                int index = Array.IndexOf(keys, data[i].Date);
                if (data[i].EnergyGenAdjustment != adjustments[index])
                {
                    data[i].EnergyGenAdjustment = adjustments[index];
                }
            }
            _context.SaveChanges();

            return(RedirectToAction("Admin"));
        }
示例#2
0
        public HomeController(ILogger <HomeController> logger, project_DContext context, IWebHostEnvironment env)
        {
            _logger  = logger;
            _context = context;
            _env     = env;

            //check if data is empty
            if (_context.Department.ToList().Count == 0 && _context.Data.ToList().Count == 0)
            {
                //add 2 departments
                _context.Department.Add(new Department {
                    Name = "Department1"
                });
                _context.Department.Add(new Department {
                    Name = "Department2"
                });
                _context.SaveChanges();
                //add 2 days of 2 years data per department
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 20.0,
                    GasConsumption    = 10.0,
                    Date                = "08/06/2020",
                    DepartmentID        = _context.Department.ToList()[1].DepartmentID,
                    EnergyGenerated     = 0.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 25.0,
                    GasConsumption    = 15.0,
                    Date                = "09/06/2020",
                    DepartmentID        = _context.Department.ToList()[1].DepartmentID,
                    EnergyGenerated     = 15.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 10.0,
                    GasConsumption    = 15.0,
                    Date                = "08/06/2020",
                    DepartmentID        = _context.Department.ToList()[0].DepartmentID,
                    EnergyGenerated     = 10.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 30.0,
                    GasConsumption    = 30.0,
                    Date                = "09/06/2020",
                    DepartmentID        = _context.Department.ToList()[0].DepartmentID,
                    EnergyGenerated     = 5.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 30.0,
                    GasConsumption    = 20.0,
                    Date                = "08/06/2021",
                    DepartmentID        = _context.Department.ToList()[1].DepartmentID,
                    EnergyGenerated     = 5.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 35.0,
                    GasConsumption    = 25.0,
                    Date                = "09/06/2021",
                    DepartmentID        = _context.Department.ToList()[1].DepartmentID,
                    EnergyGenerated     = 20.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 20.0,
                    GasConsumption    = 10.0,
                    Date                = "08/06/2021",
                    DepartmentID        = _context.Department.ToList()[0].DepartmentID,
                    EnergyGenerated     = 15.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.Data.Add(
                    new Data
                {
                    EnergyConsumption = 25.0,
                    GasConsumption    = 15.0,
                    Date                = "09/06/2021",
                    DepartmentID        = _context.Department.ToList()[0].DepartmentID,
                    EnergyGenerated     = 10.0,
                    GasAdjustment       = 0.0,
                    EnergyAdjustment    = 0.0,
                    EnergyGenAdjustment = 0.0
                });
                _context.SaveChanges();
            }
            if (_context.User.ToList().Count == 0)
            {
                //add 2 users (1 admin)
                _context.User.Add(new User {
                    UserName = "******", PassWord = "******", Email = "*****@*****.**", IsAdmin = 1
                });
                _context.User.Add(new User {
                    UserName = "******", PassWord = "", Email = "*****@*****.**", IsAdmin = 0
                });
                _context.SaveChanges();
            }
        }