public Work addEmployee(int idEmployee, int idWork) { WorkEmployee workEmployee = new WorkEmployee(); workEmployee.IdEmployee = idEmployee; workEmployee.IdWork = idWork; todoListDBContext.WorkEmployee.Add(workEmployee); todoListDBContext.SaveChanges(); var result = todoListDBContext.Work.Find(idWork); var workList = todoListDBContext.WorkList.Find(result.IdWorkList); var workListEmployeeExist = from wle in todoListDBContext.WorkListEmployee where wle.IdWorkList == result.IdWorkList && wle.IdEmployee == idEmployee select wle; if (workListEmployeeExist.Count() > 0) { return(result); } WorkListEmployee workListEmployee = new WorkListEmployee(); workListEmployee.IdWorkList = workList.Id; workListEmployee.IdEmployee = idEmployee; todoListDBContext.WorkListEmployee.Add(workListEmployee); todoListDBContext.SaveChanges(); return(result); }
public WorkList addEmployee(int idWorkList, int idEmployee) { WorkListEmployee workListEmployee = new WorkListEmployee(); workListEmployee.IdWorkList = idWorkList; workListEmployee.IdEmployee = idEmployee; var result = todoListDBContext.WorkListEmployee.Add(workListEmployee); todoListDBContext.SaveChanges(); return(todoListDBContext.WorkList.Find(idWorkList)); }
public WorkList save(WorkList workList, int idEmployee) { if (workList.Id == 0) { var result = todoListDBContext.WorkList.Add(workList); todoListDBContext.SaveChanges(); WorkListEmployee workListEmployee = new WorkListEmployee(); workListEmployee.IdEmployee = idEmployee; workListEmployee.IdWorkList = result.Entity.Id; todoListDBContext.WorkListEmployee.Add(workListEmployee); todoListDBContext.SaveChanges(); return(result.Entity); } else { WorkList findResult = todoListDBContext.WorkList.Find(workList.Id); findResult.WorkListName = workList.WorkListName; findResult.IdWorkListStatus = workList.IdWorkListStatus; todoListDBContext.SaveChanges(); return(todoListDBContext.WorkList.Find(workList.Id)); } }