public async Task AnalyzeFile(FileInfo file) { try{ var lot = new Lot.Lot(_lotconfiguration, file.Name); using (System.IO.StreamReader sr = _streamReader.GetStreamReader(file.FullName)) { string s; int currentLine = 0; while ((s = sr.ReadLine()) != null) { //We need to abstract this information to handle better and log if some information is not correct. try{ lot.AddData(s); }catch (System.Exception e) { _logger.Warning("Problem in line " + currentLine + " in the lot " + file.Name + " : " + e.Message); } currentLine++; } } await _reportGeneratorService.GenerateReport(lot); }catch (IOException e) { _logger.Warning("Error ocurred when opening lot:" + e.Message); throw e; } }
public void Update(Lot.Lot aggRoot) { var existingLot = Lots.FirstOrDefault(l => l.IsEqualTo(aggRoot)); if (existingLot != null) { Lots[Lots.IndexOf(existingLot)] = aggRoot; } }
public async Task GenerateReport(Lot.Lot lot) { try{ var content = new StringBuilder(); // Get the customers quantity in the lot content.AppendLine(lot.customers.Count + ";"); //Get the salespersons quantity in the lot content.AppendLine(lot.salespersons.Count + ";"); if (lot.sales.Count > 0) { //Get the mostexpansive sale descending by the sum of the prices x quantity to get the total of each sale, getting the most expansive one var mostExpansiveSale = lot.sales.OrderByDescending(x => x.items.Sum(i => i.price * i.quantity)).Take(1).First(); content.AppendLine(mostExpansiveSale.id + ";"); //Calculate the results to get the salesperson with minimun results decimal worstResult = 0M; Salesperson.Salesperson worstSalesPerson = null; foreach (Salesperson.Salesperson salesperson in lot.salespersons) { var salespersonSales = lot.sales.FindAll(sale => sale.salesManName == salesperson.Name); var salespersonResult = salespersonSales.Sum(sale => sale.items.Sum(i => i.price * i.quantity)); if (worstSalesPerson == null || salespersonResult < worstResult) { worstResult = salespersonResult; worstSalesPerson = salesperson; } } content.AppendLine(worstSalesPerson.Name + ";" + worstSalesPerson.CPF + ";" + worstSalesPerson.Salary + ";"); } await _fileGenerator.GenerateFile(lot.name, content.ToString()); }catch (System.Exception e) { throw e; } }
public void Add(Lot.Lot aggRoot) { Lots.Add(aggRoot); }