public async Task <IActionResult> Edit(int id, [Bind("id,Menu,Med_Hjem_Køkken,Dato,Uge,UgeNavn,MenuStatus")] MadMenu madMenu) { if (id != madMenu.Menuid) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(madMenu); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MadMenuExists(madMenu.Menuid)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(madMenu)); }
public void CreatePost_SaveThroughRepository_WhenModelStateIsValid() { // Arrange var mockRepo = new Mock <IMadmenuRepository>(); var mockMenuRepo = new Mock <IMadbestillingRepository>(); mockRepo.Setup(repo => repo.Save(It.IsAny <MadMenu>())) //.Returns(Task.CompletedTask) .Verifiable(); var controller = new MadMenuController(mockMenuRepo.Object, mockRepo.Object); MadMenu s = new MadMenu() { MenuId = 1, Menu = "Rødkålssalat med appelsin, valnød og salatost" }; // Act var result = controller.Create(s); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); mockRepo.Verify(); }
public IActionResult Details(int id) { MadMenu madMenu = madmenuRepository.Get(id); MadmenuBestillingVM vm = ViewModelCreator.createMadmenuBestillingVM(madmenuRepository); vm.MadMenu = madMenu; return(View(vm)); }
public IActionResult Edit(MadMenu m) { if (ModelState.IsValid) { madmenuRepository.Save(m); // Save it to the database return(RedirectToAction("Index")); } return(View()); }
public IActionResult Create([Bind("MenuId,Menu,Med_Hjem_Køkken,Dato,Uge,UgeNavn,MenuStatus")] MadMenu madMenu) { if (ModelState.IsValid) { madmenuRepository.Save(madMenu); return(RedirectToAction(nameof(Index))); //Runs the action named Index in this controller } return(View(madMenu)); }
public async Task <IActionResult> Create([Bind("id,Menu,Med_Hjem_Køkken,Dato,Uge,UgeNavn,MenuStatus")] MadMenu madMenu) { if (ModelState.IsValid) { _context.Add(madMenu); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(madMenu)); }
public void CreatePost_ReturnsViewWithSpecies_WhenModelStateIsInvalid() //madmenu { // Arrange var mockRepo = new Mock <IMadmenuRepository>(); var mockMenuRepo = new Mock <IMadbestillingRepository>(); var controller = new MadMenuController(mockMenuRepo.Object, mockRepo.Object); controller.ModelState.AddModelError("Name", "Required"); var madmenu = new MadMenu() { MenuId = 1, Menu = "Råmarineret laks med beder og rygeost" }; // Act var result = controller.Create(madmenu); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <MadMenu>(viewResult.ViewData.Model); Assert.IsType <MadMenu>(model); }