Esempio n. 1
0
        public ActionResult OsobaSmazat(string nameId)
        {
            var auth = Framework.ApiAuth.IsApiAuth(this, "TeamMember");

            if (auth.Authentificated)
            {
                HlidacStatu.Lib.Data.Osoba o = HlidacStatu.Lib.Data.Osoba.GetByNameId(nameId);
                if (o == null)
                {
                    return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(new { valid = false, error = "Not found." }), "application/json"));
                }

                o.Delete(auth.ApiCall.User);
                return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(
                                   new { valid = true })
                               , "application/json"));
            }
            else
            {
                return(View("Error401"));
            }
        }
Esempio n. 2
0
        public Osoba MergeWith(Osoba duplicated, string user)
        {
            if (this.InternalId == duplicated.InternalId)
            {
                return(this);
            }

            OsobaEvent[]      dEvs  = duplicated.Events().ToArray();
            OsobaExternalId[] dEids = duplicated.ExternalIds().Where(m => m.ExternalSource != (int)OsobaExternalId.Source.HlidacSmluvGuid).ToArray();

            foreach (var dEv in dEvs)
            {
                bool exists = false;
                foreach (var ev in this.Events())
                {
                    exists = exists || OsobaEvent.Compare(ev, dEv);
                }
                if (!exists)
                {
                    this.AddOrUpdateEvent(dEv, user);
                }
            }

            List <OsobaExternalId> addExternalIds = new List <OsobaExternalId>();

            foreach (var dEid in dEids)
            {
                bool exists = false;
                foreach (var eid in this.ExternalIds())
                {
                    exists = exists || (eid.ExternalId == dEid.ExternalId && eid.ExternalSource == dEid.ExternalSource && eid.OsobaId == dEid.OsobaId);
                }
                if (!exists)
                {
                    addExternalIds.Add(dEid);
                }
            }

            if (string.IsNullOrEmpty(this.TitulPred) && !string.IsNullOrEmpty(duplicated.TitulPred))
            {
                this.TitulPred = duplicated.TitulPred;
            }
            if (string.IsNullOrEmpty(this.Jmeno) && !string.IsNullOrEmpty(duplicated.Jmeno))
            {
                this.Jmeno = duplicated.Jmeno;
            }
            if (string.IsNullOrEmpty(this.Prijmeni) && !string.IsNullOrEmpty(duplicated.Prijmeni))
            {
                this.Prijmeni = duplicated.Prijmeni;
            }
            if (string.IsNullOrEmpty(this.TitulPo) && !string.IsNullOrEmpty(duplicated.TitulPo))
            {
                this.TitulPo = duplicated.TitulPo;
            }
            if (string.IsNullOrEmpty(this.Pohlavi) && !string.IsNullOrEmpty(duplicated.Pohlavi))
            {
                this.Pohlavi = duplicated.Pohlavi;
            }
            if (string.IsNullOrEmpty(this.Ulice) && !string.IsNullOrEmpty(duplicated.Ulice))
            {
                this.Ulice = duplicated.Ulice;
            }
            if (string.IsNullOrEmpty(this.Mesto) && !string.IsNullOrEmpty(duplicated.Mesto))
            {
                this.Mesto = duplicated.Mesto;
            }
            if (string.IsNullOrEmpty(this.PSC) && !string.IsNullOrEmpty(duplicated.PSC))
            {
                this.PSC = duplicated.PSC;
            }
            if (string.IsNullOrEmpty(this.CountryCode) && !string.IsNullOrEmpty(duplicated.CountryCode))
            {
                this.CountryCode = duplicated.CountryCode;
            }
            if (string.IsNullOrEmpty(this.PuvodniPrijmeni) && !string.IsNullOrEmpty(duplicated.PuvodniPrijmeni))
            {
                this.PuvodniPrijmeni = duplicated.PuvodniPrijmeni;
            }

            if (!this.Narozeni.HasValue && duplicated.Narozeni.HasValue)
            {
                this.Narozeni = duplicated.Narozeni;
            }
            if (!this.Umrti.HasValue && duplicated.Umrti.HasValue)
            {
                this.Umrti = duplicated.Umrti;
            }
            if (!this.OnRadar && duplicated.OnRadar)
            {
                this.OnRadar = duplicated.OnRadar;
            }

            if (this.Status < duplicated.Status)
            {
                this.Status = duplicated.Status;
            }

            if (duplicated.InternalId != 0)
            {
                duplicated.Delete(user);
            }

            //obrazek
            if (this.HasPhoto() == false && duplicated.HasPhoto())
            {
                foreach (var fn in new string[] { "small.jpg", "source.txt", "original.uploaded.jpg", "small.uploaded.jpg" })
                {
                    var from = Lib.Init.OsobaFotky.GetFullPath(duplicated, fn);
                    var to   = Lib.Init.OsobaFotky.GetFullPath(this, fn);
                    if (System.IO.File.Exists(from))
                    {
                        System.IO.File.Copy(from, to);
                    }
                }
            }
            this.Save(addExternalIds.ToArray());


            return(this);
        }