Exemplo n.º 1
0
        async public Task <ServiceResponse <GetReceiptDto> > UpdateReceipt(UpdateReceiptDto newReceipt)
        {
            ServiceResponse <GetReceiptDto> serviceResponse = new ServiceResponse <GetReceiptDto>();

            try
            {
                var receipt = await _context.Receipts.Include(x => x.ItemPrices).ThenInclude(xs => xs.Item).FirstOrDefaultAsync(x => x.Id == newReceipt.Id && x.User.Id == GetUserId());

                if (receipt != null)
                {
                    receipt.Shop = newReceipt.Shop;
                    _context.Receipts.Update(receipt);
                    await _context.SaveChangesAsync();

                    serviceResponse.Data = _mapper.Map <GetReceiptDto>(receipt);
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Receipt not found.";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateReceipt(UpdateReceiptDto newReceipt)
        {
            ServiceResponse <GetReceiptDto> response = await _receiptService.UpdateReceipt(newReceipt);

            if (response.Data == null)
            {
                return(NotFound(response));
            }
            else
            {
                return(Ok(response));
            }
        }