public async Task <IActionResult> Create([Bind("TermsAndConditionsSectionID,Title,Content,LastUpdate,LastUpdateUserID")] TermsAndConditionsSection termsAndConditionsSection) { var user = await _userManager.GetUserAsync(User); termsAndConditionsSection.LastUpdate = DateTime.Now; termsAndConditionsSection.LastUpdateUserID = user.Id; termsAndConditionsSection.User = user; if (ModelState.IsValid) { _context.Add(termsAndConditionsSection); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(termsAndConditionsSection)); }
public async void Create_ReturnRedirectToAction() { var size = Context.TermsAndConditionsSection.Count(); var termsAndConditionsSection = new TermsAndConditionsSection { TermsAndConditionsSectionID = 4, Title = "Tempo de permanencia dos dados", Content = "Para fins de controlo de atividade na plataforma, os dados deverão ser mantidos por...." }; Controller.ControllerContext.HttpContext = new DefaultHttpContext { User = AdministradorLog }; var result = await Controller.Create(termsAndConditionsSection); var actionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Index", actionResult.ActionName); Assert.Equal(size + 1, Context.TermsAndConditionsSection.Count()); }
public async void EditFails_ReturnNotFound(int id) { var TermsAndConditionsSectionEdited = new TermsAndConditionsSection { TermsAndConditionsSectionID = 1, Title = "Exemplo", Content = "Nao vai encontrar ...", LastUpdate = DateTime.Now, LastUpdateUserID = "1" }; Controller.ControllerContext.HttpContext = new DefaultHttpContext { User = AdministradorLog }; var result = await Controller.Edit(id, TermsAndConditionsSectionEdited); var viewResult = Assert.IsType <ViewResult>(result); Assert.Equal("/Views/Shared/NotFound.cshtml", viewResult.ViewName); }
public async Task <IActionResult> Edit(int id, [Bind("TermsAndConditionsSectionID,Title,Content,LastUpdate,LastUpdateUserID")] TermsAndConditionsSection termsAndConditionsSection) { if (id != termsAndConditionsSection.TermsAndConditionsSectionID) { return(View("/Views/Shared/NotFound.cshtml")); } var user = await _userManager.GetUserAsync(User); termsAndConditionsSection.LastUpdate = DateTime.Now; termsAndConditionsSection.LastUpdateUserID = user.Id; termsAndConditionsSection.User = user; if (ModelState.IsValid) { try { _context.Update(termsAndConditionsSection); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TermsAndConditionsSectionExists(termsAndConditionsSection.TermsAndConditionsSectionID)) { return(View("/Views/Shared/NotFound.cshtml")); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(termsAndConditionsSection)); }