Exemplo n.º 1
0
        public ActionResult FindTagPeople(string text, string tagname)
        {
            if (!tagname.HasValue())
                return Content("no tag");
            var csv = new CsvReader(new StringReader(text), false, '\t').ToList();

            if (!csv.Any())
                return Content("no data");
            var line0 = csv.First().ToList();
            var names = line0.ToDictionary(i => i.TrimEnd(),
                i => line0.FindIndex(s => s == i));
            var ActiveNames = new List<string>
            {
                "First",
                "Last",
                "Birthday",
                "Email",
                "CellPhone",
                "HomePhone",
            };
            var hasvalidcolumn = false;
            foreach (var name in names.Keys)
                if (ActiveNames.Contains(name))
                {
                    hasvalidcolumn = true;
                    break;
                }
            if (!hasvalidcolumn)
                return Content("no valid column");

            var list = new List<FindInfo>();
            foreach (var a in csv.Skip(1))
            {
                var row = new FindInfo();
                row.First = FindColumn(names, a, "First");
                row.Last = FindColumn(names, a, "Last");
                row.Birthday = FindColumnDate(names, a, "Birthday");
                row.Email = FindColumn(names, a, "Email");
                row.CellPhone = FindColumnDigits(names, a, "CellPhone");
                row.HomePhone = FindColumnDigits(names, a, "HomePhone");

                var pids = DbUtil.Db.FindPerson3(row.First, row.Last, row.Birthday, row.Email, row.CellPhone, row.HomePhone, null);
                row.Found = pids.Count();
                if (row.Found == 1)
                    row.PeopleId = pids.Single().PeopleId.Value;
                list.Add(row);
            }
            var q = from pi in list
                    where pi.PeopleId.HasValue
                    select pi.PeopleId;
            foreach (var pid in q.Distinct())
                Person.Tag(DbUtil.Db, pid.Value, tagname, Util.UserPeopleId, DbUtil.TagTypeId_Personal);
            DbUtil.Db.SubmitChanges();

            return View(list);
        }
Exemplo n.º 2
0
        public static List<FindInfo> FindTagPeople(string text, string tagname)
        {
            if (!tagname.HasValue())
                throw new UserInputException("No Tag");

            var csv = new CsvReader(new StringReader(text), true, '\t');
            if (!csv.Any())
                throw new UserInputException("No Data");

            var cols = csv.GetFieldHeaders();
            if (!cols.Contains("First") || !cols.Contains("Last"))
                throw new UserInputException("Both First and Last are required");

            if (!cols.Any(name => new[] { "Birthday", "Email", "Phone", "Phone2", "Phone3" }.Contains(name)))
                throw new UserInputException("One of Birthday, Email, Phone, Phone2 or Phone3 is required");
            
            var list = new List<FindInfo>();

            while (csv.ReadNextRecord())
            {
                var row = new FindInfo
                {
                    First = FindColumn(csv, "First"),
                    Last = FindColumn(csv, "Last"),
                    Birthday = FindColumnDate(csv, "Birthday"),
                    Email = FindColumn(csv, "Email"),
                    Phone = FindColumnDigits(csv, "Phone"),
                    Phone2 = FindColumnDigits(csv, "Phone2"),
                    Phone3 = FindColumnDigits(csv, "Phone3")
                };

                var pids = DbUtil.Db.FindPerson3(row.First, row.Last, row.Birthday, row.Email, 
                    row.Phone, row.Phone2, row.Phone3).ToList();
                row.Found = pids.Count;
                if(pids.Count == 1)
                    row.PeopleId = pids[0].PeopleId;
                list.Add(row);
            }
            var q = from pi in list
                where pi.PeopleId.HasValue
                select pi.PeopleId;
            foreach (var pid in q.Distinct())
                Person.Tag(DbUtil.Db, pid ?? 0, tagname, Util.UserPeopleId, DbUtil.TagTypeId_Personal);
            DbUtil.Db.SubmitChanges();
            return list;
        }
