Exemplo n.º 1
0
        public virtual IEnumerable <VModel.RoleFeature> GetRoleFeatures(int roleID)
        {
            Model.Role role = _repository.GetQuery <Model.Role>().SingleOrDefault(m => m.ID == roleID);

            IEnumerable <Model.RoleFeature> modroleFeatures = (from roleFeatures in _repository.GetQuery <Model.RoleFeature>()
                                                               where roleFeatures.Role.ID == roleID
                                                               select roleFeatures).Include(m => m.Feature).Include(m => m.Role).AsEnumerable();

            IEnumerable <int> featureIDs = modroleFeatures.Select(m => m.Feature.ID);

            IEnumerable <Model.Feature> modFeatures = (from feature in _repository.GetQuery <Model.Feature>()
                                                       where !featureIDs.Contains(feature.ID)
                                                       select feature).AsEnumerable();

            List <Model.RoleFeature> unusedFeatures = new List <Model.RoleFeature>();

            foreach (Model.Feature feature in modFeatures)
            {
                Model.RoleFeature roleFeature = new Model.RoleFeature();
                roleFeature.Role          = role;
                roleFeature.Feature       = feature;
                roleFeature.ViewAccessInd = roleFeature.EditAccessInd = roleFeature.DeleteAccessInd = roleFeature.NewAccessInd = false;

                unusedFeatures.Add(roleFeature);
            }

            modroleFeatures = modroleFeatures.Union(unusedFeatures);

            IEnumerable <VModel.RoleFeature> busroleFeatures = Mapper.Map <IEnumerable <Model.RoleFeature>, IEnumerable <VModel.RoleFeature> >(modroleFeatures);

            return(busroleFeatures);
        }
Exemplo n.º 2
0
        public virtual bool SetRoleFeatures(int roleID, IEnumerable <VModel.RoleFeature> roleFeatures)
        {
            bool retVal = true;

            try {
                Model.Role role = _repository.GetQuery <Model.Role>().SingleOrDefault(m => m.ID == roleID);

                foreach (VModel.RoleFeature roleFeature in roleFeatures)
                {
                    bool              isNew    = false;
                    Model.Feature     feature  = _repository.GetQuery <Model.Feature>().SingleOrDefault(m => m.ID == roleFeature.Feature.ID);
                    Model.RoleFeature rFeature = null;
                    rFeature = _repository.GetQuery <Model.RoleFeature>().SingleOrDefault(m => m.Role.ID == roleID && m.Feature.ID == feature.ID);

                    if (rFeature == null)
                    {
                        rFeature         = new Model.RoleFeature();
                        rFeature.Role    = role;
                        rFeature.Feature = feature;
                        isNew            = true;
                    }
                    rFeature.ViewAccessInd   = roleFeature.ViewAccessInd;
                    rFeature.EditAccessInd   = roleFeature.EditAccessInd;
                    rFeature.DeleteAccessInd = roleFeature.DeleteAccessInd;
                    rFeature.NewAccessInd    = roleFeature.NewAccessInd;

                    if (isNew)
                    {
                        _repository.Add <Model.RoleFeature>(rFeature);
                    }
                    else
                    {
                        _repository.Modify <Model.RoleFeature>(m => m.Role.ID == roleID && m.Feature.ID == feature.ID, rFeature);
                    }
                }

                _repository.SaveChanges();
            }
            catch (Exception ex) {
                bool rethrow = LibraryExceptionHandler.HandleException(ref ex, System.Diagnostics.TraceEventType.Error);
                if (rethrow)
                {
                    throw ex;
                }
            }
            return(retVal);
        }