Пример #1
0
        public List <ContactModel> LoadContactsFromXlsxFilePath(int businessId, string inputFilePath)
        {
            ExcelDataHandler excelDataHandler = new ExcelDataHandler();

            //string outputFile = @"C:\Users\user\OneDrive\Programming studies\Tomedia Web Team\AutoWhatsapp\03 - Business Logic Layer\CsvFiles\1.josn";
            return(ExcelDataHandler.UsingExcelDataReader(businessId, inputFilePath));
        }
Пример #2
0
        public List <ContactModel> LoadContactsFromXlsxFile(int businessId, IFormFile contactsFile)
        {
            string extension            = Path.GetExtension(contactsFile.FileName);
            string contactsBookFileName = Guid.NewGuid() + extension;

            BusinessModel businessToAddContactsBook = new BusinessModel(DB.Businesses.SingleOrDefault(p => p.BusinessId == businessId));

            businessToAddContactsBook.ContactsBookFileName = contactsBookFileName;

            using (FileStream fileStream = File.Create("ExcelFiles/" + contactsBookFileName))
            {
                contactsFile.CopyTo(fileStream);
            }

            ExcelDataHandler    excelDataHandler = new ExcelDataHandler();
            List <ContactModel> contacts         = ExcelDataHandler.UsingExcelDataReader(businessId, "ExcelFiles/" + contactsBookFileName);

            foreach (var item in contacts)
            {
                if (item.ContactPhone.Contains(":::"))
                {
                    int sliceIndex = item.ContactPhone.IndexOf(":");
                    item.ContactPhone = item.ContactPhone.Substring(0, sliceIndex);
                }
                DB.Contacts.Add(item.ConvertToContact());
            }
            DB.SaveChanges();
            return(contacts);
        }