public async Task <bool> validate(RentItemInput item) { var laptop = (await _laptopRepository.findByIdAsync(item.LaptopId)).Value; if (laptop.StockAmount > 0 && laptop.StockAmount >= item.Quantity) { laptop.StockAmount -= 1; await _laptopRepository.update(laptop); } else { return(false); } return(true); }
public async Task refund(int id) { var rent = await _rentRepository.findByIdAsync(id); if (rent.Status != "devolvido") { foreach (var item in rent.Items) { var laptop = (await _laptopRepository.findByIdAsync(item.laptopId)).Value; laptop.StockAmount += item.quantity; await _laptopRepository.update(laptop); } rent.Status = "devolvido"; await _rentRepository.update(rent); } }
public async Task update(LaptopInput laptop) { await _laptopRepository.update(new Laptop(laptop)); }