예제 #1
0
 public void Delete(string user, bool skipTransactionDelete)
 {
     if (this.pk > 0)
     {
         using (DbEntities db = new Data.DbEntities())
         {
             if (skipTransactionDelete == false && this.Zdroj?.StartsWith("https://www.hlidacstatu.cz/ucty/transakce/") == true)
             {
                 //delete link in connected transaction
                 TransparentniUcty.BankovniPolozka bp = TransparentniUcty.BankovniPolozka.Get(this.Zdroj.Replace("https://www.hlidacstatu.cz/ucty/transakce/", ""));
                 if (bp != null)
                 {
                     if (bp.Comments.Length > 0)
                     {
                         bp.Comments = new TransparentniUcty.BankovniPolozka.Comment[] { };
                         bp.Save(user);
                     }
                 }
             }
             db.OsobaEvent.Attach(this);
             db.Entry(this).State = System.Data.Entity.EntityState.Deleted;
             Audit.Add <OsobaEvent>(Audit.Operations.Delete, user, this, null);
             db.SaveChanges();
         }
     }
 }
예제 #2
0
        public void Save()
        {
            using (Lib.Data.DbEntities db = new Data.DbEntities())
            {
                db.Review.Attach(this);
                if (this.Id == 0)
                {
                    db.Entry(this).State = System.Data.Entity.EntityState.Added;
                }
                else
                {
                    db.Entry(this).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();
            }
        }
예제 #3
0
        public Osoba Save(params OsobaExternalId[] externalIds)
        {
            using (Lib.Data.DbEntities db = new Data.DbEntities())
            {
                this.JmenoAscii           = Devmasters.Core.TextUtil.RemoveDiacritics(this.Jmeno);
                this.PrijmeniAscii        = Devmasters.Core.TextUtil.RemoveDiacritics(this.Prijmeni);
                this.PuvodniPrijmeniAscii = Devmasters.Core.TextUtil.RemoveDiacritics(this.PuvodniPrijmeni);

                if (string.IsNullOrEmpty(this.NameId))
                {
                    this.NameId = GetUniqueNamedId();
                }

                db.Osoba.Attach(this);

                this.LastUpdate = DateTime.Now;



                if (this.InternalId == 0)
                {
                    db.Entry(this).State = System.Data.Entity.EntityState.Added;
                }
                else
                {
                    db.Entry(this).State = System.Data.Entity.EntityState.Modified;
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.Write(e.ToString());
                }
                if (externalIds != null)
                {
                    foreach (var ex in externalIds)
                    {
                        ex.OsobaId = this.InternalId;
                        OsobaExternalId.Add(ex);
                    }
                }
            }
            return(this);
        }
예제 #4
0
        public void Delete(string user)
        {
            if (this.Id > 0)
            {
                using (DbEntities db = new Data.DbEntities())
                {
                    db.Sponzoring.Attach(this);
                    db.Entry(this).State = System.Data.Entity.EntityState.Deleted;
                    Audit.Add <Sponzoring>(Audit.Operations.Delete, user, this, null);

                    db.SaveChanges();
                }
            }
        }
예제 #5
0
        public void Delete(string user)
        {
            using (Lib.Data.DbEntities db = new Data.DbEntities())
            {
                db.Osoba.Attach(this);
                db.Entry(this).State = System.Data.Entity.EntityState.Deleted;

                foreach (var oe in this.Events())
                {
                    oe.Delete(user, false);
                }
                Audit.Add <Osoba>(Audit.Operations.Delete, user, this, null);
                db.SaveChanges();
            }
        }
예제 #6
0
        public FirmaEvent AddOrUpdateEvent(FirmaEvent ev, string user, bool rewrite = false, bool checkDuplicates = true)
        {
            if (ev == null)
            {
                return(null);
            }

            //if (ev.Type == (int)OsobaEvent.Types.Sponzor)
            //{
            //    return AddSponsoring(ev.AddInfo, ev.DatumOd.Value.Year, ev.AddInfoNum.Value, ev.Zdroj, user);
            //}

            //check duplicates
            using (DbEntities db = new Data.DbEntities())
            {
                FirmaEvent exists = null;
                if (ev.pk > 0 && checkDuplicates)
                {
                    exists = db.FirmaEvent
                             .AsNoTracking()
                             .FirstOrDefault(m =>
                                             m.pk == ev.pk
                                             );
                }
                else if (checkDuplicates)
                {
                    exists = db.FirmaEvent
                             .AsNoTracking()
                             .FirstOrDefault(m =>
                                             m.ICO == this.ICO &&
                                             m.Type == ev.Type &&
                                             m.AddInfo == ev.AddInfo &&
                                             m.AddInfoNum == ev.AddInfoNum &&
                                             m.DatumOd == ev.DatumOd &&
                                             m.DatumDo == ev.DatumDo &&
                                             m.Zdroj == ev.Zdroj
                                             );
                    if (exists != null)
                    {
                        ev.pk = exists.pk;
                    }
                }
                if (exists != null && rewrite)
                {
                    db.FirmaEvent.Remove(exists);
                    Audit.Add <FirmaEvent>(Audit.Operations.Delete, user, exists, null);
                    db.SaveChanges();
                    exists = null;
                }

                if (exists == null)
                {
                    ev.ICO = this.ICO;
                    db.FirmaEvent.Add(ev);
                    Audit.Add(Audit.Operations.Create, user, ev, null);
                    db.SaveChanges();
                    return(ev);
                }
                else
                {
                    ev.ICO = this.ICO;
                    ev.pk  = exists.pk;
                    db.FirmaEvent.Attach(ev);
                    db.Entry(ev).State = System.Data.Entity.EntityState.Modified;
                    Audit.Add(Audit.Operations.Create, user, ev, exists);
                    db.SaveChanges();
                    return(ev);
                }
            }
        }