Ejemplo n.º 1
0
        public ActionResult Header()
        {
            var userRepository          = new UserRepository(_context);
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                var viewModel = new HeaderViewModel
                {
                    User           = UserViewModel.FromEntity(userRepository.GetByLogin(HttpContext.User.Identity.Name)),
                    KnowledgeAreas = KnowledgeAreaViewModel
                                     .FromEntityList(knowledgeAreaRepository.ListActiveKnowledgeAreas(), 2).ToList()
                };

                return(PartialView($"_{viewModel.User.RoleName}Header", viewModel));
            }
            else
            {
                var viewModel = new HeaderViewModel
                {
                    KnowledgeAreas = KnowledgeAreaViewModel
                                     .FromEntityList(knowledgeAreaRepository.ListActiveKnowledgeAreas(), 2).ToList()
                };
                return(PartialView("_Login", viewModel));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Guid id, SubjectViewModel viewModel)
        {
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);
            var subjectRepository       = new SubjectRepository(_context);


            if (ModelState.IsValid)
            {
                try
                {
                    var knowledgeArea = knowledgeAreaRepository.GetById(id);
                    subjectRepository.Update(SubjectViewModel.ToEntity(viewModel, knowledgeArea));
                    _context.Save(_loggedUser);

                    TempData["MessageType"]  = "success";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = "Subject updated";
                    return(Redirect(TempData["BackURL"].ToString()));
                }
                catch (Exception ex)
                {
                    TempData["MessageType"]  = "error";
                    TempData["MessageTitle"] = Resource.ContentManagementToastrTitle;
                    TempData["Message"]      = ex.Message;
                }
            }

            var knowledgeAreas = knowledgeAreaRepository.ListActiveKnowledgeAreas();

            ViewBag.KnowledgeAreas = new SelectList(knowledgeAreas, "Id", "Name");
            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public ActionResult Create()
        {
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);
            var knowledgeAreas          = knowledgeAreaRepository.ListActiveKnowledgeAreas();

            ViewBag.KnowledgeAreas = new SelectList(knowledgeAreas, "Id", "Name");
            return(View());
        }
Ejemplo n.º 4
0
        public ActionResult Index()
        {
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);
            var viewModel =
                KnowledgeAreaViewModel.FromEntityList(knowledgeAreaRepository.ListActiveKnowledgeAreas(), 2);


            return(View(viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(Guid id)
        {
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);

            var knowledgeAreas = knowledgeAreaRepository.ListActiveKnowledgeAreas();

            ViewBag.KnowledgeAreas = new SelectList(knowledgeAreas, "Id", "Name");

            var subjectRepository = new SubjectRepository(_context);
            var subject           = subjectRepository.GetById(id);

            return(View(SubjectViewModel.FromEntity(subject, 0)));
        }
Ejemplo n.º 6
0
        public ActionResult Index(Guid id)
        {
            var knowledgeAreaRepository = new KnowledgeAreaRepository(_context);
            var activeKnowledgeAreas    = knowledgeAreaRepository.ListActiveKnowledgeAreas();
            var selectedKnowledgeArea   = activeKnowledgeAreas.Single(x => x.Id == id);

            if (selectedKnowledgeArea == null)
            {
                TempData["MessageType"]  = "warning";
                TempData["MessageTitle"] = "Warning";
                TempData["Message"]      = "This knowledge area is not available at this moment";
                return(RedirectToAction("Index", "Home"));
            }

            var viewModel = KnowledgeAreaViewModel.FromEntity(selectedKnowledgeArea, 2);

            ViewBag.OtherKnowledgeAreas =
                new SelectList(activeKnowledgeAreas.Except(new List <KnowledgeArea> {
                selectedKnowledgeArea
            }), "Id",
                               "Name");
            return(View(viewModel));
        }