From d7182b19ab8cf999250c5d2f9d8ffb25717f29b4 Mon Sep 17 00:00:00 2001 From: Irma Date: Mon, 4 Sep 2023 12:28:23 +0200 Subject: [PATCH] added large file --- SynonymsAPI/Services/badClass.cs | 66 +++++++++++++++++++++ Test/bin/Debug/net6.0/nunit_random_seed.tmp | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/SynonymsAPI/Services/badClass.cs b/SynonymsAPI/Services/badClass.cs index efc6ad2..ff47853 100644 --- a/SynonymsAPI/Services/badClass.cs +++ b/SynonymsAPI/Services/badClass.cs @@ -1797,6 +1797,72 @@ public virtual int ImportNewsletterSubscribersFromTxt(Stream stream) return count; } +public virtual int ImportNewsletterSubscribersFromTxt2(Stream stream) + { + var count = 0; + using (var reader = new StreamReader(stream)) + { + while (!reader.EndOfStream) + { + var line = reader.ReadLine(); + if (string.IsNullOrWhiteSpace(line)) + continue; + var tmp = line.Split(','); + + string email; + var isActive = true; + var storeId = _storeContext.CurrentStore.Id; + //parse + if (tmp.Length == 1) + { + //"email" only + email = tmp[0].Trim(); + } + else if (tmp.Length == 2) + { + //"email" and "active" fields specified + email = tmp[0].Trim(); + isActive = bool.Parse(tmp[1].Trim()); + } + else if (tmp.Length == 3) + { + //"email" and "active" and "storeId" fields specified + email = tmp[0].Trim(); + isActive = bool.Parse(tmp[1].Trim()); + storeId = int.Parse(tmp[2].Trim()); + } + else + throw new NopException("Wrong file format"); + + //import + var subscription = _newsLetterSubscriptionService.GetNewsLetterSubscriptionByEmailAndStoreId(email, storeId); + if (subscription != null) + { + subscription.Email = email; + subscription.Active = isActive; + _newsLetterSubscriptionService.UpdateNewsLetterSubscription(subscription); + } + else + { + subscription = new NewsLetterSubscription + { + Active = isActive, + CreatedOnUtc = DateTime.UtcNow, + Email = email, + StoreId = storeId, + NewsLetterSubscriptionGuid = Guid.NewGuid() + }; + _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription); + } + + count++; + } + } + + return count; + } + + /// /// Import states from TXT file /// diff --git a/Test/bin/Debug/net6.0/nunit_random_seed.tmp b/Test/bin/Debug/net6.0/nunit_random_seed.tmp index e9069ca..d0a3572 100644 --- a/Test/bin/Debug/net6.0/nunit_random_seed.tmp +++ b/Test/bin/Debug/net6.0/nunit_random_seed.tmp @@ -1 +1 @@ -1030685833 \ No newline at end of file +1743653074 \ No newline at end of file