public static RestockNotices FromEmail(MailMessage email) { if (email is null) { throw new ArgumentNullException(nameof(email)); } if (email.Subject != "Shipment Received") { throw new ArgumentNullException($"Wrong email type: {email.Subject}"); } MatchCollection myCollection = myRegEx.Matches(email.Body); Match myCollection2 = myRegEx2.Match(email.Body); RestockNotices notice = new RestockNotices { //ProductID = int.Parse(myCollection[0].Groups[1].Value), //ProductName = myCollection[1].Groups[1].Value, //Quantity = int.Parse(myCollection[2].Groups[1].Value), Supplier = myCollection2.Groups[1].Value }; MatchCollection myMatchCollection = myRegEx.Matches(email.Body); List <RestockDetails> RestockDetailsList = new List <RestockDetails>(); foreach (Match a in myMatchCollection) { RestockDetails myDetails = new RestockDetails(a.Value); RestockDetailsList.Add(myDetails); } notice.RestockDetails = RestockDetailsList; return(notice); }
public static RestockNotices FromEmail(MailMessage email) { if (email is null) { throw new ArgumentNullException(nameof(email)); } if (email.Subject != "Shipment Received") { throw new ArgumentNullException($"Wrong email type: {email.Subject}"); } MatchCollection myCollection = rxproductItems.Matches(email.Body); Match myCollection2 = rxFullDetails.Match(email.Body); RestockNotices notice = new RestockNotices { Supplier = myCollection2.Groups[1].Value }; MatchCollection myMatchCollection = rxproductItems.Matches(email.Body); List <RestockDetails> RestockDetailsList = new List <RestockDetails>(); foreach (Match a in myMatchCollection) { RestockDetails myDetails = new RestockDetails(a.Value); RestockDetailsList.Add(myDetails); } notice.RestockDetails = RestockDetailsList; return(notice); }