public async Task UpdateStorageLot(string id, StorageLotDTO data) { var entity = await storageLotRepository.GetById(id); if (entity != null) { entity.WarehouseAddress = data.WarehouseAddress; entity.LaptopsCostPerUnit = data.LaptopsCostPerUnit; if (!data.LaptopId.Equals(entity.LaptopId)) { entity.LaptopsAmount = 0; } entity.LaptopId = data.LaptopId; entity.DelivererId = data.DelivererId; 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(); } } }
public async Task SaveStorageLot(StorageLotDTO data) { var entity = new StorageLot { WarehouseAddress = data.WarehouseAddress, LaptopsCostPerUnit = data.LaptopsCostPerUnit, LaptopId = data.LaptopId, DelivererId = data.DelivererId, }; await storageLotRepository.Add(entity); await saveChangesAsync(); }
public async Task <IActionResult> UpdateStorageLot(string id, [FromBody] StorageLotDTO data) { if (ModelState.IsValid) { try { await service.UpdateStorageLot(id, data); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } } else { return(Conflict(ModelState)); } }