Пример #1
0
 internal Properties CreateUpdate(Properties model)
 {
     try
     {
         using (var context = new UnitOfWorkDevelopmentEntities())
         {
             Properties property;
             if (model?.Id == 0)
             {
                 property = context.Properties.Add(model);
             }
             else
             {
                 property                      = context.Properties.Find(model?.Id);
                 property.DateCreated          = DateTime.UtcNow;
                 property.Sequence             = model.Sequence;
                 property.Nickname             = model.Nickname;
                 context.Entry(property).State = System.Data.Entity.EntityState.Modified;
             }
             context.SaveChanges();
             return(property);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
 public virtual TEntity Update(TEntity entity)
 {
     try
     {
         context = new UnitOfWorkDevelopmentEntities();
         dbSet   = context.Set <TEntity>();
         var result = dbSet.Attach(entity);
         context.Entry(entity).State = EntityState.Modified;
         context.SaveChanges();
         return(result);
     }
     catch (Exception)
     {
         return(null);
     }
 }
 public virtual void Delete(TEntity entity)
 {
     try
     {
         //context = new UnitOfWorkDevelopmentEntities();
         //dbSet = context.Set<TEntity>();
         if (context.Entry(entity).State == EntityState.Detached)
         {
             dbSet.Attach(entity);
         }
         dbSet.Remove(entity);
         var results = context.SaveChanges();
     }
     catch (Exception)
     {
     }
 }