Example #1
0
        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);
                    }
                    else
                    {
                        //Update
                        if (!new ENTRoleData().Update(db, ID, RoleName, userAccountId, Version))
                        {
                            UpdateFailed(ref validationErrors);
                            return(false);
                        }
                    }
                    return(true);
                }
                //Didn't pass validation.
                return(false);
            }
            throw new Exception("DBAction not Save.");
        }
Example #2
0
        public override bool Load(int id)
        {
            //Get the entity object from the DAL.
            var eNTRole = new ENTRoleData().Select(id);

            MapEntityToProperties(eNTRole);
            return(eNTRole != null);
        }
Example #3
0
        public override bool Load(int id)
        {
            //Get a data reader from the database.
            var role = new ENTRoleData().Select(id);

            MapEntityToProperties(role);
            return(true);
        }
Example #4
0
        public override bool Save(HRPaidTimeOffDataContext db, ref ENTValidationErrors validationErrors, int userAccountId)
        {
            if (DbAction == DBActionEnum.Save)
            {
                Validate(db, ref validationErrors);
                if (validationErrors.Count == 0)
                {
                    if (IsNewRecord())
                    {
                        ID = new ENTRoleData().Insert(db, RoleName, userAccountId);
                        foreach (var capability in RoleCapabilites)
                        {
                            capability.ENTRoleId = ID;
                        }

                        foreach (var user in RoleUserAccounts)
                        {
                            user.ENTRoleId = ID;
                        }
                    }
                    else
                    {
                        if (!new ENTRoleData().Update(db, ID, RoleName, userAccountId, Version))
                        {
                            UpdateFailed(ref validationErrors);
                            return(false);
                        }
                    }

                    if (RoleCapabilites.Save(ref validationErrors, userAccountId))
                    {
                        if (RoleUserAccounts.Save(ref validationErrors, userAccountId))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                throw new Exception("DBAction is not saved");
            }
        }
Example #5
0
        public override bool Load(int id)
        {
            ENTRole role = new ENTRoleData().Select(id);

            if (role != null)
            {
                MapEntityToProperties(role);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #6
0
        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.");
            }
        }