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 Insert(TEntity entity) { context = new UnitOfWorkDevelopmentEntities(); dbSet = context.Set <TEntity>(); var response = dbSet.Add(entity); context.SaveChanges(); return(response); //return new Response //{ // Success = (output == 0) ? true : false, // Result = output, // Exception = (output != 0) ? "Error Inserting into database" : string.Empty //}; }
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) { } }