public FileImportResult ImportFromCSV(string data, DuplicateContactMode mode)
        {
            FileImportResult result = new FileImportResult();

            //get db
            EmailType emailType = dbManager.GetPreferredEmailTypeByAccountTypeNameEF(AccountTypeDB.TYPE_CSV_STRING);
            FaxType faxType = dbManager.GetPreferredFaxTypeByAccountTypeNameEF(AccountTypeDB.TYPE_CSV_STRING);
            Account account = dbManager.GetCSVAccountEF();
            string accTypeName = AccountTypeDB.TYPE_CSV_STRING;

            //split stream from file
            string[] contactSplits = data.Split(new string[] { "\r", "\r\n", "\n" }, StringSplitOptions.None);
            var CSVHeader = contactSplits[0].Split(new char[] { ',' }).ToList().Select(n => GroupDB.TrimSpace(GroupDB.RemoveControlChars(n)).ToLower()).ToList();

            //define var
            int size = contactSplits.Count();
            List<CMData.Contact> listContact = new List<CMData.Contact>();
            //header index
            int IdFirstName = -1;
            int IdLastName = -1;
            int IdMidName = -1;
            int IdFullName = -1;
            int IdFax = -1;
            int IdEmail = -1;

            //check header
            //step 1: first last mid
            IdFirstName = CSVHeader.FindIndex(n => n.Equals("first name") || n.Equals("first") || n.Equals("first_name"));
            IdLastName = CSVHeader.FindIndex(n => n.Equals("last name") || n.Equals("last") || n.Equals("last_name"));
            IdMidName = CSVHeader.FindIndex(n => n.Equals("middle name") || n.Equals("middle") || n.Equals("middle_name"));

            //step 2: fullname
            if(IdFirstName < 0 && IdLastName < 0 && IdMidName < 0)
            {
                IdFullName = CSVHeader.FindIndex(n => n.Equals("full name") || n.Equals("name") || n.Equals("full_name") || n.Equals("fullname"));
            }

            //step3: Email & Fax
            if(IdFirstName >= 0 || IdLastName >= 0 || IdMidName >= 0 || IdFullName >= 0)
            {
                IdEmail = CSVHeader.FindIndex(n => n.Equals("email address") || n.Equals("email_address") || n.Equals("e-mail_address") || n.Equals("e-mail") || n.Equals("email") || n.Equals("home email") || n.Equals("home_email") || n.Equals("work email") || n.Equals("work_email") || n.Equals("personal email") || n.Equals("personal_email"));
                IdFax = CSVHeader.FindIndex(n => n.Equals("fax number") || n.Equals("fax_number") || n.Equals("business fax") || n.Equals("business_fax") || n.Equals("fax") || n.Equals("home fax") || n.Equals("home_fax") || n.Equals("work fax") || n.Equals("work_fax"));
            }
            else
            {
                result.errorCode = FileImExportController.CODE_FILE_STRUCTURE_NOT_SUITABLE;
                return result;
            }

            //parse data fore each row // i=0 is headers row
            for (int i = 1; i < size; i++)
            {
                string bareData = contactSplits[i];
                var valueSplits = splitCSVLine(bareData);
                var maxColumnIndex = valueSplits.Count() - 1;

                if (valueSplits.Count() < 1)
                    continue;
                var valueFullName = String.Empty;
                var valueLastName = String.Empty;
                var valueFirstName = String.Empty;
                var valueMidName = String.Empty;
                var valueEmail = String.Empty;
                var valueFax = String.Empty;

                //parse

                //get full name or detail FLM name
                if (IdFullName >= 0)
                {
                    if(IdFullName > maxColumnIndex)
                    {
                        continue;
                    }
                    valueFullName = valueSplits.ElementAt(IdFullName);

                    if (string.IsNullOrEmpty(valueFullName)) //specify full name, but it's empty
                        continue;

                    var cv = new ContactView();
                    cv.Name = valueFullName;
                    cv.SplitFirstLastMidFromFullName(ContactDB.NAME_ORDER_FIRST_LAST_MID);
                    valueFirstName = cv.FirstName;
                    valueLastName = cv.LastName;
                    valueMidName = cv.MiddleName;
                }
                else
                {   if(IdFirstName >= 0 && IdFirstName <= maxColumnIndex)
                        valueFirstName = valueSplits.ElementAt(IdFirstName);

                    if (IdLastName >= 0 && IdLastName <= maxColumnIndex)
                        valueLastName = valueSplits.ElementAt(IdLastName);

                    if (IdMidName >= 0 && IdMidName <= maxColumnIndex)
                        valueMidName = valueSplits.ElementAt(IdMidName);
                }

                //get Fax, Email
                if (IdEmail >= 0 && IdEmail <= maxColumnIndex)
                    valueEmail = valueSplits.ElementAt(IdEmail);

                if (IdFax >= 0 && IdFax <= maxColumnIndex)
                    valueFax = valueSplits.ElementAt(IdFax);

                //check to skip row when specify FLM name, but they're empty
                if (String.IsNullOrEmpty(valueFirstName) && String.IsNullOrEmpty(valueLastName) && String.IsNullOrEmpty(valueMidName))
                {
                    continue;
                }

                //Mapping Email / Fax
                List<Email> listEmail = new List<Email>();
                if (!String.IsNullOrEmpty(valueEmail))
                {
                    Email em = new Email();

                    em.Value = valueEmail;
                    em.EmailType = emailType;
                    em.EmailTypeId = emailType.Id;
                    listEmail.Add(em);
                }
                List<Fax> listFax = new List<Fax>();
                if (!String.IsNullOrEmpty(valueFax))
                {
                    Fax faxDB = new Fax();
                    faxDB.Value = valueFax;
                    faxDB.FaxType = faxType;
                    faxDB.FaxTypeId = faxType.Id;
                    listFax.Add(faxDB);
                }

                //Create Contact obj
                CMData.Contact contact;
                contact = new CMData.Contact();
                contact.AccountId = account.Id;
                contact.FirstName = valueFirstName;
                contact.LastName = valueLastName;
                contact.MiddleName = valueMidName;
                contact.Emails = listEmail;
                contact.Faxes = listFax;
                listContact.Add(contact);
            }

            //write to DB
            result = AddOrUpdateContact(listContact, accTypeName, mode);
            return result;
        }
        public void notifyPrinterContactList(PrinterContact c)
        {
            if (!flagSendToPrinter)
            {
                listContact_EF.Clear();
                listGroupName.Clear();
                contactJsons.Clear();
                //listContactPrinter.Clear();
                if (c != null && c.contacts.Count > 0)
                {
                    //listContactPrinter = c.contacts;
                    UC_AddressBook.CurrentPrinterContact = c;

                    foreach (ContactViewPrinter cp in c.contacts)
                    {
                        ContactView cv = new ContactView
                        {
                            Name = cp.Name,
                            EmailAddress = cp.EmailAddress,
                            Fax = cp.Fax,
                            Group = cp.Group,
                            Id = cp.Id,
                            ImportedFrom = cp.ImportedFrom
                        };
                        cv.SplitFirstLastMidFromFullName(ContactDB.NAME_ORDER_FIRST_MID_LAST);
                        listContact_EF.Add(cv);
                        if (!listGroupName.Contains(cp.Group) && !string.IsNullOrEmpty(cp.Group))
                        {
                            listGroupName.Add(cp.Group);
                        }
                    }
                }

                UC_AddressBook.CurrentPrinterContact.contacts = MyUtils.ConvertContactViewToContactViewPrinter(listContact_EF);

                currentPrinterMaxID = oldPrinterMaxID = GetMaxContactIdPrinter();

                printerError = null;
            }
            else
            {
                contactJsons.Clear();
                //listContact_EF.Clear();
                flagSendToPrinter = false;

                if (c != null && c.contacts.Count > 0)
                {
                    //var temp = new List<ContactView>();
                    //foreach (ContactView cw in listContact_EF)
                    //{
                    //    if (cw.Id > oldPrinterMaxID)
                    //    {
                    //        temp.Add(cw);
                    //    }
                    //}

                    //foreach (ContactView cc in temp)
                    //{
                    //    listContact_EF.Remove(cc);
                    //}

                    //foreach (ContactViewPrinter cp in c.contacts)
                    //{
                    //    ContactView cv = new ContactView
                    //    {
                    //        Name = cp.Name,
                    //        EmailAddress = cp.EmailAddress,
                    //        Fax = cp.Fax,
                    //        Group = cp.Group,
                    //        Id = cp.Id,
                    //        ImportedFrom = cp.ImportedFrom
                    //    };

                    //    cv.SplitFirstLastMidFromFullName(ContactDB.NAME_ORDER_FIRST_MID_LAST);

                    //    listContact_EF.Add(cv);

                    //    //if (cp.ContactAction == MyUtils.ADD)
                    //    //{
                    //    //    cv.Id = ++currentPrinterMaxID;
                    //    //    listContact_EF.Add(cv);
                    //    //}
                    //    //if (cp.ContactAction == MyUtils.DELETE)
                    //    //{
                    //    //    var found = listContact_EF.Where(x => x.Id == cp.Id).FirstOrDefault();
                    //    //    if (found != null)
                    //    //    {
                    //    //        listContact_EF.Remove(found);
                    //    //    }
                    //    //}
                    //    //if (cp.ContactAction == MyUtils.UPDATE)
                    //    //{
                    //    //    var found = listContact_EF.Where(x => x.Id == cp.Id).FirstOrDefault();
                    //    //    if (found != null)
                    //    //    {
                    //    //        listContact_EF.Remove(found);
                    //    //    }

                    //    //    listContact_EF.Add(cv);
                    //    //}
                    //    //if (!listGroupName.Contains(cp.Group) && !string.IsNullOrEmpty(cp.Group))
                    //    //{
                    //    //    listGroupName.Add(cp.Group);
                    //    //}
                    //}

                    var contact = c.contacts[0];
                    contact.SplitFirstLastMidFromFullName(ContactDB.NAME_ORDER_FIRST_MID_LAST);
                    contact.Id = ++currentPrinterMaxID;
                    listContact_EF.Add(contact);
                    if (!listGroupName.Contains(contact.Group) && !string.IsNullOrEmpty(contact.Group))
                    {
                        listGroupName.Add(contact.Group);
                    }

                    UC_AddressBook.CurrentPrinterContact.contacts = MyUtils.ConvertContactViewToContactViewPrinter(listContact_EF);

                    currentPrinterMaxID = oldPrinterMaxID = GetMaxContactIdPrinter();
                }
            }

            DoRefreshListView();
        }