public ActionResult AddPersons(FormCollection form) { this.Server.ScriptTimeout = 600; List <string> newIds = new List <string>(); string tabdelimited = form["data"]; foreach (var line in tabdelimited.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries)) { string[] cols = line.Split(new string[] { "\t", "|" }, StringSplitOptions.None); // Vždy musí být řádek o 13 sloupcích. Povinné položky jsou: // varianta a) jmeno, prijmeni, narozeni // varianta b) fullname, narozeni if (cols.Count() != 13) { continue; } string fullName = cols[0]; string jmeno = cols[1]; string prijmeni = cols[2]; string titulPred = cols[3]; string titulPo = cols[4]; DateTime?narozeni = ParseTools.ToDate(cols[5]); Osoba.StatusOsobyEnum status = GetStatusFromText(cols[6]); string clenstviStrana = ParseTools.NormalizaceStranaShortName(cols[7]); DateTime?clenstviVznik = ParseTools.ToDate(cols[8]); string eventOrganizace = cols[9]; string eventRole = cols[10]; DateTime?eventVznik = ParseTools.ToDate(cols[11]); string eventTyp = cols[12]; // set person from fulltext when not properly defined if (string.IsNullOrWhiteSpace(jmeno) || string.IsNullOrWhiteSpace(prijmeni)) { if (string.IsNullOrWhiteSpace(fullName)) { continue; } var osoba = Lib.Validators.OsobaInText(fullName); if (osoba is null) { continue; } if (string.IsNullOrWhiteSpace(jmeno)) { jmeno = osoba.Jmeno; } if (string.IsNullOrWhiteSpace(prijmeni)) { prijmeni = osoba.Prijmeni; } if (string.IsNullOrWhiteSpace(titulPred)) { titulPred = osoba.TitulPred; } if (string.IsNullOrWhiteSpace(titulPo)) { titulPo = osoba.TitulPo; } } // when there is no narozeni Date, then we are not going to save person... if (!narozeni.HasValue) { continue; } Osoba p = Osoba.GetOrCreateNew(titulPred, jmeno, prijmeni, titulPo, narozeni, status, this.User.Identity.Name); if (!string.IsNullOrWhiteSpace(clenstviStrana)) { OsobaEvent clenStrany = new OsobaEvent { OsobaId = p.InternalId, DatumOd = clenstviVznik, Type = 7, AddInfo = "člen strany", Organizace = clenstviStrana, Title = $"člen v {clenstviStrana}" }; OsobaEvent.CreateOrUpdate(clenStrany, this.User.Identity.Name); } if (int.TryParse(eventTyp, out int typ) && !string.IsNullOrWhiteSpace(eventRole) && !string.IsNullOrWhiteSpace(eventOrganizace)) { OsobaEvent dalsiEvent = new OsobaEvent { OsobaId = p.InternalId, DatumOd = eventVznik, Type = typ, AddInfo = eventRole, Organizace = eventOrganizace, Title = $"{eventRole} v {eventOrganizace}" }; OsobaEvent.CreateOrUpdate(dalsiEvent, this.User.Identity.Name); } //Guid? foundId; //if (Osoba.GetByName(p.Jmeno, p.Prijmeni, p.Narozeni.Value) == null) //{ // if (cols.Count() > 5) // p.Description = cols[5]; // if (cols.Count() > 6) // p.PersonStatus = string.IsNullOrEmpty(cols[6]) ? 0 : int.Parse(cols[6]); // if (cols.Count() > 7) // p.Zdroj = cols[7]; // if (cols.Count() > 8) // p.MoreInfoUrl = cols[8]; // var res = Person.Import(p, true); // if (res.IsValid) // newIds.Add(res.Id + " " + p.FullName()); //} } return(View(newIds)); }
public static Osoba GetOrCreateNew(string titulPred, string jmeno, string prijmeni, string titulPo, string narozeni, StatusOsobyEnum status, string user ) { return(GetOrCreateNew(titulPred, jmeno, prijmeni, titulPo, ParseTools.ToDate(narozeni), status, user)); }