public void EmployeeSkill_Update(EmployeeSkillItem item) { using (var context = new WorkScheduleContext()) { EmployeeSkill updateItem = new EmployeeSkill { //for an update, you need to supply your PK value EmployeeSkillID = item.EmployeeSkillID, EmployeeID = item.EmployeeID, SkillID = item.SkillID, Level = item.Level, YearsOfExperience = item.YearsOfService, HourlyWage = item.HourlyWage }; context.Entry(updateItem).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public EmployeeSkillItem EmployeesSkills_FindById(int employeeskillid) //this is just a single record thats why List<> and IEnumerable<> is not used { using (var context = new WorkScheduleContext()) { // (...).FirstOrDefault will return either // a) the first record matching the where condition // b) a null value EmployeeSkillItem results = (from x in context.EmployeeSkills where x.EmployeeSkillID == employeeskillid select new EmployeeSkillItem { EmployeeSkillID = x.EmployeeSkillID, Employee = x.Employee.LastName + ", " + x.Employee.FirstName, Skill = x.Skill.Description, Level = x.Level, YearsOfService = x.YearsOfExperience, HourlyWage = x.HourlyWage }).FirstOrDefault(); return(results); } }
public int EmployeeSkill_Add(EmployeeSkillItem item) // this will return PK { using (var context = new WorkScheduleContext()) { EmployeeSkill addItem = new EmployeeSkill { //why no PK set? //PK is an identity PK, no value is needed //However, if PK is NOT an identity spec(Identity Specification = No in the DB), ADD PK here!!! EmployeeID = item.EmployeeID, SkillID = item.SkillID, Level = item.Level, YearsOfExperience = item.YearsOfService, HourlyWage = item.HourlyWage }; context.EmployeeSkills.Add(addItem); context.SaveChanges(); return(addItem.EmployeeSkillID); } }
public void EmployeeSkill_Delete(EmployeeSkillItem item) { EmployeeSkill_Delete(item.EmployeeSkillID); }