public virtual TEntity Update(TEntity entity, ref IMDResponse res) { if (!RuleRepository <TEntity> .IsValid(entity, ref res) || !dbSet.Any(e => e.Id == entity.Id)) { return(null); } try { entity.ModifiedDate = DateTime.Now; entity.ModifiedById = CurrentUser.UserId; entity.Version++; var CanIDo = RuleRepository <TEntity> .ProcessModifiers(CurrentUser.Role, ref entity, false); if (!CanIDo) { return(null); } Attach(entity); Entities = null; } catch (Exception ex) { res.Error(ex, entity); return(null); } return(entity); }
public virtual void HardDelete(TEntity entity, ref IMDResponse res) { try { if (context.Entry(entity).State == EntityState.Detached) { dbSet.Attach(entity); } dbSet.Remove(entity); Entities = null; } catch (Exception ex) { res.Error(ex, entity); } }
public virtual TEntity Insert(TEntity entity, ref IMDResponse res) { if (!RuleRepository <TEntity> .IsValid(entity, ref res)) { return(null); } try { entity.CreatedById = CurrentUser.UserId; entity.CreatedDate = DateTime.Now; var CanIDo = RuleRepository <TEntity> .ProcessModifiers(CurrentUser.Role, ref entity, true); if (!CanIDo) { return(null); } dbSet.Add(entity); Entities = null; } catch (Exception ex) { res.Error(ex, entity); return(null); } return(entity); }
public void Save(ref IMDResponse res) { try { context.SaveChanges(); } catch (Exception ex) { res.Error(ex); } }