コード例 #1
0
ファイル: Osoba.Partial.cs プロジェクト: ovlach/HlidacStatu
        public static Osoba GetOrCreateNew(string titulPred, string jmeno, string prijmeni, string titulPo,
                                           DateTime?narozeni, StatusOsobyEnum status, string user)
        {
            var p = new Data.Osoba();

            p.TitulPred = NormalizeTitul(titulPred, true);
            p.TitulPo   = NormalizeTitul(titulPo, false);
            p.Jmeno     = NormalizeJmeno(jmeno);
            p.Prijmeni  = NormalizePrijmeni(prijmeni);

            if (narozeni.HasValue == false)
            {
                p.Status = (int)status;
                p.Save();
                Audit.Add(Audit.Operations.Create, user, p, null);
                return(p);
            }
            var exiO = Osoba.GetByName(p.Jmeno, p.Prijmeni, narozeni.Value);


            if (exiO == null)
            {
                p.Status   = (int)status;
                p.Narozeni = narozeni;
                p.Save();
                Audit.Add(Audit.Operations.Create, user, p, null);
                return(p);
            }
            else
            {
                bool changed = false;
                if (exiO.TitulPred != p.TitulPred)
                {
                    changed        = true;
                    exiO.TitulPred = p.TitulPred;
                }
                if (exiO.TitulPo != p.TitulPo)
                {
                    changed      = true;
                    exiO.TitulPo = p.TitulPo;
                }
                if (exiO.Status < (int)status)
                {
                    changed     = true;
                    exiO.Status = (int)status;
                }
                if (changed)
                {
                    exiO.Save();
                    Audit.Add(Audit.Operations.Update, user, exiO, Osoba.Get(exiO.InternalId));
                }
                return(exiO);
            }
        }
コード例 #2
0
            public Osoba Save(string user)
            {
                Osoba o = null;
                var   t = this;

                DateTime?narozeni = ParseTools.ToDateTime(t.Narozeni, "yyyy-MM-dd");

                //find existing
                if (this.Id > 0)
                {
                    o = Osoby.GetById.Get(this.Id);
                }
                else if (narozeni.HasValue == false)
                {
                    return(null);
                }
                if (o == null)
                {
                    o = Osoba.GetByName(t.Jmeno, t.Prijmeni, narozeni.Value);
                }
                if (o == null)
                {
                    o = Osoba.GetByNameAscii(t.Jmeno, t.Prijmeni, narozeni.Value);
                }

                if (o == null)
                {
                    o = new Data.Osoba();
                }

                o.Pohlavi  = (t.Gender == gender.Žena) ? "f" : "m";
                o.Jmeno    = t.Jmeno;
                o.Narozeni = narozeni.Value;
                o.Umrti    = ParseTools.ToDateTime(t.Umrti, "yyyy-MM-dd");
                o.Prijmeni = t.Prijmeni;
                o.Status   = (int)t.Status;
                o.NameId   = t.NameId;
                o.Save();

                foreach (var e in t.Event)
                {
                    OsobaEvent ev = new OsobaEvent();
                    ev.pk         = e.pk;
                    ev.Organizace = e.Organizace;
                    ev.AddInfoNum = e.AddInfoNum;
                    ev.DatumOd    = ParseTools.ToDateTime(e.DatumOd, "yyyy-MM-dd");
                    ev.DatumDo    = ParseTools.ToDateTime(e.DatumDo, "yyyy-MM-dd");
                    ev.Note       = e.Note;
                    ev.Title      = e.Title;
                    ev.Type       = (int)e.Typ;
                    ev.AddInfo    = e.AddInfo;
                    ev.Zdroj      = e.Zdroj;
                    ev.OsobaId    = o.InternalId;
                    o.AddOrUpdateEvent(ev, user);
                }

                foreach (var v in t.Vazbyfirmy)
                {
                    if (!string.IsNullOrEmpty(v.VazbaKOsoba))
                    {
                        var os = Osoby.GetByNameId.Get(v.VazbaKOsoba);
                        if (os != null)
                        {
                            OsobaVazby.AddOrUpdate(o.InternalId, os.InternalId, (int)v.TypVazby, v.Popis, 0, ParseTools.ToDateTime(v.DatumOd, "yyyy-MM-dd"), ParseTools.ToDateTime(v.DatumDo, "yyyy-MM-dd"), v.Zdroj);
                        }
                    }
                    else
                    {
                        OsobaVazby.AddOrUpdate(o.InternalId, v.VazbaKIco, (int)v.TypVazby, v.Popis, 0, ParseTools.ToDateTime(v.DatumOd, "yyyy-MM-dd"), ParseTools.ToDateTime(v.DatumDo, "yyyy-MM-dd"), v.Zdroj);
                    }
                }
                return(o);
            }