示例#1
0
 public Employee CreateEmployee(Employee employee)
 {
     using (var database = new Core.Entity.SeedsEntities())
     {
         var entity = employee.ToEntity(database);
         entity.ID = database.Employee.Execute(MergeOption.NoTracking).Any() ? database.Employee.Execute(MergeOption.NoTracking).Max(e => e.ID) + 1 : 0;
         long subjectID = employee.Subject.ID;
         entity.SubjectID = subjectID;
         database.AddToEmployee(entity);
         database.SaveChanges();
         employee = new Employee(database.Employee.Execute(MergeOption.NoTracking).First(e => e.ID == entity.ID));
         employee.Subject = Cache.Instance.Subjects[subjectID];
         employee.Subject.Employees[employee.ID] = employee;
         return employee;
     }
 }