public ResultEntity <bool> AddDealer([FromBody] AddDealerDto addDealerDto) { var result = new ResultEntity <bool>(); //创建经销商EF 连接上下文 var dealerEFCoreContext = new DealerEFCoreContext(); //EF仓储 var repository = new EFCoreRepository(dealerEFCoreContext); //经销商EF仓库 var dealerEFCoreRepository = new DealerEFCoreRepository(dealerEFCoreContext); //经销商登陆仓库 var loginEFCoreRepository = new LoginEFCoreRepository(dealerEFCoreContext); AddDealerUseCase addDealerUseCase = new AddDealerUseCase(repository, dealerEFCoreRepository, loginEFCoreRepository); try { result = addDealerUseCase.AddDealer(addDealerDto); result.IsSuccess = true; result.Count = 1; result.Msg = "经销商注册成功"; } catch (OverTwoSubExeption ex) { result.IsSuccess = false; result.Msg = ex.Message; result.ErrorCode = 300; } catch (Exception ex) { result.IsSuccess = false; result.Msg = ex.Message; result.ErrorCode = 200; } return(result); }
public ResultEntity <bool> AddDealer(AddDealerDto addDealerDto) { //内存中组织对象 var dealerid = Guid.NewGuid(); var dealercontact = new List <Contact>(); for (int i = 0; i < addDealerDto.ContactName.Count; i++) { var dealercontactmodel = new Contact().CreateContact(dealerid, addDealerDto.ContactName[i], addDealerDto.ContactTel[i], addDealerDto.ContactSheng[i], addDealerDto.ContactShi[i], addDealerDto.ContactQu[i], addDealerDto.ContactJiedao[i], addDealerDto.ContactIsDefault[i] ); dealercontact.Add(dealercontactmodel); } var dealer = new Dealers(_dealerRepository).RegisterDealers(dealerid, addDealerDto.Name, addDealerDto.Tel, addDealerDto.EleMoney, dealercontact, addDealerDto.Parentid); var login = new Login().CreateLogin(dealer.Tel, dealerid); //实际持续化到数据库中 try { using (_repository) { _dealerRepository.CreateDealer(dealer); if (addDealerDto.Parentid != null) { _dealerRepository.SubParentEleMoney((Guid)addDealerDto.Parentid, addDealerDto.EleMoney); } _dealerRepository.AddParentSubCount(addDealerDto.Parentid); _loginRepository.CreateLogin(login); _repository.Commit(); } return(GetResultEntity(true)); } catch (Exception ex) { throw ex; } }
public async Task <ServiceResponse <List <GetDealerDto> > > AddDealer(AddDealerDto newDealer) { ServiceResponse <List <GetDealerDto> > serviceResponse = new ServiceResponse <List <GetDealerDto> >(); Dealer dealer = _mapper.Map <Dealer>(newDealer); using (IDbConnection dbConnection = _connection) { string query = @" INSERT INTO [dbo].[Dealer] ([DealerNo] ,[DealerName] ,[SearchName]) VALUES (@DealerNo ,@DealerName ,@SearchName)"; await dbConnection.ExecuteAsync(query, dealer); } serviceResponse.Data = GetAllDealers().Result.Data; return(serviceResponse); }
public void AddDealerTest() { http = new HttpClient(); var addDealerDto = new AddDealerDto() { Name = "沈柱", Tel = "123456789", ContactName = new List <string>() { "张三", "李四" }, ContactTel = new List <string> { "1234567", "7654321" }, ContactIsDefault = new List <int> { 1, 0 }, ContactSheng = new List <string> { "湖北省", "上海省" }, ContactShi = new List <string> { "武汉", "上海市" }, ContactQu = new List <string> { "黄陂区", "闵行区" }, ContactJiedao = new List <string> { "李家集", "联航路" }, EleMoney = 2000 }; var json = JsonConvert.SerializeObject(addDealerDto); HttpContent httpContent = new StringContent(json); httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); var result = http.PostAsync("http://localhost:57817/api/Dealer/AddDealer", httpContent).Result; var val = result.Content.ReadAsStringAsync().Result; }
public async Task <IActionResult> Add(AddDealerDto newDealer) { return(Ok(await _dealerService.AddDealer(newDealer))); }