Guest User

Untitled

a guest
Dec 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. [Route("{id}")]
  2. [HttpGet]
  3. public async Task<HttpResponseMessage> GetInvoiceById(int id)
  4. {
  5. var result = await _invoice_service.GetInvoiceById(id);
  6. if (result == null)
  7. return Request.CreateResponse(HttpStatusCode.NotFound);
  8.  
  9. return Request.CreateResponse(HttpStatusCode.OK, result);
  10. }
  11.  
  12. public async Task<Invoice> GetInvoiceById(int id)
  13. {
  14. return await _invoice_repo.GetInvoiceById(id);
  15.  
  16. }
  17.  
  18. namespace Accounting.Infrastructure.Repositories
  19. {
  20. public class InvoiceRepository : BaseRepository, IInvoiceRepository
  21. {
  22. private readonly IQueryable<Invoice> _dbSet;
  23.  
  24. public InvoiceRepository(IUnitOfWork unit_of_work) : base(unit_of_work)
  25. {
  26. _dbSet = unit_of_work.Set<Invoice>()
  27. .Include(m => m.Articles)
  28. }
  29.  
  30. public Task<Invoice> GetInvoiceById(int id)
  31. {
  32. return _dbSet.SingleOrDefaultAsync(m => m.id == id);
  33. }
  34.  
  35. public void Insert(Invoice invoice)
  36. {
  37. _unitOfWork.Set<Invoice>().Add(invoice);
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment