public async Task <IActionResult> AddReceiptItem(NewReceiptItem newreceipt) { bool isAdded = await _eventService.AddReceiptItem(newreceipt); if (isAdded) { return(Ok(new { Status = "OK", Message = "Poprawnie dodano nową pozycje" })); } return(Ok(new { Status = "Exists", Message = "Już taka pozycja jest na paragonie" })); }
public async Task <bool> AddReceiptItem(NewReceiptItem receiptItem) { bool CheckExists(int participant, int amount, string name, double price) { int a = _context.ReceiptItems.Count(x => (x.ParticipantId == participant) && (x.Price == price) && (x.ProductName == name)); return(a == 0 ? false : true); } var a = await _context.Participants.FirstAsync(x => x.Id == receiptItem.Participant); if (CheckExists(receiptItem.Participant, receiptItem.Count, receiptItem.PositionName, receiptItem.Value)) { return(false); } _context.ReceiptItems.Add(new ReceiptItem() { Amount = receiptItem.Count, ParticipantId = receiptItem.Participant, Price = receiptItem.Value, ProductName = receiptItem.PositionName }); await _context.SaveChangesAsync(); return(true); }
public Task <bool> AddReceipt(NewReceiptItem item) { throw new NotImplementedException(); }