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

        }
Esempio n. 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;
        }
Esempio n. 3
0
        public virtual int Delete(BaseEntity TObject)
        {
            DbSet.Remove(TObject);

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

            return (BaseEntity)newEntry;
        }