public MemoryStream SaveToXML(string filter) { string db = ConfigurationManager.AppSettings["DBConnectionString"]; ContactsDBOperator dBOperator = new ContactsDBOperator(db); List <Contact> contacts = (filter == "")?dBOperator.GetAll():ContactsSearch(filter); //string file = ConfigurationManager.AppSettings["tempfilePath"]; //string filepath = AppDomain.CurrentDomain.BaseDirectory + file; using (ExcelPackage package = new ExcelPackage()) { var newworksheet = package.Workbook.Worksheets.Add("test"); newworksheet.Cells["A1"].LoadFromCollection(contacts, true); var stream = new MemoryStream(package.GetAsByteArray()); return(stream); //string filepath = "C:\\Users\\anotfullina\\Documents\\GitHub\\learning\\FinalService\\temp\\contacts1.xlsx"; //FileInfo fi = new FileInfo(filepath); //package.SaveAs(fi); } //return "temp\\contacts.xls"; }
public string GetAllContacts() { Logger.Log.Info($"GetAllContacts called"); string db = ConfigurationManager.AppSettings["DBConnectionString"]; ContactsDBOperator dBOperator = new ContactsDBOperator(db); List <Contact> contacts = dBOperator.GetAll(); if (contacts == null) { Logger.Log.Info($"Contacts list is empty"); throw new FaultException <int>(0, $"Список контактов пуст"); } else { JsonSerializerSettings settings = new JsonSerializerSettings(); settings.DateFormatString = "d MMMM, yyyy"; string responce = JsonConvert.SerializeObject(contacts, settings); Logger.Log.Info($"GetAllContacts return {contacts?.Count} contacts"); return(responce); } }