Exemplo n.º 3
0
        public ActionResult FindTagPeople(string text, string tagname)
        {
            if (!tagname.HasValue())
            {
                return(Content("no tag"));
            }
            var csv = new CsvReader(new StringReader(text), false, '\t').ToList();

            if (!csv.Any())
            {
                return(Content("no data"));
            }
            var line0 = csv.First().ToList();
            var names = line0.ToDictionary(i => i.TrimEnd(),
                                           i => line0.FindIndex(s => s == i));
            var ActiveNames = new List <string>
            {
                "First",
                "Last",
                "Birthday",
                "Email",
                "CellPhone",
                "HomePhone",
            };
            var hasvalidcolumn = false;

            foreach (var name in names.Keys)
            {
                if (ActiveNames.Contains(name))
                {
                    hasvalidcolumn = true;
                    break;
                }
            }
            if (!hasvalidcolumn)
            {
                return(Content("no valid column"));
            }


            var list = new List <FindInfo>();

            foreach (var a in csv.Skip(1))
            {
                var row = new FindInfo();
                row.First     = FindColumn(names, a, "First");
                row.Last      = FindColumn(names, a, "Last");
                row.Birthday  = FindColumnDate(names, a, "Birthday");
                row.Email     = FindColumn(names, a, "Email");
                row.CellPhone = FindColumnDigits(names, a, "CellPhone");
                row.HomePhone = FindColumnDigits(names, a, "HomePhone");

                var pids = DbUtil.Db.FindPerson3(row.First, row.Last, row.Birthday, row.Email, row.CellPhone, row.HomePhone, null);
                row.Found = pids.Count();
                if (row.Found == 1)
                {
                    row.PeopleId = pids.Single().PeopleId.Value;
                }
                list.Add(row);
            }
            var q = from pi in list
                    where pi.PeopleId.HasValue
                    select pi.PeopleId;

            foreach (var pid in q.Distinct())
            {
                Person.Tag(DbUtil.Db, pid.Value, tagname, Util.UserPeopleId, DbUtil.TagTypeId_Personal);
            }
            DbUtil.Db.SubmitChanges();

            return(View(list));
        }
Exemplo n.º 4
0
        public static List <FindInfo> FindTagPeople(string text, string tagname)
        {
            if (!tagname.HasValue())
            {
                throw new UserInputException("No Tag");
            }

            var csv = new CsvReader(new StringReader(text), true, '\t');

            if (!csv.Any())
            {
                throw new UserInputException("No Data");
            }

            var cols = csv.GetFieldHeaders();

            if (!cols.Contains("First") || !cols.Contains("Last"))
            {
                throw new UserInputException("Both First and Last are required");
            }

            if (!cols.Any(name => new[] { "Birthday", "Email", "Phone", "Phone2", "Phone3" }.Contains(name)))
            {
                throw new UserInputException("One of Birthday, Email, Phone, Phone2 or Phone3 is required");
            }

            var list = new List <FindInfo>();

            while (csv.ReadNextRecord())
            {
                var row = new FindInfo
                {
                    First    = FindColumn(csv, "First"),
                    Last     = FindColumn(csv, "Last"),
                    Birthday = FindColumnDate(csv, "Birthday"),
                    Email    = FindColumn(csv, "Email"),
                    Phone    = FindColumnDigits(csv, "Phone"),
                    Phone2   = FindColumnDigits(csv, "Phone2"),
                    Phone3   = FindColumnDigits(csv, "Phone3")
                };

                var pids = DbUtil.Db.FindPerson3(row.First, row.Last, row.Birthday, row.Email,
                                                 row.Phone, row.Phone2, row.Phone3).ToList();
                row.Found = pids.Count;
                if (pids.Count == 1)
                {
                    row.PeopleId = pids[0].PeopleId;
                }
                list.Add(row);
            }
            var q = from pi in list
                    where pi.PeopleId.HasValue
                    select pi.PeopleId;

            foreach (var pid in q.Distinct())
            {
                Person.Tag(DbUtil.Db, pid ?? 0, tagname, Util.UserPeopleId, DbUtil.TagTypeId_Personal);
            }
            DbUtil.Db.SubmitChanges();
            return(list);
        }