public XHRResponse <_Receipt> Update(string userId, _ReceiptUpdate data) { XHRResponse <_Receipt> result = new XHRResponse <_Receipt>(); try { Receipt receipt = _receiptRepository.GetById(data.ReceiptId); ThrowExceptionIfIsInvalidReceipt(receipt, userId); receipt.TransactionDate = data.TransactionDate; receipt.Amount = data.Amount; receipt.CategoryId = data.CategoryId; receipt.Title = data.Title; receipt.PaymentId = data.PaymentId; receipt.Description = data.Description; _receiptRepository.Update(receipt); _receiptRepository.Save(); _receiptRepository.Load(receipt, nameof(Category)); _receiptRepository.Load(receipt, nameof(Payment)); result.Data = Mapper.Map <_Receipt>(receipt); result.Succeeded = true; } catch (Exception ex) { result.Message = "Unable to update receipt."; result.Succeeded = false; } return(result); }
public IActionResult Put(_ReceiptUpdate data) { return(Ok(_receiptService.Update(UserId, data))); }