public async Task <Boolean> CanShowCosteoAsync(int customerID, int productID) { Stopwatch timespan = Stopwatch.StartNew(); Boolean result = false; try { CustomerProduct customerProduct = await db.CustomerProducts .Where(t => t.CustomerID == customerID) .Where(p => p.ProductID == productID).FirstOrDefaultAsync(); if (customerProduct != null) { result = customerProduct.CalculationDetails; } timespan.Stop(); log.TraceApi("SQL Database", "CustomerProductRepository.CanShowCosteoAsync", timespan.Elapsed, "customerID={0}", customerID); return(result); } catch (Exception e) { log.Error(e, "Error in CustomerProductRepository.CanShowCosteoAsync(customerID={0})", customerID); throw; } }
public void AddAllCustomersToProduct(int productID) { var customers = this.FindCustomerNoAssignedToProduct(productID); foreach (Customer c in customers) { CustomerProduct cp = new CustomerProduct { CustomerID = c.CustomerID, ProductID = productID, CalculationDetails = c.IsSpot //si es Spot visualiza el Costeo }; this.Create(cp); } }
public void AddAllProductsToCustomer(int customerID, bool calculationDetails) { var products = this.FindProductsAvailableByCustomer(customerID); foreach (Product p in products) { CustomerProduct cp = new CustomerProduct { CustomerID = customerID, ProductID = p.ProductID, CalculationDetails = calculationDetails }; this.Create(cp); } }
public async Task CreateAsync(CustomerProduct customerProductToAdd) { Stopwatch timespan = Stopwatch.StartNew(); try { db.CustomerProducts.Add(customerProductToAdd); await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "CustomerProductRepository.CreateAsync", timespan.Elapsed, "customerProductToAdd={0}", customerProductToAdd); } catch (Exception e) { log.Error(e, "Error in CustomerProductRepository.CreateAsync(customerProductToAdd={0})", customerProductToAdd); throw; } }
public async Task UpdateAsync(CustomerProduct customerProductToSave) { Stopwatch timespan = Stopwatch.StartNew(); try { db.Entry(customerProductToSave).State = EntityState.Modified; await db.SaveChangesAsync(); timespan.Stop(); log.TraceApi("SQL Database", "CustomerProductRepository.Update", timespan.Elapsed, "customerProductToSave={0}", customerProductToSave); } catch (Exception e) { log.Error(e, "Error in CustomerProductRepository.Update(customerProductToSave={0})", customerProductToSave); throw; } }
public void Delete(int customerProductID) { Stopwatch timespan = Stopwatch.StartNew(); try { CustomerProduct customerProduct = db.CustomerProducts.Find(customerProductID); db.CustomerProducts.Remove(customerProduct); db.SaveChanges(); timespan.Stop(); log.TraceApi("SQL Database", "CustomerProductRepository.Delete", timespan.Elapsed, "customerProductID={0}", customerProductID); } catch (Exception e) { log.Error(e, "Error in CustomerProductRepository.Delete(customerProductID={0})", customerProductID); throw; } }