public StockItem Update(StockItem StockItem, StockItemDto fromDto) { var resultingStockItem = BuildNew(fromDto); // resultingStockItem.Update(); return(resultingStockItem); }
public async Task <ActionResult> CreateStockItem(StockItemDto stockItemDto) { await _posAuthLoader.AssertResourceAccessAsync(User, stockItemDto.PointOfSaleId, IsAuthorizedUserPolicy.Instance); return(await SendAndHandleIdentifierResultCommand( new CreateStockItem(Guid.NewGuid(), stockItemDto.DisplayName, stockItemDto.PointOfSaleId), nameof(GetStockItem) )); }
private ICommand <StockItem> CreateCommandForState(StockItemDto newState) { if (_queryMediator.Get(newState.Id) == null) { return(new CreateStockItemCommand(newState, GetUserId())); } return(new UpdateStockItemCommand(newState, GetUserId())); }
public void GetStockItem_ConstructsQuery_ReturnsResultOfDispatch() { var stockItemId = TestIds.A; var result = new StockItemDto(); _dispatcherMock.Setup(d => d.QueryAsync(It.Is <GetStockItem>(q => q.Id == stockItemId))).ReturnsAsync(result).Verifiable(); var actionResult = _controller.GetStockItem(stockItemId).GetAwaiter().GetResult(); Assert.AreEqual(actionResult.Value, result); _dispatcherMock.Verify(); }
public StockItem BuildNew(StockItemDto buildData) { ValidateInput(buildData); var resultingStockItem = new StockItem( buildData.Id, LookupItem.GetFromCache <ProductType>(_cache, (int)buildData.ProductTypeId), (int)buildData.Quantity, (double)buildData.Price, LookupItem.GetFromCache <StockOwner>(_cache, (int)buildData.OwnerId), buildData.AdvertId); return(resultingStockItem); }
public IActionResult Create([FromBody] StockItemDto stockItemDto) { StockItem stockItem = mapper.Map <StockItem>(stockItemDto); try { stockItemService.Create(stockItem); return(Ok(stockItem)); } catch (ApplicationException ex) { return(BadRequest(new { message = ex.Message })); } }
public async Task <ActionResult> UpdateStockItem(Guid id, StockItemDto stockItemDto) { var stockItem = await _stockItemsService.GetStockItem(id); if (stockItem is null) { return(NotFound()); } await _posAuthLoader.AssertResourceAccessAsync(User, stockItem.PointOfSaleId, IsAuthorizedUserPolicy.Instance); if (stockItem.PointOfSaleId != stockItemDto.PointOfSaleId) { await _posAuthLoader.AssertResourceAccessAsync(User, stockItemDto.PointOfSaleId, IsAuthorizedUserPolicy.Instance); } return(await SendAndHandleOperationCommand(new UpdateStockItem(id, stockItemDto.DisplayName, stockItemDto.PointOfSaleId))); }
public IActionResult Put(Guid id, [FromBody] StockItemDto newState) { // Set the Id from the URI to the DTO to send on newState.Id = id; // Ensure the current user is the stock owner newState.OwnerId = GetUserId(); try { _commandMediator.Send(CreateCommandForState(newState)); return(Created($"/api/stockitem/{id}", _queryMediator.Get(id))); } catch (System.Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult Add(Guid?id) { var stock = new StockItemDto(); if (id.HasValue) { stock = new StockItemDto(); //await GetAdvert((Guid)advertId); } var vm = new EditStockItemViewModel() { UserName = _userDetails.GetUserName(), UserId = _userDetails.GetUserId(), DashboardUrl = _options.Value.DashboardUrl, StockItem = stock }; return(View(vm)); }
public void UpdateAdvert(StockItemDto stockItem) { SetBearerToken(); var jsonString = JsonConvert.SerializeObject(stockItem); var payload = new StringContent(jsonString, Encoding.UTF8, "application/json"); HttpResponseMessage result; try { result = client.PutAsync($"{client.BaseAddress}publishedadverts/{stockItem.AdvertId}", payload).Result; } catch (System.Exception ex) { Console.WriteLine("Exception from {0}: {1}", client.BaseAddress, ex.Message); throw; } }
public IActionResult Update(int id, [FromBody] StockItemDto stockItemDto) { var stockItem = mapper.Map <StockItem>(stockItemDto); stockItem.StockItemId = id; try { stockItemService.Update(stockItem); return(Ok()); } catch (ApplicationException ex) { return(BadRequest(new { messaage = ex.Message })); } }
public IActionResult PublishAdvert(Guid id, [FromBody] StockItemDto data) { try { _command.Send(new PublishAdvertCommand(id, (int)data.Quantity)); return(new StatusCodeResult((int)HttpStatusCode.Accepted)); } catch (ItemNotFoundException) { return(NotFound()); } catch (InvalidOperationException ex) { return(BadRequest(ex.Message)); } catch { return(NotFound()); // Better a 404 than a potential hack vector. } }
public CreateStockItemCommand(StockItemDto stockItem, int userId) : base(userId) { StockItem = stockItem; }
private static void ValidateInput(StockItemDto fromDto) { }
private void OnNextItem(StockItemDto stockItemDto) { if (stockItemDto.Symbol == _symbol) this.StockItem = stockItemDto; }
public void Post([FromBody] StockItemDto item) { _commandMediator.Send(CreateCommandForState(item)); }