protected override void MapEntityToCustomProperties(IENTBaseEntity entity) { var role = (ENTRole)entity; ID = role.ENTRoleId; RoleName = role.RoleName; RoleCapabilities.LoadByENTRoleId(ID); RoleUserAccounts.LoadByEntRoleId(ID); }
public override bool Save(HRPaidTimeOffDataContext db, ref ENTValidationErrors validationErrors, int userAccountId) { if (DBAction == DBActionEnum.Save) { //Validate the object Validate(db, ref validationErrors); //Check if there were any validation errors if (validationErrors.Count == 0) { if (IsNewRecord()) { //Add ID = new ENTRoleData().Insert(db, RoleName, userAccountId); //Since this was an add you need to update all the role ids for the user and capability records foreach (ENTRoleCapabilityEO capability in RoleCapabilities) { capability.ENTRoleId = ID; } foreach (ENTRoleUserAccountEO user in RoleUserAccounts) { user.ENTRoleId = ID; } } else { //Update if (!new ENTRoleData().Update(db, ID, RoleName, userAccountId, Version)) { UpdateFailed(ref validationErrors); return(false); } } //Now save the capabilities if (RoleCapabilities.Save(db, ref validationErrors, userAccountId)) { //Now save the users if (RoleUserAccounts.Save(db, ref validationErrors, userAccountId)) { return(true); } else { return(false); } } else { return(false); } } else { //Didn't pass validation. return(false); } } else { throw new Exception("DBAction not Save."); } }