public async Task DeleteAsync(int productQuoteID) { Stopwatch timespan = Stopwatch.StartNew(); try { if (HasCustomerOrder(productQuoteID)) { throw new ProductQuoteAppException("La Cotizacion no puede ser eliminada porque tiene una OC asociada."); } ProductQuote productQuote = await db.ProductQuotes.FindAsync(productQuoteID); db.ProductQuotes.Remove(productQuote); await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "ProductQuoteRepository.DeleteAsync", timespan.Elapsed, "productQuoteID={0}", productQuoteID); } catch (Exception e) { log.Error(e, "Error in ProductQuoteRepository.DeleteAsync(productQuoteID={0})", productQuoteID); throw; } }
public async Task UpdateAsync(ProductQuote productQuoteToSave) { Stopwatch timespan = Stopwatch.StartNew(); try { db.Entry(productQuoteToSave).State = EntityState.Modified; await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "ProductQuoteRepository.UpdateAsync", timespan.Elapsed, "productQuoteToSave={0}", productQuoteToSave); } catch (Exception e) { log.Error(e, "Error in ProductQuoteRepository.UpdateAsync(productQuoteToSave={0})", productQuoteToSave); throw; } }
public async Task UpdateDateSentAsync(ProductQuote productQuoteToSave) { Stopwatch timespan = Stopwatch.StartNew(); try { db.ProductQuotes.Attach(productQuoteToSave); db.Entry(productQuoteToSave).Property(p => p.DateSent).IsModified = true; await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "ProductQuoteRepository.UpdateDateSentAsync", timespan.Elapsed, "productQuoteToSave={0}", productQuoteToSave); } catch (Exception e) { log.Error(e, "Error in ProductQuoteRepository.UpdateDateSentAsync(productQuoteToSave={0})", productQuoteToSave); throw; } }
public void UpdatePdf(ProductQuote productQuoteToSave) { Stopwatch timespan = Stopwatch.StartNew(); try { db.Entry(productQuoteToSave).Property(p => p.ProductQuotePDF).IsModified = true; db.Entry(productQuoteToSave).Property(p => p.ProductQuoteSmallPDF).IsModified = true; db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "ProductQuoteRepository.UpdatePdf", timespan.Elapsed, "productQuoteToSave={0}", productQuoteToSave); } catch (Exception e) { log.Error(e, "Error in ProductQuoteRepository.UpdatePdf(productQuoteToSave={0})", productQuoteToSave); throw; } }
public async Task CreateAsync(ProductQuote productQuoteToAdd) { Stopwatch timespan = Stopwatch.StartNew(); try { productQuoteToAdd.DateQuote = DateTime.Now; db.ProductQuotes.Add(productQuoteToAdd); await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "ProductQuoteRepository.CreateAsync", timespan.Elapsed, "productQuoteToAdd={0}", productQuoteToAdd); } catch (Exception e) { log.Error(e, "Error in ProductQuoteRepository.CreateAsync(productQuoteToAdd={0})", productQuoteToAdd); throw; } }
public async Task <ProductQuote> FindProductQuotesByIDUserIDAsync(int productQuoteID, string userId) { ProductQuote productQuote = null; Stopwatch timespan = Stopwatch.StartNew(); try { productQuote = await db.ProductQuotes .Where(t => t.ProductQuoteID == productQuoteID) .Where(t => t.UserId == userId) .OrderByDescending(t => t.DateQuote).SingleOrDefaultAsync(); timespan.Stop(); log.TraceApi("SQL Database", "ProductQuoteRepository.FindProductQuotesByIDUserIDAsync", timespan.Elapsed, "productQuoteID={0}", productQuoteID); } catch (Exception e) { log.Error(e, "Error in ProductQuoteRepository.FindProductQuotesByIDUserIDAsync(productQuoteID={0})", productQuoteID); throw; } return(productQuote); }