private void AddSalesToDB(IExcelDataReader excelReader, DateTime currentDate) { var salesTable = excelReader.AsDataSet().Tables["Sales"]; var locationName = (string)salesTable.Rows[1].ItemArray[1]; var currentLocation = GetOrCreateLocation(locationName); for (var i = 3; i < salesTable.Rows.Count; i++) { if (((string)salesTable.Rows[i].ItemArray[1]).Contains("Total sum")) { break; } var productName = (string)salesTable.Rows[i].ItemArray[1]; var quantity = (double)salesTable.Rows[i].ItemArray[2]; var pricePerUnit = (double)salesTable.Rows[i].ItemArray[3]; var currentProduct = GetOrCreateProduct(productName,pricePerUnit); Sale currentSale = new Sale { LocationId = currentLocation.Id, DateOfSale = currentDate, ProductId = currentProduct.Id, Quantity = (decimal) quantity, PricePerUnit = (decimal) pricePerUnit }; this.db.Sales.Add(currentSale); } this.db.SaveChanges(); }
//Tanya public bool Equals(Sale other) { if ((this.ProductId == other.ProductId) && (this.DateOfSale.Date == other.DateOfSale.Date) && (this.VendorId == other.VendorId)) { return true; } return false; }