Beispiel #1
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,EmployeeId,Skill,SkillId,YearsExperience")] EmployeeSkillVM employeeSkillVM)
        {
            if (ModelState.IsValid)
            {
                //Map the modelView to Model
                EmployeeSkill employeeSkill = employeeSkillVM;
                db.Entry(employeeSkill).State = EntityState.Modified;

                //Call the EF to save chages
                await db.SaveChangesAsync();

                return(RedirectToAction("Edit", "Employee", new { Id = employeeSkill.EmployeeId }));
            }
            return(View(employeeSkillVM));
        }
Beispiel #2
0
        // GET: EmployeeSkill/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Retrieve Employee information for user comfirmation before delete
            EmployeeSkillVM employeeSkillVM = await db.EmployeeSkills.Include("Skill").FirstOrDefaultAsync(x => x.Id == id);

            if (employeeSkillVM == null)
            {
                return(HttpNotFound());
            }

            return(View(employeeSkillVM));
        }
Beispiel #3
0
        public async Task <ActionResult> Create([Bind(Include = "EmployeeId,SkillId,YearsExperience")] EmployeeSkillVM employeeSkillVM)
        {
            if (ModelState.IsValid)
            {
                //Map to Model
                EmployeeSkill employeeSkill = employeeSkillVM;
                employeeSkill.Skill = await db.Skills.FindAsync(employeeSkillVM.SkillId);

                employeeSkill.Employee = await db.Employees.FindAsync(employeeSkillVM.EmployeeId);

                //Call the EF to save chages
                db.EmployeeSkills.Add(employeeSkill);
                await db.SaveChangesAsync();

                return(RedirectToAction("Edit", "Employee", new { Id = employeeSkill.EmployeeId }));
            }

            return(View(employeeSkillVM));
        }
Beispiel #4
0
        // GET: EmployeeSkill/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Retrieve the Employee information and Map to ModeView
            EmployeeSkillVM employeeSkillVM = await db.EmployeeSkills.Include("Skill").FirstOrDefaultAsync(x => x.Id == id);

            //Retrieve all skill on database not assigned to Employee
            var skills = (from s in db.Skills
                          .Except(from es in db.EmployeeSkills
                                  where es.EmployeeId == employeeSkillVM.EmployeeId && es.Id != id
                                  select es.Skill)
                          select new SelectListItem {
                Value = s.Id.ToString(), Text = s.Name
            });

            //Attach to modelView
            employeeSkillVM.Skills = skills;

            return(View(employeeSkillVM));
        }
Beispiel #5
0
        // GET: EmployeeSkill/Create
        public async Task <ActionResult> Create(int id)
        {
            if (await db.Employees.FindAsync(id) == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //Retrieve the Employee information and Map to ModeView
            EmployeeSkillVM employeeSkillVM = new EmployeeSkillVM();

            employeeSkillVM.EmployeeId = id;

            //Retrieve all skill on database not assigned to Employee
            var skills = (from s in db.Skills
                          .Except(from es in db.EmployeeSkills where es.EmployeeId == id select es.Skill)
                          select new SelectListItem {
                Value = s.Id.ToString(), Text = s.Name
            });

            //Attach to modelView
            employeeSkillVM.Skills = skills;

            return(View(employeeSkillVM));
        }