Ejemplo n.º 1
0
        public bool PostSalesOrder(int id)
        {
            Model.SalesOrdersModel oneOrder = GetOneSalesOrder(id);
            if (oneOrder.Status.Equals("已出库"))
            {
                Exception oe = new Exception();
                throw new FaultException <Exception>(oe, "订单已出库");
            }
            List <Model.SalesCommodityModel> salesCommoditiesList = GetSalesCommoditiesByID(id).ToList();
            List <Model.SalesCommodityModel> errorList            = salesCommoditiesList.Where(u => u.CommodityInventory < u.Count).ToList();

            //简单处理回滚,因为一条不成功,所有记录操作所有被回滚
            //这儿确保安全无误后对库存进行更新
            if (errorList.Count > 0)
            {
                Exception oe      = new Exception();
                string    message = "提交失败!\r\n";
                foreach (Model.SalesCommodityModel oneErrorSalesCommodity in errorList)
                {
                    message += string.Format("{0}的当前库存({1})小于订单的数量({2})!\r\n", oneErrorSalesCommodity.CommodityName, oneErrorSalesCommodity.CommodityInventory, oneErrorSalesCommodity.Count);
                }
                throw new FaultException <Exception>(oe, message);
            }
            IDAL.ICommodityService commodityService = new MSSQLDAL.CommodityService();
            foreach (Model.SalesCommodityModel oneSalesCommodity in salesCommoditiesList)
            {
                Model.CommodityModel oneCommodity = new Model.CommodityModel();
                oneCommodity.ID           = oneSalesCommodity.CommodityID;
                oneCommodity.Name         = oneSalesCommodity.CommodityName;
                oneCommodity.Type         = oneSalesCommodity.CommodityType;
                oneCommodity.Manufacturer = oneSalesCommodity.CommodityManufacturer;
                oneCommodity.Unit         = oneSalesCommodity.CommodityUnit;
                oneCommodity.UnitPrice    = oneSalesCommodity.CommodityUnitPrice;
                oneCommodity.Inventory    = oneSalesCommodity.CommodityInventory - oneSalesCommodity.Count;

                commodityService.AddEntity(oneCommodity);
            }
            oneOrder.Status = "已出库";
            IDAL.ISalesOrdersService salesOrderService = new MSSQLDAL.SalesOrderService();
            //return salesOrderService.UpdateEntity(oneOrder);
            return(dataFactory.SalesOrderDal.UpdateEntity(oneOrder));
        }
Ejemplo n.º 2
0
 public Model.SalesOrdersModel GetOneSalesOrder(int id)
 {
     IDAL.ISalesOrdersService salesOrdersService = new MSSQLDAL.SalesOrderService();
     //return salesOrdersService.GetOneEntityByID(id);
     return(dataFactory.SalesOrderDal.GetOneEntityByID(id));
 }