Beispiel #1
0
        public ActionResult EditResponse(string id, int code)
        {
            var mock = mockRepository.FindById(id);

            if (mock == null)
            {
                return MockNotFound(id);
            }

            var response = mock.Responses.FirstOrDefault(x => (int) x.StatusCode == code);

            if (response == null)
            {
                return ResponseNotFound(id, (HttpStatusCode) code);
            }

            var viewModel = new MockResponseViewModel(mock, response);

            return View(viewModel);
        }
Beispiel #2
0
        public ActionResult NewResponse(string id)
        {
            var mock = mockRepository.FindById(id);

            if (mock == null)
            {
                return MockNotFound(id);
            }

            var viewModel = new MockResponseViewModel(mock, new MockResponse());

            return View(viewModel);
        }
Beispiel #3
0
        public ActionResult NewResponse(string id, MockResponseViewModel model)
        {
            var mock = mockRepository.FindById(id);

            if (mock == null)
            {
                return MockNotFound(id);
            }

            model.Mock = mock;

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            if (mock.Responses.Any(x => x.StatusCode == model.MockResponse.StatusCode))
            {
                ModelState.AddModelError("", $"A response already exists with the status code {model.MockResponse.StatusCode.ToFriendlyString()}");
                return View(model);
            }

            mock.Responses.Add(model.MockResponse);

            if (mock.Responses.Count == 1)
            {
                mock.ActiveStatusCode = model.MockResponse.StatusCode;
            }

            mockRepository.Update(id, mock);

            return RedirectToAction("Edit", new {id});
        }
Beispiel #4
0
        public ActionResult EditResponse(string id, int code, MockResponseViewModel model)
        {
            var mock = mockRepository.FindById(id);

            if (mock == null)
            {
                return MockNotFound(id);
            }

            var response = mock.Responses.FirstOrDefault(x => (int)x.StatusCode == code);

            if (response == null)
            {
                return ResponseNotFound(id, (HttpStatusCode)code);
            }

            model.Mock = mock;

            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var index = mock.Responses.FindIndex(x => (int) x.StatusCode == code);
            mock.Responses[index] = model.MockResponse;

            mockRepository.Update(id, mock);

            return RedirectToAction("Edit", new {id});
        }