public string GenerateSalesOnXML() { var sales = GetAllSales(); if (sales == null || !sales.Any()) { throw new HttpStatusException($"No hay ventas disponibles. Favor revisar la fuente de datos.", HttpStatusCode.Forbidden); } var salesRoot = new SalesRoot() { Sales = new Sales() { Sale = sales.ToList() } }; var xml = SerializerHelper.ObjectToXml(salesRoot); var file = Path.Combine(_appSettings.Value.XmlPath, $"{Guid.NewGuid().ToString().Replace("-", string.Empty)}.xml"); File.WriteAllText(file, xml); return(file); }
public void PersistSalesFromXML(SalesRoot salesRoot) { IList <SaleSummary> saleSummariesList = new List <SaleSummary>(); salesRoot?.Sales?.Sale?.ForEach(x => { saleSummariesList.Add(_mapper.Map <SaleSummary>(x)); }); _appDbContext.SaleSummaries.AddRange(saleSummariesList); _appDbContext.SaveChanges(); }