public async Task <ApiResult> Add(string Title, string Note, int Sorting, bool IsEnable) { // 以接口的形式返回数据 var res = new ApiResult(); if (string.IsNullOrWhiteSpace(Title)) { res.msg = "请填写标题"; } else { try { Provider m = new Provider() { Title = Title, Sorting = Sorting, Note = Note, AddDate = DateTime.Now, IsEnable = IsEnable }; res.success = providerdb.Add(m) > 0; } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.msg = ApiEnum.Error.GetEnumText() + ex.Message; } } // {"success":true,"message":null,"statusCode":200,"data":null} return(await Task.Run(() => res)); }
public HttpResponseMessage Create(HttpRequestMessage request, ProviderViewModel providerVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { var newProvider = new Provider(); newProvider.UpdateProvider(providerVm); newProvider.CreatedDate = DateTime.Now; newProvider.CreatedBy = User.Identity.Name; newProvider.UpdatedDate = DateTime.Now; newProvider.UpdatedBy = User.Identity.Name; _providerService.Add(newProvider); _providerService.Save(); var responseData = Mapper.Map <Provider, ProviderViewModel>(newProvider); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
private void btnAddNew_Click(object sender, EventArgs e) { ProviderAddForm providerAddForm = new ProviderAddForm(); var result = providerAddForm.ShowDialog(); if (result == DialogResult.OK) { _providerService.Add(providerAddForm.Provider); UpdateList(); } }
public async Task <ActionResult <ProviderViewModel> > Create(ProviderViewModel providerViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } await _providerService.Add(_mapper.Map <Provider>(providerViewModel)); return(CustomResponse(providerViewModel)); }
public async Task <ActionResult <ProviderResponseDto> > Add(ProviderRequestDto providerDto) { var provider = await _service.Add(_mapper.Map <Provider>(providerDto)); if (_notification.Any) { return(BadRequest(_notification.Messages)); } return(Ok(_mapper.Map <ProviderResponseDto>(provider))); }
public async Task <ActionResult <ProviderDTO> > Create(ProviderDTO providerDTO) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } var provider = _mapper.Map <Provider>(providerDTO); await _service.Add(provider); return(CustomResponse(providerDTO)); }
public ActionResult Create([Bind(Include = "ID,Name")] Provider provider) { if (ModelState.IsValid) { _providerService.Add(provider); _providerService.SaveChanges(); return(RedirectToAction("Index")); } return(View(provider)); }
public async Task <IActionResult> Create(ProviderViewModel providerViewModel) { if (!ModelState.IsValid) { return(View(providerViewModel)); } var provider = _mapper.Map <Provider>(providerViewModel); await _providerService.Add(provider); if (!OperacaoValida()) { return(View(providerViewModel)); } return(RedirectToAction(nameof(Index))); }
public void Setup() { IConsumerNotifier notifier = new ConsumerNotifier(Substitute.For <INdmNotifier>()); DepositsInMemoryDb db = new DepositsInMemoryDb(); IProviderRepository providerRepository = new ProviderInMemoryRepository(db); DataAssetProvider provider = new DataAssetProvider(_providerAddress, "provider"); DataAssetService dataAssetService = new DataAssetService(providerRepository, notifier, LimboLogs.Instance); _asset1 = new DataAsset(_asset1Id, "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1), new DataAssetRule(100)), provider, state: DataAssetState.Published); dataAssetService.AddDiscovered(_asset1, _ndmPeer); _deposit1 = new Deposit(_deposit1Id, 1, 2, 3); _details1 = new DepositDetails(_deposit1, _asset1, Address.Zero, new byte[0], 1, new TransactionInfo[0], 1); _asset2 = new DataAsset(_asset2Id, "name", "desc", 1, DataAssetUnitType.Time, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published); dataAssetService.AddDiscovered(_asset2, _ndmPeer); _deposit2 = new Deposit(_deposit2Id, 1, 2, 3); _details2 = new DepositDetails(_deposit2, _asset2, Address.Zero, new byte[0], 1, new TransactionInfo[0], 2); _closed = new DataAsset(_closedId, "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Closed); dataAssetService.AddDiscovered(_closed, _ndmPeer); _depositForClosed = new Deposit(_depositForClosedId, 1, 2, 3); _depositForClosedDetails = new DepositDetails(_depositForClosed, _closed, Address.Zero, new byte[0], 1, new TransactionInfo[0]); _missingAsset = new DataAsset(_missingAssetId, "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published); _depositForMissing = new Deposit(_depositForMissingId, 1, 2, 3); _depositForMissingDetails = new DepositDetails(_depositForMissing, _missingAsset, Address.Zero, new byte[0], 1, new TransactionInfo[0]); IDepositProvider depositProvider = Substitute.For <IDepositProvider>(); depositProvider.GetAsync(_deposit1Id).Returns(_details1); depositProvider.GetAsync(_deposit2Id).Returns(_details2); depositProvider.GetAsync(_depositForMissingId).Returns(_depositForMissingDetails); depositProvider.GetAsync(_depositForClosedId).Returns(_depositForClosedDetails); _ndmPeer = Substitute.For <INdmPeer>(); _ndmPeer.ProviderAddress.Returns(_providerAddress); _ndmPeer.NodeId.Returns(_providerNodeId); _providerService = new ProviderService(providerRepository, notifier, LimboLogs.Instance); _providerService.Add(_ndmPeer); _sessionRepository = new ConsumerSessionInMemoryRepository(); _sessionService = new SessionService(_providerService, depositProvider, dataAssetService, _sessionRepository, Timestamper.Default, notifier, LimboLogs.Instance); }
public async Task <IActionResult> Create(ProviderViewModel providerViewModel) { if (!ModelState.IsValid) { return(View(providerViewModel)); } var provider = _mapper.Map <Provider>(providerViewModel); await _providerService.Add(provider); if (!ValidOperation()) { return(View(providerViewModel)); } TempData["Success"] = "Provider successfully created."; return(RedirectToAction("Index")); }
public ActionResult <ItemResponse <int> > Create(ProviderAddRequest model) { int code = 201; BaseResponse response = null; try { int userId = _authService.GetCurrentUserId(); int id = _service.Add(model, userId); response = new ItemResponse <int> { Item = id }; // Provider Id } catch (Exception ex) { code = 500; response = new ErrorResponse($"ArgumentException Error: {ex.ToString() }"); base.Logger.LogError(ex.ToString()); } return(StatusCode(code, response)); }
public void AddProviderPeer(INdmPeer peer) => _providerService.Add(peer);
// POST: api/Provider public void Post([FromBody] ProviderDT value) { _providerService.Add(value); }
public ActionResult Post([FromBody] Provider model) { return(Ok( _providerService.Add(model))); }