/// <summary> /// /// </summary> public void CreateShopExpress(BShopExpress express) { if (this.CurrentUserPermission.ADD_SHOP_EXPRESS == 0) { throw new KMJXCException("没有权限添加店铺快递信息"); } if (express == null) { throw new KMJXCException("异常出错"); } using (KuanMaiEntities db = new KuanMaiEntities()) { using (TransactionScope trans = new TransactionScope()) { Express_Shop es=(from exp in db.Express_Shop where exp.Express_ID==express.ID && exp.Shop_ID==this.Shop.Shop_ID select exp).FirstOrDefault<Express_Shop>(); if (es != null) { throw new KMJXCException("已经添加过此快递公司"); } es = new Express_Shop(); es.Shop_ID = this.Shop.Shop_ID; es.Express_ID = express.ID; es.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); es.Modified = es.Created; es.Created_By = this.CurrentUser.ID; es.Modified_By = es.Created_By; if (express.IsDefault) { es.IsDefault = 1; //revert old default exp Express_Shop defaultExp=(from exp in db.Express_Shop where exp.IsDefault==1 && exp.Shop_ID==es.Shop_ID select exp).FirstOrDefault<Express_Shop>(); if (defaultExp != null) { defaultExp.IsDefault = 0; } } else { es.IsDefault = 0; } db.Express_Shop.Add(es); db.SaveChanges(); if (express.Fees != null && express.Fees.Count > 0) { foreach (BExpressFee fee in express.Fees) { Express_Fee sFee = new Express_Fee(); if (fee.City != null) { sFee.City_ID = fee.City.ID; } sFee.Created = es.Created; sFee.Created_By = es.Created_By; sFee.Express_ID = es.Express_ID; sFee.Fee = fee.Fee; sFee.Modified = es.Modified; sFee.Modified_By = es.Modified_By; if (fee.Province != null) { sFee.Province_ID = fee.Province.ID; } if (fee.StoreHouse != null && fee.StoreHouse.ID > 0) { sFee.StoreHouse_ID = fee.StoreHouse.ID; } else { continue; } sFee.Shop_ID = es.Shop_ID; db.Express_Fee.Add(sFee); } } db.SaveChanges(); trans.Complete(); } } }
public void CreateExpressFees(BShopExpress express) { if (this.CurrentUserPermission.ADD_SHOP_EXPRESS == 0) { throw new KMJXCException("没有权限添加店铺快递信息"); } if (express == null) { throw new KMJXCException("异常出错"); } using (KuanMaiEntities db = new KuanMaiEntities()) { using (TransactionScope trans = new TransactionScope()) { Express_Shop es = (from exp in db.Express_Shop where exp.Express_ID == express.ID && exp.Shop_ID == this.Shop.Shop_ID select exp).FirstOrDefault<Express_Shop>(); if (es == null) { throw new KMJXCException("店铺还没有添加此快递公司,请先添加快递公司,然后再添加快递费用"); } List<Express_Fee> allFees=(from fee in db.Express_Fee where fee.Shop_ID==es.Shop_ID select fee).ToList<Express_Fee>(); if (express.Fees != null && express.Fees.Count > 0) { foreach (BExpressFee fee in express.Fees) { if (fee.City == null && fee.Province == null) { continue; } if (fee.City == null) { fee.City = new BArea() { ID = 0 }; } if (fee.Province == null) { fee.Province = new BArea() { ID = 0 }; } Express_Fee sFee = (from efee in allFees where efee.Express_ID==es.Express_ID && efee.Province_ID == fee.Province.ID && efee.City_ID == fee.City.ID && efee.StoreHouse_ID == fee.StoreHouse.ID select efee).FirstOrDefault<Express_Fee>(); bool isNew = false; if (sFee == null) { isNew = true; sFee = new Express_Fee(); } sFee.Fee = fee.Fee; sFee.Modified = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); sFee.Modified_By = this.CurrentUser.ID; if (fee.StoreHouse != null && fee.StoreHouse.ID > 0) { sFee.StoreHouse_ID = fee.StoreHouse.ID; } else { continue; } if (isNew) { if (fee.Province != null) { sFee.Province_ID = fee.Province.ID; } if (fee.City != null) { sFee.City_ID = fee.City.ID; } sFee.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); sFee.Created_By = this.CurrentUser.ID; sFee.Express_ID = es.Express_ID; sFee.Shop_ID = es.Shop_ID; db.Express_Fee.Add(sFee); } } } db.SaveChanges(); trans.Complete(); } } }