Ejemplo n.º 1
0
        public ActionResult Create(SkillModel skill)
        {
            if (ModelState.IsValid)
            {
                var newSkill = new Skill
                {
                    Name = skill.Name,
                    Desc = skill.Desc,
                    Min  = skill.Min,
                    Max  = skill.Max
                };
                // related skills
                foreach (var id in skill.SelectedSkillIds)
                {
                    var relSkill = db.Skills.Single(x => x.Id == id);
                    newSkill.AddSkillRelation(relSkill);
                }
                // related Labors
                foreach (var id in skill.SelectedLaborIds)
                {
                    var relLab = db.Products.Single(x => x.Id == id);
                    newSkill.ValidLabors.Add(relLab);
                    relLab.Skills.Add(newSkill);
                }
                // do not connect to jobs here. Jobs should decide who they relate to.

                db.Skills.Add(newSkill);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(skill));
        }