public IActionResult Edit(PlayerInfoApiVM vm) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorJson())); } else { vm.DoEdit(false); if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorJson())); } else { return(Ok(vm.Entity)); } } }
public void EditTest() { PlayerInfo v = new PlayerInfo(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.Sex = 71; v.Sect = 53; context.Set <PlayerInfo>().Add(v); context.SaveChanges(); } PlayerInfoApiVM vm = _controller.CreateVM <PlayerInfoApiVM>(); var oldID = v.ID; v = new PlayerInfo(); v.ID = oldID; v.Sex = 39; v.Sect = 95; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.Sex", ""); vm.FC.Add("Entity.Sect", ""); var rv = _controller.Edit(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <PlayerInfo>().FirstOrDefault(); Assert.AreEqual(data.Sex, 39); Assert.AreEqual(data.Sect, 95); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public void CreateTest() { PlayerInfoApiVM vm = _controller.CreateVM <PlayerInfoApiVM>(); PlayerInfo v = new PlayerInfo(); v.Sex = 71; v.Sect = 53; vm.Entity = v; var rv = _controller.Add(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <PlayerInfo>().FirstOrDefault(); Assert.AreEqual(data.Sex, 71); Assert.AreEqual(data.Sect, 53); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }