public async Task <bool> UpdateBatch(ICollection <Product> products) { try { foreach (Product product in products) { await Update(product); } try { await _dbContext.SaveChangesAsync(); } catch (Exception) { throw; } } catch (Exception ex) { throw ex; } return(true); }
public async Task <bool> UpdateBatch(long eventId, ICollection <HelixEventProduct> eventProducts) { bool isDeleted = false; try { isDeleted = DeleteByEventId(eventId); } catch (Exception ex) { /** In real application, * Encapsulate the details in the layer-specific log files for further troubleshooting * and wrap it in user-friendly manner **/ throw ex; } if (isDeleted) { try { foreach (HelixEventProduct eventProduct in eventProducts) { await _dbContext.HelixEventProducts.AddAsync(eventProduct); } await _dbContext.SaveChangesAsync(); } catch (Exception ex) { /// Logging details into DB or S3 /// Which eventId, etc /// Encapsulate the exception details etc throw ex; } } else { /** In real application, * Encapsulate the details in the layer-specific log files for further troubleshooting * and wrap it in user-friendly manner **/ throw new Exception("Could not delete the previously updated products for the event!!!"); } return(true); }