Advertisement
_fops

Untitled

Jan 7th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1.         protected override bool BeforeSaveEntity(EntityInfo entityInfo)
  2.         {
  3.             // use beforesaveentity for security checks
  4.             var entity = entityInfo.Entity;
  5.  
  6.             if (entity is tblTransactionImporterDiscounts)
  7.             {
  8.                 return !IsSales;
  9.             }
  10.  
  11.             if (entity is tblTransactions)
  12.             {
  13.                 return BeforeSaveTransaction(entity as tblTransactions, entityInfo);
  14.             }
  15.             if (entity is tblEmployees)
  16.             {
  17.                 // employee objects can only be changed by admin. basta
  18.                 if (!IsAdmin)
  19.                     return false;
  20.                 // never allow admin to delete himself...
  21.                 if (((tblEmployees)entity).IDEmployee == UserId && entityInfo.EntityState == EntityState.Deleted)
  22.                     return false;
  23.                 if (entityInfo.EntityState == EntityState.Deleted)
  24.                     BeforeDeleteEmployees(entity as tblEmployees, entityInfo);
  25.  
  26.                 return true;
  27.             }
  28.  
  29.             throw new InvalidOperationException("Cannot save entity of unknown type");
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement