Пример #1
0
        public void UpdateTeacher()
        {
            //Arrange
            var contexFactory = Substitute.For <IContextFactory>();
            var teacherDal    = new TeacherDal(contexFactory);
            var context       = Substitute.For <SchoolContext>();
            var teacherDbSet  = Substitute.For <DbSet <Teacher> >();

            contexFactory.Create().Returns(context);
            context.Teachers = teacherDbSet;

            var teacherDto = new TeacherDto()
            {
                Name    = "Jacek",
                Surname = "Maslak"
            };

            teacherDbSet.Attach(Arg.Do <Teacher>(t =>
                                                 t.Person = new Person()
            {
                Name    = "Pawel",
                Surname = "Styrna"
            }
                                                 ));

            //Act
            teacherDal.UpdateTeacher(1, teacherDto);

            //Assert
            teacherDbSet.Received().Attach(Arg.Is <Teacher>(t => t.Id == 1));
            context.ChangeTracker.Entries().Equals(teacherDto);
            context.Received().SaveChanges();
        }
Пример #2
0
        public void DeleteTg(int tgid)
        {
            TeacherDal            teadal = new TeacherDal();
            DBSession             db     = new DBSession();
            ThemeDal              thdal  = new ThemeDal();
            IQueryable <TeaGroup> iq     = tgdal.GetEntities(u => u.TG_Id == tgid);
            TeaGroup              tg     = new TeaGroup();

            foreach (var item in iq)
            {
                tg = item;
            }
            if (tgdal.DeleteEntity(tg) != null)
            {
                IQueryable <Teacher> tiq = teadal.GetEntities(u => u.TeaGroup == tg);
                foreach (var item in tiq)
                {
                    item.TeaGroup = null;
                }
                IQueryable <Theme> theiq = thdal.GetEntities(u => u.TeaGroup == tg);
                foreach (var item in theiq)
                {
                    item.TeaGroup = null;
                }
            }
            ;

            db.SaveChanges();
        }
Пример #3
0
        public void CreateTeacher()
        {
            //Arrange
            var contexFactory = Substitute.For <IContextFactory>();
            var context       = Substitute.For <SchoolContext>();
            var teacherDbSet  = Substitute.For <DbSet <Teacher> >();

            var teacherDal = new TeacherDal(contexFactory);
            var teacherDto = new TeacherDto()
            {
                Name    = "Jacek",
                Surname = "Maslak"
            };

            contexFactory.Create().Returns(context);
            context.Teachers = teacherDbSet;

            teacherDbSet.Add(Arg.Do <Teacher>(t => t.Id = 1));

            //Act
            var id = teacherDal.CreateTeacher(teacherDto).Result;

            //Assert
            teacherDbSet.Received().Add(Arg.Is <Teacher>(
                                            t => t.Person.Name == teacherDto.Name &&
                                            t.Person.Surname == teacherDto.Surname));
            context.Received().SaveChangesAsync();
            Assert.That(id, Is.EqualTo(1));
        }
Пример #4
0
        public ActionResult GetTeaBySou()
        {
            string key = Request["key"];

            if (string.IsNullOrEmpty(key))
            {
                string str1 = js.Serialize("请输入正确的Key值");
                Response.Write(str1);
                Response.End();
                return(View());
            }
            string               dep     = Request["dep"];
            TeacherDal           teadal1 = new TeacherDal();
            IQueryable <Teacher> iq      = teadal1.GetEntities(u => (u.Tea_Name.Contains(key) || (u.TeaGroup == null ? false : u.TeaGroup.TG_Name.Contains(key))) && u.Department.Dep_Name == dep);
            IList <string>       strlist = new List <string>();
            string               str     = "";

            foreach (var item in iq)
            {
                if (item.TeaGroup != null)
                {
                    str = item.Tea_Id + "-" + item.Tea_Name + "-" + item.Tea_Sex + "-" + item.TeaGroup.TG_Name;
                }
                if (item.TeaGroup == null)
                {
                    str = item.Tea_Id + "-" + item.Tea_Name + "-" + item.Tea_Sex + "-" + " ";
                }
                strlist.Add(str);
            }
            string s = js.Serialize(strlist);

            Response.Write(s);
            Response.End();
            return(View());
        }
