public int AddOrUpdateCommodityProperty(AddOrUpdateCommodityPropertyDTO commodityProperty, string operatorName)
        {
            if (commodityProperty == null)
            {
                throw new BusinessException("商品对象未设定");
            }
            if (string.IsNullOrWhiteSpace(operatorName))
            {
                throw new BusinessException("操作人未设定");
            }
            if (string.IsNullOrWhiteSpace(commodityProperty.PropertyCategoryUUID))
            {
                throw new BusinessException("请设定属性类别");
            }
            if (string.IsNullOrWhiteSpace(commodityProperty.CommodityUUID))
            {
                throw new BusinessException("请设定商品");
            }

            CRestaurantPO restaurant = CRestaurantManager.Instance.GetById(commodityProperty.ResId);

            if (restaurant == null)
            {
                throw new BusinessException("此餐厅不存在");
            }

            Core.Data.QueryResult <CCommodityPO> commodityResult = CCommodityManager.Instance.GetCCommoditys(null, null, commodityProperty.CommodityUUID, null, null, 1, 1, null);
            if (commodityResult == null || commodityResult.Items == null || commodityResult.Items.Length == 0)
            {
                throw new BusinessException("此商品不存在");
            }

            Core.Data.QueryResult <CPropertyCategoryPO> propertyCategoryResult = CPropertyCategoryManager.Instance.GetPropertyCategorys(null, new List <string> {
                commodityProperty.PropertyCategoryUUID
            }, 1, 1);
            if (propertyCategoryResult == null || propertyCategoryResult.Items == null || propertyCategoryResult.Items.Length == 0)
            {
                throw new BusinessException("此属性类别不存在");
            }

            CCommodityPropertyPO commodityPropertyPO = null;

            if (commodityProperty.Id > 0)
            {
                commodityPropertyPO = CCommodityPropertyManager.Instance.GetById(commodityProperty.Id);
                if (commodityPropertyPO == null)
                {
                    throw new BusinessException("商品不存在");
                }
            }
            else
            {
                commodityPropertyPO = new CCommodityPropertyPO();
            }

            commodityPropertyPO.AddPrice             = commodityProperty.AddPrice;
            commodityPropertyPO.ChineseName          = commodityProperty.ChineseName;
            commodityPropertyPO.CommodityUUID        = commodityProperty.CommodityUUID;
            commodityPropertyPO.EnglishName          = commodityProperty.EnglishName;
            commodityPropertyPO.IsDelete             = commodityProperty.IsDelete;
            commodityPropertyPO.PropertyCategoryUUID = commodityProperty.PropertyCategoryUUID;
            commodityPropertyPO.ResUUID = restaurant.ResUUID;
            commodityPropertyPO.Sort    = commodityProperty.Sort;

            if (commodityPropertyPO.Id > 0)
            {
                return(Update(commodityPropertyPO, operatorName));
            }
            else
            {
                return(Add(commodityPropertyPO, operatorName));
            }
        }
Beispiel #2
0
 public ReturnValue <int> AddOrUpdateCommodityProperty(AddOrUpdateCommodityPropertyDTO commodityProperty, string operatorName)
 {
     return(ReturnValue <int> .Get200OK(CCommodityPropertyManager.Instance.AddOrUpdateCommodityProperty(commodityProperty, operatorName)));
 }