public async Task <IActionResult> PutProductUnit(int id, ProductUnitVM puvm) { if (id != puvm.Product_Unit_ID) { return(BadRequest()); } Product_Unit pu = new Product_Unit(); pu.Product_Unit_ID = puvm.Product_Unit_ID; pu.Product_Unit_Quantity = puvm.Product_Unit_Quantity; db1.Entry(pu).State = EntityState.Modified; await db1.SaveChangesAsync(); try { await db1.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!Product_UnitExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void EditTest() { ProductUnit v = new ProductUnit(); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { v.PUName = "4PBK"; context.Set <ProductUnit>().Add(v); context.SaveChanges(); } ProductUnitVM vm = _controller.Wtm.CreateVM <ProductUnitVM>(); var oldID = v.ID; v = new ProductUnit(); v.ID = oldID; v.PUName = "Fwgq"; vm.Entity = v; vm.FC = new Dictionary <string, object>(); vm.FC.Add("Entity.PUName", ""); var rv = _controller.Edit(vm); Assert.IsInstanceOfType(rv, typeof(OkObjectResult)); using (var context = new DataContext(_seed, DBTypeEnum.Memory)) { var data = context.Set <ProductUnit>().Find(v.ID); Assert.AreEqual(data.PUName, "Fwgq"); Assert.AreEqual(data.UpdateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.UpdateTime.Value).Seconds < 10); } }
public async Task <ActionResult <Product_Unit> > PostProductUnit([FromBody] ProductUnitVM puvm) { Product_Unit pu = new Product_Unit(); //pu.Product_Unit_ID = puvm.Product_Unit_ID; pu.Product_Unit_Quantity = puvm.Product_Unit_Quantity; db1.Product_Unit.Add(pu); //db1.Entry(pu).State = EntityState.Modified; await db1.SaveChangesAsync(); return(Ok()); }
public IActionResult Edit(ProductUnitVM 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 CreateTest() { ProductUnitVM vm = _controller.Wtm.CreateVM <ProductUnitVM>(); ProductUnit v = new ProductUnit(); v.PUName = "4PBK"; 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 <ProductUnit>().Find(v.ID); Assert.AreEqual(data.PUName, "4PBK"); Assert.AreEqual(data.CreateBy, "user"); Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10); } }