public void EditTeacher(FullInfoTeacher teacher)
        {
            Users    editUser     = teacher;
            Teachers editTeachers = null;

            using (ElectronicalJournalContext db = new ElectronicalJournalContext())
            {
                var teach = from tc in db.Teachers
                            where tc.UserId == editUser.UserId
                            select new Teachers
                {
                    TeacherId  = tc.TeacherId,
                    PositionId = tc.PositionId,
                    UserId     = tc.UserId
                };
                foreach (Teachers item in teach)
                {
                    editTeachers = item;
                }

                if (editTeachers == null && teacher.PositionId != null)
                {
                    Teachers tc = new Teachers();
                    tc.UserId     = teacher.UserId;
                    tc.PositionId = teacher.PositionId;
                    db.Teachers.Add(tc);
                }
                else if (editTeachers == null)
                {
                }
                else if (editTeachers.PositionId != teacher.PositionId)
                {
                    editTeachers.PositionId = teacher.PositionId;
                    db.Teachers.Update(editTeachers);
                }
                db.Users.Update(editUser);
                db.SaveChanges();
            }
        }
 public FullInfoTeacher FullInfoTeacher(int id)
 {
     using (ElectronicalJournalContext db = new ElectronicalJournalContext())
     {
         var teacher = from us in db.Users
                       join al in db.AccessLevels on us.AccessLevelId equals al.AccessLevelId
                       into alDatails
                       from alDat in alDatails.DefaultIfEmpty()
                       join tch in db.Teachers on us.UserId equals tch.UserId
                       into tchDatail
                       from tchDat in tchDatail.DefaultIfEmpty()
                       join pos in db.Positions on tchDat.PositionId equals pos.PositionId
                       into posDatail
                       from posDat in posDatail.DefaultIfEmpty()
                       where us.UserId == id
                       select new FullInfoTeacher
         {
             UserId         = us.UserId,
             FirstName      = us.FirstName,
             MiddleName     = !string.IsNullOrEmpty(us.MiddleName) ? us.MiddleName : string.Empty,
             LastName       = us.LastName,
             Login          = us.Login,
             PasswordHash   = us.PasswordHash,
             PasswordSalt   = us.PasswordSalt,
             AccessLevelId  = us.AccessLevelId,
             AcessLevelName = alDat.AccessLevelName,
             Email          = us.Email,
             Phone          = us.Phone,
             PositionId     = posDat.PositionId,
             PositionName   = posDat.PositionName
         };
         foreach (var item in teacher)
         {
             _fullInfoTeacher = item;
         }
     }
     return(_fullInfoTeacher);
 }