Пример #1
0
        public async Task <IActionResult> Edit(int id, HttpEndpointViewModel vm)
        {
            if (id != vm.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var endpoint    = vm.ToEndpoint();
                    var oldEndpoint = _context.Endpoints.AsNoTracking().First(e => e.Id == endpoint.Id);
                    _context.Update(endpoint);
                    await _context.SaveChangesAsync();

                    NotifyEditEvent(oldEndpoint, endpoint);
                    _stateService.RemoveStatus(endpoint.Id);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EndpointExists(vm.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(List)));
            }
            return(View(nameof(Edit), vm));
        }
Пример #2
0
        public void ShouldConvertHttpViewModelToEndpoint()
        {
            var vm1 = new HttpEndpointViewModel {
                Id = 5, Enabled = true, Kind = Endpoint.EndpointKind.Http, Name = "fdsa", Location = "asdf", ResponseMatch = "qwerty", StatusCodes = " 201, 500", IgnoreCerts = true, CustomCert = "zxcvbnm"
            };
            var ep1 = vm1.ToEndpoint();

            Assert.AreEqual(5, ep1.Id);
            Assert.IsTrue(ep1.Enabled);
            Assert.AreEqual(Endpoint.EndpointKind.Http, ep1.Kind);
            Assert.AreEqual("fdsa", ep1.Name);
            Assert.AreEqual("asdf", ep1.GetHttpLocation());
            Assert.AreEqual("qwerty", ep1.GetHttpResponseMatch());
            CollectionAssert.AreEquivalent(new List <int> {
                201, 500
            }, ep1.GetHttpStatusCodes());
            Assert.IsTrue(ep1.GetHttpIgnoreTlsCerts());
            Assert.AreEqual("zxcvbnm", ep1.GetHttpCustomTlsCert());
            Assert.IsTrue(DateTimeOffset.UtcNow.AddMinutes(-1) < ep1.LastUpdated);

            var vm2 = new HttpEndpointViewModel {
                Kind = Endpoint.EndpointKind.Http
            };
            var ep2 = vm2.ToEndpoint();

            Assert.AreEqual(Endpoint.EndpointKind.Http, ep2.Kind);
            Assert.IsTrue(DateTimeOffset.UtcNow.AddMinutes(-1) < ep2.LastUpdated);
        }
Пример #3
0
        public async Task <IActionResult> Create(HttpEndpointViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var endpoint = vm.ToEndpoint();
                endpoint.Id = 0;
                _context.Add(endpoint);
                await _context.SaveChangesAsync();

                NotifyEvent(endpoint, NotificationType.EndpointAdded);
                return(RedirectToAction(nameof(List)));
            }
            return(View(nameof(Create), vm));
        }