public ActionResult Add(PurchaseDataModel model) { if (ModelState.IsValid) { PurchaseData Purchase = model.MapTo <PurchaseDataModel, PurchaseData>(); InventoryData inventoryData = new InventoryData() { WarehouseID = model.WarehouseID, WarehouseName = model.WarehouseName, GoodsID = model.GoodsID, GoodsName = model.GoodsName, Unit = model.Unit, Specification = model.Specification, GoodsType = model.GoodsType, Brand = model.Brand, InventoryQuantity = model.Quantity, CostPrice = ((model.Quantity != 0) ? (model.Sum / Convert.ToDecimal(model.Quantity)) : 0), InventorySum = model.Sum, SupplierID = model.SupplierID, SupplierName = model.SupplierName, SupplierAddress = model.SupplierAddress, PurchaseDate = DateTime.Now, ShipmentsDate = DateTime.Now, LastInventoryDate = DateTime.Now, FinalSaleDate = DateTime.Now, Active = "1", ShipmentsQuantity = 0, RemainingQuantity = model.Quantity }; //添加货物库存表返回ID int inventoryDataID = _inventoryDataService.Insert(inventoryData); Purchase.InventoryDataID = inventoryDataID; Purchase.Active = "1"; _purchaseDataService.Insert(Purchase); return(RedirectToAction("Index")); } model.GoodsList = GetGoodsList(); model.SupplierList = GetSupplierList(); model.WarehouseList = GetWarehouseList(); model.SpecificationList = GetSpecificationList(); model.GoodsTypeList = GetGoodsTypeList(); return(View(model)); }