private List<double> CalculateAvgRaitingValuation(int id, TeacherSubject teach)
        {
            var avgValuationList = new List<double>();

            for (int index = 0; index < 19; index++)
                avgValuationList.Add(0);

            var listId = db.Votings.Where(x => x.TeacherSubjectId == id).ToList();
            var teachId = db.TeacherSubject.Where(x => x.TeacherId == teach.TeacherId);

            var listS = new List<int>();
            foreach (var s in teachId)
            {
                listS.Add(s.Id);
            }

            int count = 0;

            var listIdRaiting = db.RaitingTeacherSubject.Where(x => x.TeacherSubject.TeacherId == teach.TeacherId && x.AvgRating != 0).ToList();
            foreach (var voit in listIdRaiting)
            {
                avgValuationList[0] += voit.ActivityInClass;
                avgValuationList[1] += voit.AvailabilityTeacherOutsideLessons;
                avgValuationList[2] += voit.ClarityAndAccessibility;
                avgValuationList[3] += voit.CommentsTheWork;
                avgValuationList[4] += voit.DepthPossessionOf;
                avgValuationList[5] += voit.HowWellTheProcedurePerformedGrading;
                avgValuationList[6] += voit.InterestInTheSubject;
                avgValuationList[7] += voit.NumberOfAttendance;
                avgValuationList[8] += voit.OverallSubject;
                avgValuationList[9] += voit.PreparationTime;
                avgValuationList[10] += voit.ProcedureGrading;
                avgValuationList[11] += voit.QualityMasteringTheSubject;
                avgValuationList[12] += voit.QualityTeachingMaterials;
                avgValuationList[13] += voit.RelevantToStudents;
                avgValuationList[14] += voit.SomethingNew;
                avgValuationList[15] += voit.TheDifficultyOfTheCourse;
                avgValuationList[16] += voit.ThePracticalValue;
                avgValuationList[17] += voit.RelevantToStudents;
                avgValuationList[18] += voit.CountVoting;
                count++;
            }

            for (int index = 0; index < avgValuationList.Count - 1; index++)
                avgValuationList[index] /= count;

            return avgValuationList;
        }
        public ActionResult Edit([Bind(Include = "TeacherId,Name,SurName,LastName,PathToPhoto,Description,CathedraId")] Teacher teacher, int [] selectedSubjects)
        {
            if (ModelState.IsValid)
            {
                Teacher newteacher = db.Teachers.Find(teacher.TeacherId);
                newteacher.Name = teacher.Name;
                newteacher.SurName = teacher.SurName;
                newteacher.LastName = teacher.LastName;
                newteacher.PathToPhoto = teacher.PathToPhoto;
                newteacher.Description = teacher.Description;

                if (selectedSubjects != null)
                {
                    var lastTeacherSubjects = db.TeacherSubject.Where(m => m.TeacherId == newteacher.TeacherId).ToList();
                    foreach (var c in db.Subjects.Where(co => selectedSubjects.Contains(co.Id)))
                    {
                        //Додає нові предмети
                        if (lastTeacherSubjects.FirstOrDefault(m => m.SubjectId == c.Id) == null)
                        {
                            var teachersubject = new TeacherSubject
                            {
                                TeacherId = teacher.TeacherId,
                                SubjectId = c.Id
                            };

                            db.TeacherSubject.Add(teachersubject);
                        }

                        else
                        {
                            foreach (var lsbj in lastTeacherSubjects)
                            {

                                if (lsbj.SubjectId == c.Id)
                                {
                                    lastTeacherSubjects.Remove(lsbj);
                                    break;
                                }

                            }

                        }

                    }
                    //Видаляє зняті прапорці
                    foreach(var lsbj in lastTeacherSubjects)
                    {
                        TeacherSubject teachersubjectDel = db.TeacherSubject.Include(c => c.RaitingTeacherSubject).First(m => m.SubjectId == lsbj.SubjectId && m.TeacherId == teacher.TeacherId);
                        db.TeacherSubject.Remove(teachersubjectDel);
                    }

                }
                db.Entry(newteacher).State = EntityState.Modified;
                db.SaveChanges();
                var TeacherSubjectId = db.TeacherSubject.Where(x => x.TeacherId == teacher.TeacherId);
                foreach (var lest in TeacherSubjectId.ToList())
                {
                    var raitingSubject = new RaitingTeacherSubject
                    {
                        ActivityInClass = 0,
                        AvailabilityTeacherOutsideLessons = 0,
                        ClarityAndAccessibility = 0,
                        CommentsTheWork = 0,
                        DepthPossessionOf = 0,
                        HowWellTheProcedurePerformedGrading = 0,
                        InterestInTheSubject = 0,
                        NumberOfAttendance = 0,
                        OverallSubject = 0,
                        PreparationTime = 0,
                        ProcedureGrading = 0,
                        QualityMasteringTheSubject = 0,
                        QualityTeachingMaterials = 0,
                        RelevantToStudents = 0,
                        SomethingNew = 0,
                        TheDifficultyOfTheCourse = 0,
                        ThePracticalValue = 0,
                        AvgRating = 0,
                        ForTheEntirePeriod = 0,
                        PreviousMonth = 0,
                        TeacherSubjectId = lest.Id
                    };
                    db.RaitingTeacherSubject.Add(raitingSubject);
                    db.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            ViewBag.CathedraId = new SelectList(db.Cathedras, "Id", "NameCathedra", teacher.CathedraId);
            return View(teacher);
        }