Beispiel #1
0
        public void CreateOrUpdate(BaseEntity model)
        {
            if ((model as BaseEntity).Id == 0)
            {
                Create(model);
            }
            else
            {
                Update(model);
            }

        }
Beispiel #2
0
        public virtual int Update(BaseEntity TObject)
        {
            var entry = Context.Entry(TObject);

            if (entry.State == EntityState.Detached)
            {
                var attachedEntity = DbSet.Find(entry.Entity.Id);

                if (attachedEntity != null)
                {
                    var attachedEntry = Context.Entry(attachedEntity);

                    attachedEntry.CurrentValues.SetValues(TObject);
                }
                else
                {
                    entry.State = EntityState.Modified;
                }
            }

            return 0;
        }
Beispiel #3
0
        public virtual int Delete(BaseEntity TObject)
        {
            DbSet.Remove(TObject);

            return 0;
        }
Beispiel #4
0
        public virtual BaseEntity Create(BaseEntity TObject)
        {
            var newEntry = DbSet.Add(TObject);

            return (BaseEntity)newEntry;
        }