public async Task <IActionResult> ReplenishStorageLot(string id, [FromBody] StorageReplenishmentDTO data) { if (ModelState.IsValid) { try { await service.ReplenishStorageLot(id, data); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } } else { return(Conflict(ModelState)); } }
public async Task ReplenishStorageLot(string id, StorageReplenishmentDTO data) { var entity = await storageLotRepository.GetById(id); if (entity != null) { entity.SupplyDateTime = DateTime.UtcNow.AddDays(3); entity.LaptopsAmount += data.LaptopsAmount; await storageLotRepository.Update(entity); await saveChangesAsync(); var amount = await GetLaptopStorageAmount(entity.LaptopId); var laptop = await laptopRepository.GetById(entity.LaptopId); if (laptop != null) { laptop.IsAvailable = amount > 0; await laptopRepository.Update(laptop); await saveChangesAsync(); } } }