Пример #1
0
 public IActionResult AddNewTeacher(CTeacher newTeacher, int userId)
 {
     if (DbActions.ValidateRequest(Request))
     {
         DbActions.AddNewTeacher(newTeacher, userId);
         return(StatusCode(200));
     }
     return(StatusCode(401));
 }
Пример #2
0
 public IActionResult UpdateTeacher(CTeacher teacherToUpdate, int userId)
 {
     if (DbActions.ValidateRequest(Request))
     {
         DbActions.UpdateExistingTeacher(teacherToUpdate, userId);
         return(StatusCode(200));
     }
     return(StatusCode(401));
 }
Пример #3
0
        public void Task_246_1()         //Добавление в пустую таблицу
        {
            //arrange
            MTeacher tcher    = new MTeacher("Садовская Ольга Борисовна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            bool     expected = true;
            //act
            CTeacher T      = new CTeacher();
            bool     actual = T.Insert(tcher);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public void Task_248_2()         //Удаление не существующей строки
        {
            //arrange
            MTeacher tcher    = new MTeacher("Садовская Ольга Борисовна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            bool     expected = false;
            CTeacher T        = new CTeacher();
            //act
            bool actual = T.Delete(tcher);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        public void Task_246_7()         //Все атрибуты повторяются
        {
            //arrange
            MTeacher tcher1   = new MTeacher("Киприна Людмила Юрьевна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            MTeacher tcher    = new MTeacher("Киприна Людмила Юрьевна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            bool     expected = false;
            //act
            CTeacher T      = new CTeacher();
            bool     f      = T.Insert(tcher1);
            bool     actual = T.Insert(tcher);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void Task_246_4_or_6()         //Повторяющиеся атрибуты все кроме ФИО
        {
            //arrange
            MTeacher tcher1   = new MTeacher("Садовская Ольга Борисовна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            MTeacher tcher    = new MTeacher("Киприна Людмила Юрьевна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            bool     expected = true;
            //act
            CTeacher T      = new CTeacher();
            bool     f      = T.Insert(tcher1);
            bool     actual = T.Insert(tcher);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void Task_246_3()         //Повторяющийся атрибут "ФИО"
        {
            //arrange
            MTeacher tcher1   = new MTeacher("Киприна Людмила Юрьевна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            MTeacher tcher    = new MTeacher("Киприна Людмила Юрьевна", "Доктор наук", "ИАСТ", "Пт, Ср", "Пн, Вт", "Суббота");
            bool     expected = false;
            //act
            CTeacher T      = new CTeacher();
            bool     f      = T.Insert(tcher1);
            bool     actual = T.Insert(tcher);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void Task_246_2()         //Полностью отличные атрибуты
        {
            //arrange
            MTeacher tcher1   = new MTeacher("Садовская Ольга Борисовна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            MTeacher tcher    = new MTeacher("Киприна Людмила Юрьевна", "Доктор наук", "ИАСТ", "Пт, Ср", "Пн, Вт", "Суббота");
            bool     expected = true;
            //act
            CTeacher T      = new CTeacher();
            bool     f      = T.Insert(tcher1);
            bool     actual = T.Insert(tcher);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        public static CTeacher GetTeacher(int teacherId, int userId)
        {
            var teacher = new CTeacher();

            teacher.ClassesTaught = new List <CClassTerm>();
            try
            {
                using (var db = new RecContext())
                {
                    int recIdForAdmin = GetRecIdForUser(userId, db);
                    var dbTeacher     = db.Teacher.Where(t => t.TeacherId == teacherId).FirstOrDefault();
                    teacher.TeacherId    = dbTeacher.TeacherId;
                    teacher.FirstName    = dbTeacher.FirstName;
                    teacher.LastName     = dbTeacher.LastName;
                    teacher.EmailAddress = dbTeacher.Email;
                    var disableDate = db.RecTeacher.Where(rt => rt.TeacherId == teacher.TeacherId).Select(rt => rt.DisableDate).FirstOrDefault();
                    if (disableDate == null)
                    {
                        teacher.IsDisabled = false;
                    }
                    else
                    {
                        teacher.IsDisabled = true;
                    }
                    teacher.IsAdministrator = db.RecTeacher.Where(rt => rt.TeacherId == teacher.TeacherId && rt.RecId == recIdForAdmin).Select(rt => rt.IsAdministrator).FirstOrDefault();

                    var classTermsForTeacher = db.ClassTermTeacher.Where(ctt => ctt.TeacherId == teacher.TeacherId && ctt.ClassTerm.Class.RecId == recIdForAdmin).Select(ctt => ctt.ClassTerm).ToArray();
                    foreach (ClassTerm classTerm in classTermsForTeacher)
                    {
                        var classInfo = db.Class.Where(c => c.ClassId == classTerm.ClassId).FirstOrDefault();
                        var termInfo  = db.Term.Where(t => t.TermId == classTerm.TermId).FirstOrDefault();
                        teacher.ClassesTaught.Add(new CClassTerm
                        {
                            ClassTermId = classTerm.ClassTermId,
                            Name        = classInfo.Name + " (" + termInfo.Name + ")",
                            Description = classInfo.Description
                        });
                    }
                }
            }

            catch (Exception e)
            {
                var sException = new ServerException(e.Message, e, true);
                LogServerException(sException);
            }
            return(teacher);
        }
Пример #10
0
        public static void UpdateExistingTeacher(CTeacher teacher, int userId)
        {
            try
            {
                using (var db = new RecContext())
                {
                    var dbTeacher = db.Teacher.Where(t => t.TeacherId == teacher.TeacherId).First();
                    db.Update(dbTeacher);
                    dbTeacher.FirstName = teacher.FirstName;
                    dbTeacher.LastName  = teacher.LastName;
                    dbTeacher.Email     = teacher.EmailAddress;
                    var recId      = GetRecIdForUser(userId, db);
                    var recTeacher = db.RecTeacher.Where(rt => rt.TeacherId == teacher.TeacherId && rt.RecId == recId).FirstOrDefault();
                    db.Update(recTeacher);
                    recTeacher.IsAdministrator = teacher.IsAdministrator;
                    if (teacher.IsDisabled)
                    {
                        recTeacher.DisableDate = DateTime.Now;
                    }

                    foreach (CClassTerm classTerm in teacher.ClassesTaught)
                    {
                        var dbClassTerm = db.ClassTermTeacher.Where(ctt => ctt.TeacherId == teacher.TeacherId && ctt.ClassTermId == classTerm.ClassTermId).FirstOrDefault();
                        if (dbClassTerm == null)
                        {
                            db.Add(new ClassTermTeacher
                            {
                                ClassTermId = classTerm.ClassTermId,
                                TeacherId   = teacher.TeacherId
                            });
                        }
                        else if (classTerm.Operation == Operation.Deleted)
                        {
                            db.Remove(dbClassTerm);
                        }
                    }
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                var sException = new ServerException(e.Message, e, false);
                LogServerException(sException);
            }
        }
Пример #11
0
 public static void AddNewTeacher(CTeacher teacher, int userId)
 {
     try
     {
         using (var db = new RecContext())
         {
             var dbTeacher = new Teacher
             {
                 FirstName = teacher.FirstName,
                 LastName  = teacher.LastName,
                 Email     = teacher.EmailAddress
             };
             db.Add(dbTeacher);
             db.SaveChanges();
             var teacherId  = db.Teacher.Where(t => t.Email == teacher.EmailAddress).Select(t => t.TeacherId).First();
             var recTeacher = new RecTeacher
             {
                 TeacherId       = teacherId,
                 RecId           = GetRecIdForUser(userId, db),
                 IsAdministrator = teacher.IsAdministrator,
             };
             if (teacher.IsDisabled)
             {
                 recTeacher.DisableDate = DateTime.Now;
             }
             db.Add(recTeacher);
             foreach (CClassTerm classTerm in teacher.ClassesTaught)
             {
                 db.Add(new ClassTermTeacher
                 {
                     ClassTermId = classTerm.ClassTermId,
                     TeacherId   = teacherId
                 });
             }
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         var sException = new ServerException(e.Message, e, false);
         LogServerException(sException);
     }
 }
        public void Task_247_1()        //изменение когда атрибуды не повторяются (ФИО и Кафедра изменить не возможно)
        {
            //arrange
            MTeacher tcher  = new MTeacher("Садовская Ольга Борисовна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            MTeacher tcher1 = new MTeacher("Киприна Людмила Юрьевна", "Доктор наук", "ИАСТ", "Пт, Ср", "Пн, Вт", "Суббота");
            CTeacher T      = new CTeacher();

            T.Insert(tcher);
            T.Insert(tcher1);
            bool expected = true;

            //act
            tcher1.Note          = "Ученый";
            tcher1.MetodicalDays = "Чт, Сб";
            tcher1.Windows       = "Сб, Пн";
            tcher1.Weekends      = "Пятница";
            bool actual = T.Update(tcher1);

            //assert
            Assert.AreEqual(expected, actual);
        }
        public void Task_247_5and7()        //изменение при условии что примечание, кафедра и график работы дублируется
        {
            //arrange
            MTeacher tcher  = new MTeacher("Садовская Ольга Борисовна", "Кандидат наук", "ФАСТ", "Пн, Вт", "Ср, Чт, Пт", "Воскресенье");
            MTeacher tcher1 = new MTeacher("Киприна Людмила Юрьевна", "Доктор наук", "ИАСТ", "Пт, Ср", "Пн, Вт", "Суббота");
            CTeacher T      = new CTeacher();

            T.Insert(tcher);
            T.Insert(tcher1);
            bool expected = true;

            //act
            tcher1.Note          = "Кандидат наук";
            tcher1.Departament   = "ФАСТ";
            tcher1.MetodicalDays = "Пн, Вт";
            tcher1.Windows       = "Ср, Чт, Пт";
            tcher1.Weekends      = "Воскресенье";
            bool actual = T.Update(tcher1);

            //assert
            Assert.AreEqual(expected, actual);
        }
Пример #14
0
 public static void addTeacher(CTeacher teacher)
 {
     DUsersManager.addUser(teacher);
     DUsersManager.addKinderGardenToTeacher(teacher.KinderGardens, teacher.Id);
 }
Пример #15
0
 public int addTeacher([FromBody] CTeacher user)
 {
     BUserManager.addTeacher(user);
     return(1);
 }