Example #1
0
        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));
        }
Example #2
0
        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());
        }
Example #3
0
        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);
        }
Example #4
0
        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));
        }