Пример #5
0
        public ActionResult GetTeaGroupByDep()
        {
            string                dep    = Request["dep"];
            TeaGroupDal           tgdal  = new TeaGroupDal();
            TeacherDal            teadal = new TeacherDal();
            IQueryable <TeaGroup> iq     = tgdal.GetEntities(u => u.Department.Dep_Name == dep);
            IList <string>        ls     = new List <string>();

            foreach (var item in iq)
            {
                string         lstr = "";
                IList <string> l    = new List <string>();
                l.Add(item.TG_Id + "-" + item.TG_Name + "-");
                TeaGroup             t     = item;
                IQueryable <Teacher> teaiq = teadal.GetEntities(u => u.TeaGroup == t);
                foreach (var item1  in teaiq)
                {
                    l.Add(item1.Tea_Name + "  ");
                }
                for (int i = 0; i < l.Count(); i++)
                {
                    lstr = lstr + l[i];
                }
                ls.Add(lstr);
            }
            string str = js.Serialize(ls);

            // Session["tgmanage"] = ls;
            Response.Write(str);
            string s = string.Empty;

            Response.End();
            return(View());
        }
Пример #6
0
 public ActionResult ChangePassword(Teacher t)
 {
     if (ModelState.IsValid)
     {
         TeacherDal dal = new TeacherDal();
         t.Password = Request.Form["Password"].ToString();
         dal.SaveChanges();
         return(View("SendPassword", t));
     }
     return(View(t));
 }
Пример #7
0
        public ActionResult GetTeasByTg()
        {
            Session["tgid"] = null;
            int tgid = Convert.ToInt32(Request["tgid"]);

            Session["tgid"] = tgid;
            TeacherDal           teadal1 = new TeacherDal();
            IQueryable <Teacher> iq      = teadal1.GetEntities(u => u.TeaGroup.TG_Id == tgid);
            string str = js.Serialize(iq);

            Response.Write(str);

            Response.End();
            return(View());
        }
Пример #8
0
        public ActionResult Submit2(EmployeeNumber num)
        {
            if (ModelState.IsValid)
            {
                TeacherDal     dal = new TeacherDal();
                List <Teacher> l   =
                    (from x in dal.Teachers
                     where x.TeacherId == num.number
                     select x).ToList <Teacher>();

                /*Assistant assis = list[0];
                 * list[0].LastName = "nahmani";
                 * assdal.SaveChanges();*/
                return(View("ChangePassword", l[0]));
            }
            return(View("ForgetPassword", new EmployeeNumber()));
        }
Пример #9
0
        public ActionResult GetTeaListByTgId()
        {
            TeaGroupService      tgser  = new TeaGroupService();
            TeacherDal           teadal = new TeacherDal();
            int                  tgid   = Convert.ToInt32(Request["tgid"]);
            TeaGroup             tg     = tgser.GetTeaGroupById(tgid);
            string               str    = tg.TG_Name + "-";
            IQueryable <Teacher> teaiq  = teadal.GetEntities(u => u.TeaGroup == tg);

            foreach (var item in teaiq)
            {
                str = str + item.Tea_Name + "-";
            }
            Response.Write(str);
            Response.End();
            return(null);
        }
Пример #10
0
        public void DeleteTeacher()
        {
            //Arrange
            var contexFactory = Substitute.For <IContextFactory>();
            var teacherDal    = new TeacherDal(contexFactory);
            var context       = Substitute.For <SchoolContext>();
            var teacherDbSet  = Substitute.For <DbSet <Teacher> >();

            contexFactory.Create().Returns(context);
            context.Teachers = teacherDbSet;

            //Act
            teacherDal.DeleteTeacher(1);

            //Assert
            teacherDbSet.Received().Attach(Arg.Is <Teacher>(t => t.Id == 1));
            teacherDbSet.Received().Remove(Arg.Is <Teacher>(t => t.Id == 1));
            context.Received().SaveChanges();
        }
Пример #11
0
        //public ActionResult Submit([ModelBinder(typeof(TeacherBinder))] Teacher myTeacher)
        public ActionResult Submit(Teacher myTeacher)
        {
            //Teacher myTeacher = new Teacher();
            //myTeacher.FirstName = Request.Form["FirstName"];
            //myTeacher.LastName = Request.Form["LastName"];
            //myTeacher.TeacherId = Request.Form["TeacherId"];

            if (ModelState.IsValid)
            {
                TeacherDal dal = new TeacherDal();
                dal.Teachers.Add(myTeacher);// in memory adding
                dal.SaveChanges();
                return(View("Teacher", myTeacher));
            }
            else
            {
                return(View("Enter", myTeacher));
            }
        }