Ejemplo n.º 1
0
        public IActionResult Student(BOStudentViewModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                TempData["Got-Error"]     = "true";
                TempData["Login-Message"] = "É necessário iniciar sessão";

                return(RedirectToAction("Index", "Home"));
            }

            _context.Address.Add(model.Address);

            Student std = new Student
            {
                Email                     = model.Student.Email,
                Name                      = model.Student.Name,
                BirthDate                 = model.Student.BirthDate,
                Telephone                 = model.Student.Telephone,
                StudentNumber             = model.Student.StudentNumber,
                IdStudentBranchNavigation = _context.StudentBranch.Where(sb => sb.IdStudentBranch == model.Student.IdStudentBranch).FirstOrDefault(),
                IdAddressNavigation       = model.Address
            };

            _context.Student.Add(std);

            _context.SaveChanges();

            TempData["HasAlert"]     = "true";
            TempData["AlertMessage"] = "Student added successfully.";

            return(RedirectToAction("Students", "BackOffice"));
        }
Ejemplo n.º 2
0
        public IActionResult EditStudent(BOStudentViewModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                TempData["Got-Error"]     = "true";
                TempData["Login-Message"] = "É necessário iniciar sessão";

                return(RedirectToAction("Index", "Home"));
            }

            model.Student.IdAddressNavigation = model.Address;

            _context.Student.Update(model.Student);
            _context.SaveChanges();

            TempData["HasAlert"]     = "true";
            TempData["AlertMessage"] = "Student edited succesfully.";

            return(RedirectToAction("Students", "BackOffice"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the Students Main List Backoffice page
        /// </summary>
        /// <returns>Students Main List Backoffice page</returns>
        /// <remarks></remarks>
        public IActionResult Students()
        {
            if (!User.Identity.IsAuthenticated)
            {
                TempData["Got-Error"]     = "true";
                TempData["Login-Message"] = "É necessário iniciar sessão";

                return(RedirectToAction("Index", "Home"));
            }

            TempData["minDate"] = DateTime.Now.AddYears(-70).ToString("MM-dd-yyyy");
            TempData["maxDate"] = DateTime.Now.AddYears(-18).ToString("MM-dd-yyyy");

            BOStudentViewModel viewModel = new BOStudentViewModel();
            var students = _context.Student.Include(s => s.IdStudentBranchNavigation).Include(s => s.IdAddressNavigation.IdDistrictNavigation);

            viewModel.Students  = students;
            viewModel.Branches  = PopulateBranches();
            viewModel.Districts = PopulateDistricts();

            return(View(viewModel));
        }