예제 #1
0
        public StockItem Update(StockItem StockItem, StockItemDto fromDto)
        {
            var resultingStockItem = BuildNew(fromDto);

            // resultingStockItem.Update();
            return(resultingStockItem);
        }
예제 #2
0
        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)
                       ));
        }
예제 #3
0
        private ICommand <StockItem> CreateCommandForState(StockItemDto newState)
        {
            if (_queryMediator.Get(newState.Id) == null)
            {
                return(new CreateStockItemCommand(newState, GetUserId()));
            }

            return(new UpdateStockItemCommand(newState, GetUserId()));
        }
예제 #4
0
        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();
        }
예제 #5
0
        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);
        }
예제 #6
0
        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
                }));
            }
        }
예제 #7
0
        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)));
        }
예제 #8
0
        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));
            }
        }
예제 #9
0
        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));
        }
예제 #10
0
        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;
            }
        }
예제 #11
0
        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
                }));
            }
        }
예제 #12
0
 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.
     }
 }
예제 #13
0
 public CreateStockItemCommand(StockItemDto stockItem, int userId) : base(userId)
 {
     StockItem = stockItem;
 }
예제 #14
0
 private static void ValidateInput(StockItemDto fromDto)
 {
 }
예제 #15
0
 private void OnNextItem(StockItemDto stockItemDto)
 {
     if (stockItemDto.Symbol == _symbol)
         this.StockItem = stockItemDto;
 }
예제 #16
0
 public void Post([FromBody] StockItemDto item)
 {
     _commandMediator.Send(CreateCommandForState(item));
 }