示例#1
0
        public async Task <IActionResult> Edit(string id, [Bind("AwsInstanceID,Region,InstanceState")] AwsInstance awsInstance)
        {
            if (id != awsInstance.AwsInstanceID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(awsInstance);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AwsInstanceExists(awsInstance.AwsInstanceID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(awsInstance));
        }
示例#2
0
        public static void Initialize(AwsContext context)
        {
            context.Database.EnsureCreated();

            // Look for any data.
            if (context.AwsInstances.Any())
            {
                return;   // DB has been seeded
            }

            // Set initial data to AwsInstance
            var awsinstances = new AwsInstance[]
            {
                new AwsInstance {
                    AwsInstanceID = "000000", Region = "nowhere", InstanceState = "unknown", Environment = "Uknown", Name = "Unknown"
                },
                //new AwsInstance{ AwsInstanceID = "111111", Region = "nowhere", InstanceState = "unknown" }
            };

            // Add initial data to Database
            foreach (AwsInstance aws in awsinstances)
            {
                context.AwsInstances.Add(aws);
            }
            context.SaveChanges();
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("AwsInstanceID,Region,InstanceState")] AwsInstance awsInstance)
        {
            if (ModelState.IsValid)
            {
                _context.Add(awsInstance);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(awsInstance));
        }
示例#4
0
        public AwsInstanceViewModel(AwsInstance awsInstance)
        {
            awsInstance = awsInstance ?? throw new ArgumentNullException(nameof(awsInstance));

            Id          = awsInstance.Id;
            IpAddress   = awsInstance.IpAddress;
            ReportLines = awsInstance.ReportLines.Where(x => x.Parent == null)
                          .Select(x => new ReportLineViewModel(x))
                          .Where(x => !x.IsEmptyRoot)
                          .OrderBy(x => x.Name)
                          .ToArray();
        }