Пример #1
0
 public static string NormalizePartyName(string name, string ico)
 {
     if (_partyNames.TryGetValue(ico, out string normalizedName))
     {
         return(normalizedName);
     }
     return(ParseTools.NormalizaceStranaShortName(name));
 }
Пример #2
0
        public OsobaEvent AddClenStrany(string strana, int rokOd, int?rokDo, string zdroj, string user)
        {
            OsobaEvent oe = new OsobaEvent(this.InternalId, string.Format("Člen strany {0}", strana), "", OsobaEvent.Types.ClenStrany);

            oe.AddInfo = ParseTools.NormalizaceStranaShortName(strana);
            oe.Zdroj   = zdroj;
            oe.DatumOd = new DateTime(rokOd, 1, 1, 0, 0, 0, DateTimeKind.Local);
            oe.DatumDo = rokDo == null ? (DateTime?)null : new DateTime(rokDo.Value, 12, 31, 0, 0, 0, DateTimeKind.Local);
            return(AddOrUpdateEvent(oe, user));
        }
Пример #3
0
        private static OsobaEvent UpdateEvent(OsobaEvent eventToUpdate, OsobaEvent osobaEvent, string user, DbEntities db)
        {
            if (eventToUpdate is null)
            {
                throw new ArgumentNullException(nameof(eventToUpdate), "Argument can't be null");
            }
            if (osobaEvent is null)
            {
                throw new ArgumentNullException(nameof(osobaEvent), "Argument can't be null");
            }
            if (db is null)
            {
                throw new ArgumentNullException(nameof(db), "Argument can't be null");
            }

            var eventOriginal = eventToUpdate.ShallowCopy();

            NormalizeOsobaEvent(osobaEvent);

            if (!string.IsNullOrWhiteSpace(osobaEvent.Ico))
            {
                eventToUpdate.Ico = osobaEvent.Ico;
            }
            if (osobaEvent.OsobaId > 0)
            {
                eventToUpdate.OsobaId = osobaEvent.OsobaId;
            }

            eventToUpdate.DatumOd    = osobaEvent.DatumOd;
            eventToUpdate.DatumDo    = osobaEvent.DatumDo;
            eventToUpdate.Organizace = ParseTools.NormalizaceStranaShortName(osobaEvent.Organizace);
            eventToUpdate.AddInfoNum = osobaEvent.AddInfoNum;
            eventToUpdate.AddInfo    = osobaEvent.AddInfo;
            eventToUpdate.Title      = osobaEvent.Title;
            eventToUpdate.Type       = osobaEvent.Type;
            eventToUpdate.Zdroj      = osobaEvent.Zdroj;
            eventToUpdate.Status     = osobaEvent.Status;
            eventToUpdate.CEO        = osobaEvent.CEO;
            eventToUpdate.Created    = DateTime.Now;

            db.SaveChanges();
            if (osobaEvent.OsobaId > 0)
            {
                Osoby.GetById.Get(osobaEvent.OsobaId).FlushCache();
            }
            Audit.Add(Audit.Operations.Update, user, eventToUpdate, eventOriginal);
            return(eventToUpdate);
        }
Пример #4
0
        public OsobaEvent AddDescription(string text, string strana, string zdroj, string user, bool deletePrevious = false)
        {
            if (deletePrevious)
            {
                var oes = this.Events(m => m.Type == (int)OsobaEvent.Types.Popis);
                foreach (var o in oes)
                {
                    o.Delete(user, true);
                }
            }
            OsobaEvent oe = new OsobaEvent(this.InternalId, "", text, OsobaEvent.Types.Popis);

            oe.AddInfo = ParseTools.NormalizaceStranaShortName(strana);
            oe.Zdroj   = zdroj;
            return(AddOrUpdateEvent(oe, user));
        }
Пример #5
0
        public FirmaEvent AddSponsoring(string strana, int rok, decimal castka, string zdroj, string user, bool rewrite = false, bool checkDuplicates = true)
        {
            strana = ParseTools.NormalizaceStranaShortName(strana);
            var t = FirmaEvent.Types.Sponzor;

            if (zdroj?.Contains("https://www.hlidacstatu.cz/ucty/transakce/") == true)
            {
                t = FirmaEvent.Types.SponzorZuctu;
            }

            FirmaEvent oe = new FirmaEvent(this.ICO, string.Format("Sponzor {0}", strana), "", t);

            oe.AddInfoNum = castka;
            oe.Zdroj      = zdroj;
            oe.SetYearInterval(rok);
            oe.AddInfo = strana;
            return(AddOrUpdateEvent(oe, user, checkDuplicates: false));
        }
