示例#1
0
        public async Task <StockItemUpdate> Update(StockItemUpdate request)
        {
            var stockItem = await _stockManagerService.GetById(request.Id);

            if (stockItem == null)
            {
                return(null);
            }
            _mapper.Map(request, stockItem);
            await _stockManagerService.Update(stockItem);

            var result = _mapper.Map <StockItemUpdate>(stockItem);

            return(result);
        }
        public async void Update(string equipmentId, StockItem original, StockItemUpdate update)
        {
            Equipment eq = await _equipment.Find <Equipment>(equipment => equipment.Id == equipmentId).FirstOrDefaultAsync();

            foreach (StockItem item in eq.Stock)
            {
                if (item.StockId == original.StockId)
                {
                    StockItem        replace = StockItem.FromUpdate(original, update);
                    List <StockItem> stock   = eq.Stock;
                    stock[stock.IndexOf(item)] = replace;

                    await _equipment.ReplaceOneAsync(equipment => equipment.Id == equipmentId, Equipment.FromUpdateStock(eq, stock));

                    break;
                }
            }
        }
示例#3
0
 protected async override Task OnInitializedAsync()
 {
     StockItem = await Http.GetJsonAsync <StockItemUpdate>($"api/StockItem/{StockItemId}");
 }
        public async Task <IActionResult> Update([FromHeader] string authToken, string stockId, StockItemUpdate update)
        {
            if (!await _authenticationService.CheckAccess(authToken, "equipmentMgr"))
            {
                return(Unauthorized());
            }

            StockItem item = await _stockItemService.Get(stockId);

            if (item == null)
            {
                return(NotFound());
            }

            Equipment eq = await _equipmentService.GetFromStockId(stockId);

            _stockItemService.Update(eq.Id, item, update);

            await _logService.Create(new Log(
                                         null,
                                         AuthenticationHelpers.GetUserIdFromToken(authToken),
                                         DateTime.UtcNow,
                                         "StockItem modified.",
                                         "equipment",
                                         eq.Id,
                                         JsonSerializer.Serialize(StockItem.FromUpdate(item, update))
                                         ));

            return(Ok());
        }