public async Task <IActionResult> AddOrUpdate(MrrCustomer parameter) { var data = await _service.AddOrUpdate(parameter).ConfigureAwait(false); return(Ok(data)); }
public async Task <dynamic> AddOrUpdate(MrrCustomer data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } var id = data.MrrCustomerId; if (data.QualityEngineerClosedId is null) { data.MrrClosedTimestamp = null; } else { data.MrrClosedTimestamp ??= DateTime.Now; } data.DateModified = DateTime.Now; var entity = _context.MrrCustomers.Update(data); await _context.SaveChangesAsync().ConfigureAwait(false); var mrrCustomer = await GetMrrCustomer(entity.Entity.MrrCustomerId) .ConfigureAwait(false); // send on create send to quality team if (id == 0) { await SendReport(mrrCustomer).ConfigureAwait(false); } // send on create send to logistics team if ( id > 0 && mrrCustomer.MrrClosedTimestamp is not null && mrrCustomer.LogisticsReturnPo is null ) { await SendReport(mrrCustomer).ConfigureAwait(false); } // send on create send to finance team if ( id > 0 && mrrCustomer.MrrClosedTimestamp is not null && mrrCustomer.LogisticsReturnPo is not null && mrrCustomer.FinanceCreditMemo is null ) { await SendReport(mrrCustomer).ConfigureAwait(false); } // send to every body if ( id > 0 && mrrCustomer.MrrClosedTimestamp is not null && mrrCustomer.LogisticsReturnPo is not null && mrrCustomer.FinanceCreditMemo is not null ) { await SendReport(mrrCustomer).ConfigureAwait(false); } return(mrrCustomer); }