public async Task <bool> UpdateInvoice(InvoiceFilter invoiceFilter, InvoiceCreationDTO invoiceCreationDTO) { var entity = await dbContext.Invoices.FirstOrDefaultAsync(x => x.ActivityId.Equals(invoiceFilter.ActivityId) && x.UserId.Equals(invoiceFilter.UserId)); if (entity == null) { return(false); } mapper.Map(invoiceCreationDTO, entity); dbContext.Entry(entity).State = EntityState.Modified; await dbContext.SaveChangesAsync(); return(true); }
public async Task <Invoice> CreateInvoiceForUser(InvoiceCreationDTO invoice) { try { var entity = mapper.Map <Invoice>(invoice); dbContext.Add(entity); await dbContext.SaveChangesAsync(); return(entity); } catch (DbUpdateException) { return(null); } }