Exemplo n.º 1
0
        public IActionResult CompetencesManage(long id, CompetenceUpdateModel competenceUpdateModel)
        {
            var competence = _context.Set <CompetencesModel>().Find(id);

            switch (competenceUpdateModel.Action)
            {
            case CompetenceActions.AddContent:
                competence.Content.Add(competenceUpdateModel.Content);
                break;

            case CompetenceActions.RemoveCompetence:
                _context.Set <CompetencesModel>().Remove(competence);
                _context.SaveChanges();
                return(RedirectToAction("Competences"));

            case CompetenceActions.RemoveContent:
                List <string> newContent = new List <string>();
                for (int i = 0; i < competence.Content.Count; i++)
                {
                    if (!competenceUpdateModel.Checkboxes.Contains(i))
                    {
                        newContent.Add(competence.Content[i]);
                    }
                }
                competence.Content = newContent;
                break;
            }

            competenceUpdateModel.Competence = competence;
            _context.SaveChanges();
            return(View(competenceUpdateModel));
        }
Exemplo n.º 2
0
        public IActionResult CompetencesManage(long id)
        {
            var competence            = _context.Set <CompetencesModel>().Find(id);
            var competenceUpdateModel = new CompetenceUpdateModel {
                Competence = competence
            };

            return(View(competenceUpdateModel));
        }