Beispiel #1
0
        public async Task <IActionResult> PutHost([FromRoute] string id, [FromBody] Host host)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != host.IpAddress)
            {
                return(BadRequest());
            }

            _context.Entry(host).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HostExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Postcode")] Apiary apiary)
        {
            if (ModelState.IsValid)
            {
                _context.Add(apiary);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(apiary));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("ID,Name")] Beehive beehive)
        {
            if (ModelState.IsValid)
            {
                _context.Add(beehive);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(beehive));
        }
        public async Task <IActionResult> Post([FromBody] Website data)
        {
            MonitorAPI.Data.Website Website = new Data.Website();
            var website = new Website();

            website.Link      = data.Link;
            website.Word      = data.Word;
            website.TimeStamp = DateTime.Now.ToString("dd-MM-yyyyTHH:mm:sszzz");

            if (Website.GetStatus(website.Link, website.Word))
            {
                website.Status = true;
            }
            else
            {
                website.Status = false;
            }

            using (var db = new MonitorContext())
            {
                db.Websites.Add(website);
                await db.SaveChangesAsync();
            }

            return(CreatedAtAction("GetWebsite", new { id = website.Id }, website));
        }
        public async Task <IActionResult> Put(int id, Website data)
        {
            using (var db = new MonitorContext())
            {
                var website = db.Websites.SingleOrDefault(s => s.Id == id);

                if (website == null)
                {
                    return(NotFound());
                }

                website.Word      = data.Word;
                website.TimeStamp = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");

                MonitorAPI.Data.Website tester = new Data.Website();
                if (tester.GetStatus(website.Link, website.Word))
                {
                    website.Status = true;
                }
                else
                {
                    website.Status = false;
                }

                db.Websites.Update(website);
                await db.SaveChangesAsync();

                return(Ok(website));
            }
        }
Beispiel #6
0
        public async Task <IActionResult> Post([FromBody] Service data)
        {
            MonitorAPI.Data.Service Service = new Data.Service();
            var service = new Service();

            service.Link      = data.Link;
            service.TimeStamp = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");

            if (Service.GetStatus(service.Link))
            {
                service.Status = true;
            }
            else
            {
                service.Status = false;
            }

            using (var db = new MonitorContext())
            {
                db.Services.Add(service);
                await db.SaveChangesAsync();
            }

            return(CreatedAtAction("GetService", new { id = service.Id }, service));
        }
Beispiel #7
0
        public async Task <IActionResult> Put(int id, Service data)
        {
            using (var db = new MonitorContext())
            {
                var service = db.Services.SingleOrDefault(s => s.Id == id);

                if (service == null)
                {
                    return(NotFound());
                }

                service.TimeStamp = DateTime.Now.ToString("dd-MM-yyyyTHH:mm:sszzz");
                service.Link      = data.Link;

                MonitorAPI.Data.Service tester = new Data.Service();
                if (tester.GetStatus(service.Link))
                {
                    service.Status = true;
                }
                else
                {
                    service.Status = false;
                }

                db.Services.Update(service);
                await db.SaveChangesAsync();

                return(Ok(service));
            }
        }
        public async Task <IHttpActionResult> PutTemperature(int id, TemperatureModel temperatureModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Temperature temperature = new Temperature()
            {
                TemperatureId = temperatureModel.TemperatureId, Celcius = temperatureModel.Celcius, Time = temperatureModel.Time, Location = temperatureModel.Location
            };

            if (id != temperature.TemperatureId)
            {
                return(BadRequest());
            }

            db.Entry(temperature).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TemperatureExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(temperatureModel));
        }
        public async Task <IActionResult> Delete(int id)
        {
            using (var db = new MonitorContext())
            {
                var website = db.Websites.SingleOrDefault(s => s.Id == id);

                if (website == null || id <= 0)
                {
                    return(NotFound());
                }

                db.Websites.Remove(website);
                await db.SaveChangesAsync();

                return(Ok(website));
            }
        }
Beispiel #10
0
        public Task <int> SaveAsync(CancellationToken ct = default)
        {
            var task = _monitorContext.SaveChangesAsync(ct);

            return(task);
        }