public async Task <InvoiceCategoryDto> SaveAsync(Guid orgId, InvoiceCategoryDto dto) { if (orgId == null || orgId == Guid.Empty) { throw new ArgumentNullException("orgId", "Org id is missing"); } InvoiceCategory category = _mapper.Map <InvoiceCategory>(dto); if (category.Id == Guid.Empty) { category.OrgId = orgId; category.DateCreated = DateTime.UtcNow; category.DateModified = null; await _context.InvoiceCategories.AddAsync(category); } else { category.OrgId = orgId; category.DateModified = DateTime.UtcNow; _context.InvoiceCategories.Update(category); } await _context.SaveChangesAsync(); dto = _mapper.Map <InvoiceCategoryDto>(category); return(dto); }
public async Task <InvoiceCategoryDto> GetByIdAsync(Guid id) { InvoiceCategoryDto category = await _context.InvoiceCategories .ProjectTo <InvoiceCategoryDto>(_mapper.ConfigurationProvider) .AsNoTracking() .SingleOrDefaultAsync(pc => pc.Id == id); if (category != null) { return(category); } throw new KeyNotFoundException("Invoice category not found"); }