/// <summary> /// 更新预占库存 /// </summary> /// <param name="obj">预占库存实体</param> /// <param name="operation">操作标识:0:增加预占;1:减少预占</param> /// <returns></returns> public bool UpdateInventoryAssignedQty(UpdateInventoryItemDto obj) { InventoryItem item = repository.GetInventoryItemBySkuId(obj.WarehouseId, obj.SkuId); int? assignedQtyBefore = item.AssignedQty; item.AssignedQty = obj.Action == 0 ? (item.AssignedQty + obj.AssignedQty) : (item.AssignedQty - obj.AssignedQty); item.UpdateTime = DateTime.Now; if (repository.UpdateInventoryItem(item) > 0) { InventoryOperationLog log = new InventoryOperationLog { WarehouseId = obj.WarehouseId, SkuId = obj.SkuId, Action = obj.Action, OperationType = obj.OperationType, AvailableQtyAfter = 0, AvailableQtyBefore = 0, AvailableQtyChange = 0, AssignedQtyBefore = assignedQtyBefore, AssignedQtyChange = obj.AssignedQty, AssignedQtyAfter = item.AssignedQty, OrderId = obj.RelationOrderId, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, UpdateUserId = obj.UpdateUserId }; if (logRepository.InsertInventoryItem(log) > 0) { return(true); } } return(false); }
public InventoryItem PostInventoryItem(AddInventoryItemDto itemDto) { ItemImage img = inventoryRepository.GetItemImage(itemDto.ItemImageId); ItemType type = inventoryRepository.GetItemType(itemDto.ItemTypeId); /* * Check if item already exists in Inventory * Update amount if so. */ InventoryItem existingItem = this.inventoryRepository.GetInventoryItemByColor(img); if (existingItem != null) { Console.WriteLine("Existing item was found, we're going to update its amount"); var updateItem = new UpdateInventoryItemDto( existingItem.ItemImage.ItemImageId, existingItem.ItemType.ItemTypeId, existingItem.Amount + itemDto.Amount ); return(this.UpdateInventoryItem(updateItem, existingItem.InventoryItemId)); } else { Console.WriteLine("Existing item was not found, we're creating a new one"); } InventoryItem item = new InventoryItem(itemDto.AuthId, img, type, itemDto.Amount); return(this.inventoryRepository.PostInventoryItem(item)); }
public InventoryItem UpdateInventoryItem(UpdateInventoryItemDto itemDto, int itemid) { InventoryItem item = this.inventoryRepository.GetInventoryItem(itemid); ItemImage img = this.inventoryRepository.GetItemImage(itemDto.ItemImageId); ItemType type = this.inventoryRepository.GetItemType(itemDto.ItemTypeId); if (item == null) { return(null); } if (img == null) { img = item.ItemImage; } if (type == null) { type = item.ItemType; } item.Amount = itemDto.Amount; item.ItemType = type; item.ItemImage = img; if (item.Amount == 0) { this.DeleteInventoryItem(itemid); return(item); } return(this.inventoryRepository.UpdateInventoryItem(item, itemid)); }
public async Task <ActionResult <InventoryItemDto> > Put(UpdateInventoryItemDto dto) { var inventoryItem = await dataContext.Set <InventoryItem>().FirstOrDefaultAsync(x => x.Id == dto.Id); if (inventoryItem == null) { ModelState.AddModelError(nameof(UpdateInventoryItemDto.Id), "No such inventory item"); return(NotFound(new ValidationProblemDetails(ModelState))); } mapper.Map(dto, inventoryItem); await dataContext.SaveChangesAsync(); return(Ok(mapper.Map <InventoryItemDto>(inventoryItem))); }
public async Task Update(int id, UpdateInventoryItemDto updateInventoryItemDto) { var itemToUpdate = await _repository.GetById(id); if (updateInventoryItemDto == null || itemToUpdate == null) { throw new ArgumentNullException(); } _mapper.Map(updateInventoryItemDto, itemToUpdate); await _repository.Update(itemToUpdate); if (updateInventoryItemDto.Tags != null) { foreach (var inventoryItemTag in updateInventoryItemDto.Tags) { if (await _inventoryItemTagsRepository.FindByInventoryItemIdAndTagId(itemToUpdate.Id, inventoryItemTag.Id) is null) { await _inventoryItemTagsRepository.Create(new InventoryItemTag() { InventoryItemId = itemToUpdate.Id, TagId = inventoryItemTag.Id }); } } } var allCurrentItemTags = await _inventoryItemTagsRepository.FindAllByInventoryItemId(itemToUpdate.Id); foreach (var currentItemTag in allCurrentItemTags) { var tagDto = _mapper.Map <TagDto>(await _tagRepository.GetById(currentItemTag.TagId)); if (!updateInventoryItemDto.Tags.Any(x => x.Id == tagDto.Id)) { await _inventoryItemTagsRepository.Delete(await _inventoryItemTagsRepository.GetById(currentItemTag.Id)); } } }
public void UpdateInventoryItemTest() { context.SeedPlayer(new Player { AuthId = "admin", Experience = 123, Landmarks = null, PlayerName = "Admin" }); InventoryItem item = inventoryService.PostInventoryItem(new AddInventoryItemDto { AuthId = "admin", InventoryItemId = 1, ItemImageId = 1, ItemTypeId = 1, Amount = 1 }); UpdateInventoryItemDto updateItem = new UpdateInventoryItemDto { ItemTypeId = 2, ItemImageId = 2, Amount = 2 }; InventoryItem updatedItem = inventoryService.UpdateInventoryItem(updateItem, 1); updatedItem.ItemImage.ItemImageId.Should().Be(2); updatedItem.ItemType.ItemTypeId.Should().Be(2); updatedItem.Amount.Should().Be(2); }
public async Task <IActionResult> Put(int id, UpdateInventoryItemDto updateInventoryItemDto) { await _inventoryItemService.Update(id, updateInventoryItemDto); return(NoContent()); }
public InventoryItem UpdateInventoryItem([FromBody] UpdateInventoryItemDto item, int itemid) { return(this.inventoryService.UpdateInventoryItem(item, itemid)); }