Exemplo n.º 1
0
        public void OpenBuyer(RequestBuyer buyer)
        {
            if (buyer == null)
            {
                throw new CustomException(500, "输入信息丢失");
            }
            var isexist = this.businessmanRepository.FindAll(p => p.Code == buyer.Code).Count() > 0;

            if (isexist)
            {
                throw new CustomException(500, string.Format("{0}已存在", buyer.Code));
            }
            var curentUser         = AuthManager.GetCurrentUser();
            var businessmanBuilder = AggregationFactory.CreateBuiler <BusinessmanBuilder>();

            buyer.CarrierCode = curentUser.Code;
            Buyer by = businessmanBuilder.CreateBuyer(AutoMapper.Mapper.Map <RequestBuyer, Buyer>(buyer));

            by.CheckRule();
            var cashbagModel = accountClientProxy.AddCompany(curentUser.CashbagCode, curentUser.CashbagKey, new BPiaoBao.Cashbag.Domain.Models.CashCompanyInfo
            {
                ClientAccount = buyer.Code,
                Contact       = buyer.ContactWay.Contact,
                CpyName       = buyer.Name,
                Moblie        = buyer.ContactWay.Tel,
                Province      = buyer.ContactWay.Province,
                City          = buyer.ContactWay.City,
                Address       = buyer.ContactWay.Address
            });

            try
            {
                by.CashbagCode = cashbagModel.PayAccount;
                by.CashbagKey  = cashbagModel.Token;
                unitOfWorkRepository.PersistCreationOf(by);
                unitOfWork.Commit();
            }
            catch (Exception e)
            {
                Logger.WriteLog(LogType.ERROR, "添加商户发生异常", e);
                accountClientProxy.DeleteCashBagBusinessman(curentUser.CashbagCode, cashbagModel.PayAccount, curentUser.CashbagKey);
                throw new CustomException(500, "添加商户发生异常");
            }
        }