예제 #1
0
        public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

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

            FrameworkUserVM   vm = rv.Model as FrameworkUserVM;
            FrameworkUserBase v  = new FrameworkUserBase();

            v.ITCode   = "itcode";
            v.Name     = "name";
            v.Password = "******";
            vm.Entity  = v;
            _controller.Create(vm);

            using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <FrameworkUserBase>().FirstOrDefault();
                Assert.AreEqual(data.ITCode, "itcode");
                Assert.AreEqual(data.Name, "name");
                Assert.AreEqual(data.Password, Utils.GetMD5String("password"));
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
예제 #2
0
        public ActionResult Password(FrameworkUserVM vm)
        {
            var keys = ModelState.Keys.ToList();

            foreach (var item in keys)
            {
                if (item != "Entity.Password")
                {
                    ModelState.Remove(item);
                }
            }
            if (ModelState.IsValid == false)
            {
                return(PartialView(vm));
            }
            else
            {
                vm.ChangePassword();
                if (!ModelState.IsValid)
                {
                    vm.DoReInit();
                    return(PartialView(vm));
                }
                else
                {
                    return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID));
                }
            }
        }
예제 #3
0
        public void DeleteTest()
        {
            FrameworkUserBase v = new FrameworkUserBase();

            using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory))
            {
                v.ITCode   = "itcode";
                v.Name     = "name";
                v.Password = "******";
                context.Set <FrameworkUserBase>().Add(v);
                context.SaveChanges();
            }

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

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

            FrameworkUserVM vm = rv.Model as FrameworkUserVM;

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

            using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory))
            {
                Assert.AreEqual(context.Set <FrameworkUserBase>().Count(), 0);
            }
        }
예제 #4
0
        public async Task <IActionResult> Password(FrameworkUserVM vm)
        {
            var keys = ModelState.Keys.ToList();

            foreach (var item in keys)
            {
                if (item != "Entity.Password")
                {
                    ModelState.Remove(item);
                }
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorJson()));
            }
            else
            {
                await vm.ChangePassword();

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState.GetErrorJson()));
                }
                else
                {
                    return(Ok(vm.Entity));
                }
            }
        }
예제 #5
0
 public ActionResult Edit(FrameworkUserVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(vm));
     }
     else
     {
         vm.DoEdit();
         return(FFResult().CloseDialog().RefreshGridRow(typeof(FrameworkUserListVM), vm.Entity.ID));
     }
 }
예제 #6
0
 public ActionResult Create(FrameworkUserVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(PartialView(vm));
     }
     else
     {
         vm.DoAdd();
         return(FFResult().CloseDialog().RefreshGrid());
     }
 }
예제 #7
0
 public IActionResult Edit(FrameworkUserVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     else
     {
         vm.DoEdit(true);
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         else
         {
             return(Ok(vm.Entity));
         }
     }
 }
예제 #8
0
 public IActionResult Add(FrameworkUserVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState.GetErrorJson()));
     }
     else
     {
         vm.DoAdd();
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState.GetErrorJson()));
         }
         else
         {
             return(Ok(vm.Entity));
         }
     }
 }
예제 #9
0
 public IActionResult Put([FromBody] FrameworkUserVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     else
     {
         vm.DoEdit();
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         else
         {
             return(CreatedAtAction(nameof(Get), new { id = vm.Entity.ID }, vm));
         }
     }
 }
예제 #10
0
 public IActionResult Add([FromBody] FrameworkUserVM vm)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     else
     {
         vm.DoAdd();
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         else
         {
             return(Ok(vm.Entity));
         }
     }
 }
예제 #11
0
 public IActionResult Edit(FrameworkUserVM vm)
 {
     ModelState.Remove("Entity.Password");
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState.GetErrorJson()));
     }
     else
     {
         vm.DoEdit(false);
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState.GetErrorJson()));
         }
         else
         {
             return(Ok(vm.Entity));
         }
     }
 }
예제 #12
0
        public async Task <IActionResult> Add(FrameworkUserVM vm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorJson()));
            }
            else
            {
                await vm.DoAddAsync();

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState.GetErrorJson()));
                }
                else
                {
                    return(Ok(vm.Entity));
                }
            }
        }
예제 #13
0
 public ActionResult Edit(FrameworkUserVM vm)
 {
     if (ModelState.Any(x => x.Key != "Entity.Password" && x.Value.ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid))
     {
         return(PartialView(vm));
     }
     else
     {
         ModelState.Clear();
         vm.DoEdit();
         if (!ModelState.IsValid)
         {
             vm.DoReInit();
             return(PartialView(vm));
         }
         else
         {
             return(FFResult().CloseDialog().RefreshGridRow(vm.Entity.ID));
         }
     }
 }
예제 #14
0
        public async Task <ActionResult> Create(FrameworkUserVM vm)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(vm));
            }
            else
            {
                await vm.DoAddAsync();

                if (!ModelState.IsValid)
                {
                    vm.DoReInit();
                    return(PartialView(vm));
                }
                else
                {
                    return(FFResult().CloseDialog().RefreshGrid());
                }
            }
        }
예제 #15
0
        public void EditTest()
        {
            FrameworkUserBase v = new FrameworkUserBase();

            using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory))
            {
                v.ITCode   = "itcode";
                v.Name     = "name";
                v.Password = "******";
                context.Set <FrameworkUserBase>().Add(v);
                context.SaveChanges();
            }

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

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

            FrameworkUserVM vm = rv.Model as FrameworkUserVM;

            v         = new FrameworkUserBase();
            v.ID      = vm.Entity.ID;
            v.ITCode  = "itcode1";
            v.Name    = "name1";
            vm.Entity = v;
            vm.FC     = new Dictionary <string, object>();
            vm.FC.Add("Entity.ITCode", "");
            vm.FC.Add("Entity.Name", "");
            _controller.Edit(vm);

            using (var context = new FrameworkContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <FrameworkUserBase>().FirstOrDefault();
                Assert.AreEqual(data.ITCode, "itcode1");
                Assert.AreEqual(data.Name, "name1");
                Assert.AreEqual(data.UpdateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10);
            }
        }