public ActionResult ListCodeType(string startswith, string listtype, bool exactlookup = false, int maxrows = 0) { PageTitle = "List Code Type"; var model = new ListCodeTypeViewModel(); model.Overview = new Infrastructure.ViewModels.ContentViewModel().AddTitle("List Code Type").AddParagraph("List all code table types. If an optional start type is entered, the list will start with this table type."); // TODO: POST - REDIRECT - GET if (!string.IsNullOrEmpty(startswith) && listtype != null) { model.StartFromTableType = startswith; model.ListType = listtype; model.MaxRows = maxrows; model.ExactLookup = exactlookup; var metadata = model.ToListCodeTypePageMetadata(); model.Results = GetListCodeType(metadata); if (model.Results == null || (model.Results != null && !model.Results.Any())) { AddInformationMessage("No results returned."); } } return(View(model)); }
public void ListCodeType_Post() { // Arrange var controller = SystemUnderTest(); var viewModel = new ListCodeTypeViewModel() { }; var codeModel = new CodeTypeModel { CodeType = "ABCD", ShortDescription = "Short Description", LongDescription = "LongDescription" }; IList <CodeTypeModel> models = new List <CodeTypeModel>() { codeModel }; controller.ModelState.AddModelError("", "SomeError"); // Act var result = controller.ListCodeType(viewModel) as ViewResult; // Assert Assert.IsNotNull(result, "View Result must not be null."); }
public void ListCodeType_PostRedirectedToGet() { // Arrange var controller = SystemUnderTest(); var viewModel = new ListCodeTypeViewModel() { StartFromTableType = "A", ListType = "A", MaxRows = 1, ExactLookup = true }; var codeModel = new CodeTypeModel { CodeType = "ABCD", ShortDescription = "Short Description", LongDescription = "LongDescription" }; IList <CodeTypeModel> models = new List <CodeTypeModel>() { codeModel }; mockAdwAdminService.Setup(m => m.GetListCodeTypes(It.IsAny <string>(), It.IsAny <char>(), It.IsAny <bool>(), It.IsAny <int>())).Returns(models); // Act var result = controller.ListCodeType(viewModel) as RedirectToRouteResult; // Assert Assert.IsNotNull(result, "Redirect To Route Result must not be null."); if (result != null) { Assert.AreEqual("ListCodeType", result.RouteValues["action"]); } }
public static ListCodeTypePageMetadata ToListCodeTypePageMetadata(this ListCodeTypeViewModel model) { if (model == null) { return(null); } return(new ListCodeTypePageMetadata { ExactLookup = model.ExactLookup, ListType = model.ListType, MaxRows = model.MaxRows, StartsWith = model.StartFromTableType }); }
public ActionResult ListCodeType(ListCodeTypeViewModel model) { if (ModelState.IsValid) { var route = new RouteValueDictionary(); route.Add("startswith", model.StartFromTableType); route.Add("listtype", model.ListType ?? "C"); route.Add("exactlookup", model.ExactLookup); route.Add("maxrows", model.MaxRows); //bool currentCodesOnly = false; //currentCodesOnly = !string.IsNullOrEmpty(selectedCodeType) && selectedCodeType.StartsWith("c") ? true : false; // Following Post Redirect Get pattern return(RedirectToAction("ListCodeType", route)); } return(View(model)); }