Пример #6
0
        private static OsobaEvent CreateEvent(OsobaEvent osobaEvent, string user, DbEntities db)
        {
            if (osobaEvent.OsobaId == 0 && string.IsNullOrWhiteSpace(osobaEvent.Ico))
            {
                throw new Exception("Cant attach event to a person or to a company since their reference is empty");
            }

            osobaEvent.Organizace = ParseTools.NormalizaceStranaShortName(osobaEvent.Organizace);
            osobaEvent.Created    = DateTime.Now;
            db.OsobaEvent.Add(osobaEvent);
            db.SaveChanges();
            if (osobaEvent.OsobaId > 0)
            {
                Osoby.GetById.Get(osobaEvent.OsobaId).FlushCache();
            }
            Audit.Add(Audit.Operations.Update, user, osobaEvent, null);
            return(osobaEvent);
        }
Пример #7
0
        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  = Devmasters.DT.Util.ToDate(cols[5]);

                Osoba.StatusOsobyEnum status = GetStatusFromText(cols[6]);

                string   clenstviStrana = ParseTools.NormalizaceStranaShortName(cols[7]);
                DateTime?clenstviVznik  = Devmasters.DT.Util.ToDate(cols[8]);

                string   eventOrganizace = cols[9];
                string   eventRole       = cols[10];
                DateTime?eventVznik      = Devmasters.DT.Util.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.JmenoInText(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.Searching.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));
        }
Пример #8
0
        public static OsobaEvent CreateOrUpdate(OsobaEvent osobaEvent, string user)
        {
            using (Lib.Data.DbEntities db = new Data.DbEntities())
            {
                // create
                if (osobaEvent.pk == 0 && osobaEvent.OsobaId > 0)
                {
                    osobaEvent.Organizace = ParseTools.NormalizaceStranaShortName(osobaEvent.Organizace);
                    osobaEvent.Created    = DateTime.Now;

                    // check if event exists so we are not creating duplicities...
                    var oe = db.OsobaEvent
                             .Where(ev =>
                                    ev.OsobaId == osobaEvent.OsobaId &&
                                    ev.Title == osobaEvent.Title &&
                                    ev.DatumOd == osobaEvent.DatumOd &&
                                    ev.Type == osobaEvent.Type &&
                                    ev.Organizace == osobaEvent.Organizace)
                             .FirstOrDefault();

                    if (oe != null)
                    {
                        return(oe);
                    }

                    db.OsobaEvent.Add(osobaEvent);
                    db.SaveChanges();
                    Audit.Add(Audit.Operations.Update, user, osobaEvent, null);
                    return(osobaEvent);
                }

                // update
                if (osobaEvent.pk > 0)
                {
                    var eventToUpdate = db.OsobaEvent
                                        .Where(ev =>
                                               ev.pk == osobaEvent.pk
                                               ).FirstOrDefault();

                    var eventOriginal = eventToUpdate.ShallowCopy();

                    if (eventToUpdate != null)
                    {
                        eventToUpdate.DatumOd    = osobaEvent.DatumOd;
                        eventToUpdate.DatumDo    = osobaEvent.DatumDo;
                        eventToUpdate.Organizace = ParseTools.NormalizaceStranaShortName(osobaEvent.Organizace);
                        eventToUpdate.AddInfoNum = osobaEvent.AddInfoNum;
                        eventToUpdate.AddInfo    = osobaEvent.AddInfo;
                        eventToUpdate.Title      = osobaEvent.Title;
                        eventToUpdate.Type       = osobaEvent.Type;
                        eventToUpdate.Zdroj      = osobaEvent.Zdroj;

                        eventToUpdate.Created = DateTime.Now;

                        db.SaveChanges();
                        Audit.Add(Audit.Operations.Update, user, eventToUpdate, eventOriginal);

                        return(eventToUpdate);
                    }
                }
            }
            return(osobaEvent);
        }