コード例 #1
0
        public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

            Assert.IsInstanceOfType(rv.Model, typeof(MajorVM));

            MajorVM vm = rv.Model as MajorVM;
            Major   v  = new Major();

            v.MajorCode = "mH280Yr";
            v.MajorName = "5jNsB";
            v.SchoolId  = AddSchool();
            vm.Entity   = v;
            _controller.Create(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Major>().FirstOrDefault();

                Assert.AreEqual(data.MajorCode, "mH280Yr");
                Assert.AreEqual(data.MajorName, "5jNsB");
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
コード例 #2
0
        public void DeleteTest()
        {
            Major v = new Major();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.MajorCode = "mH280Yr";
                v.MajorName = "5jNsB";
                v.SchoolId  = AddSchool();
                context.Set <Major>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Delete(v.ID);

            Assert.IsInstanceOfType(rv.Model, typeof(MajorVM));

            MajorVM vm = rv.Model as MajorVM;

            v         = new Major();
            v.ID      = vm.Entity.ID;
            vm.Entity = v;
            _controller.Delete(v.ID, null);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <Major>().Count(), 0);
            }
        }
コード例 #3
0
        public ActionResult EditMajor(int id)
        {
            var     major   = MajorRepository.Get(id);
            MajorVM majorVM = new MajorVM();

            majorVM.MajorName = major.MajorName;
            majorVM.MajorId   = major.MajorId;
            return(View(majorVM));
        }
コード例 #4
0
 public ActionResult EditMajor(MajorVM majorVM)
 {
     if (ModelState.IsValid)
     {
         Major major = new Major();
         major.MajorId   = majorVM.MajorId;
         major.MajorName = majorVM.MajorName;
         MajorRepository.Edit(major);
         return(RedirectToAction("Majors"));
     }
     else
     {
         return(View(majorVM));
     }
 }
コード例 #5
0
        public void EditTest()
        {
            Major v = new Major();

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                v.MajorCode = "mH280Yr";
                v.MajorName = "5jNsB";
                v.SchoolId  = AddSchool();
                context.Set <Major>().Add(v);
                context.SaveChanges();
            }

            PartialViewResult rv = (PartialViewResult)_controller.Edit(v.ID);

            Assert.IsInstanceOfType(rv.Model, typeof(MajorVM));

            MajorVM vm = rv.Model as MajorVM;

            v    = new Major();
            v.ID = vm.Entity.ID;

            v.MajorCode = "BzktnsT";
            v.MajorName = "8C2p";
            vm.Entity   = v;
            vm.FC       = new Dictionary <string, object>();

            vm.FC.Add("Entity.MajorCode", "");
            vm.FC.Add("Entity.MajorName", "");
            vm.FC.Add("Entity.SchoolId", "");
            _controller.Edit(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Major>().FirstOrDefault();

                Assert.AreEqual(data.MajorCode, "BzktnsT");
                Assert.AreEqual(data.MajorName, "8C2p");
                Assert.AreEqual(data.UpdateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10);
            }
        }
コード例 #6
0
ファイル: MajorController.cs プロジェクト: zgk1994/WTM
 public ActionResult Edit(MajorVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(vm));
     }
     else
     {
         vm.DoEdit();
         if (!ModelState.IsValid)
         {
             vm.DoReInit();
             return(PartialView(vm));
         }
         else
         {
             return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID));
         }
     }
 }
コード例 #7
0
ファイル: MajorController.cs プロジェクト: zgk1994/WTM
 public ActionResult Create(MajorVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(vm));
     }
     else
     {
         vm.DoAdd();
         if (!ModelState.IsValid)
         {
             vm.DoReInit();
             return(PartialView(vm));
         }
         else
         {
             return(FFResult().CloseDialog().RefreshGrid());
         }
     }
 }