예제 #1
0
        public static int CsvImport(byte[] data, int clubId)
        {
            int importCount = 0;

            using (StreamReader stream = new StreamReader(new MemoryStream(data), Encoding.Default))
            {
                int counter = 0;
                while (stream.Peek() >= 0)
                {
                    string line = stream.ReadLine();

                    if (counter > 0)
                    {
                        List <string> lineData = line.Split(',').ToList();
                        if (lineData.Count > 58)
                        {
                            var contact = new Contact()
                            {
                                ClubId    = clubId,
                                FirstName = lineData[1].Trim('"'),
                                LastName  = lineData[3].Trim('"'),
                                Email     = lineData[57].Trim('"')
                            };

                            //Check if email is valid, then save the contact...
                            if (EmailHelper.IsValidEmail(contact.Email))
                            {
                                ContactDAL.SaveContact(contact, clubId);
                                importCount++;
                            }
                        }
                    }
                    counter++;
                }
            }

            return(importCount);
        }
예제 #2
0
 public static void SaveContact(Contact contact, int clubId)
 {
     contact.ClubId = clubId;
     ContactDAL.SaveContact(contact, clubId);
 }