示例#1
0
        public void removeAction(Guid moduleId, Guid actionId)
        {
            Modules m = context.Modules.Find(moduleId);

            Business.Entities.Actions a = context.Actions.Find(actionId);
            if (m.Actions.Contains(a))
            {
                m.Actions.Remove(a);
                context.SaveChanges();
            }
        }
示例#2
0
        public void AddModuleAndAction(string[] modules, string role)
        {
            roles r = context.roles.Where(x => x.role_name == role).FirstOrDefault();
            IEnumerable <ModulesInRoles> listModule = r.ModulesInRoles;

            foreach (ModulesInRoles mInRole in listModule)
            {
                if (mInRole.Actions.Count > 0)
                {
                    var actions = mInRole.Actions.ToList();
                    foreach (var a in actions)
                    {
                        mInRole.Actions.Remove(a);
                    }
                }
            }

            context.ModulesInRoles.RemoveRange(listModule);
            context.SaveChanges();

            foreach (string s in modules)
            {
                string[]       temp = s.Split(';');
                ModulesInRoles mr;
                Guid           moduleId = new Guid(temp.First());
                Guid           actionId = new Guid(temp.Last());

                ModulesInRoles            available = context.ModulesInRoles.Where(x => x.RoleId == r.role_id).Where(x => x.ModuleId == moduleId).FirstOrDefault();
                Business.Entities.Actions a         = context.Actions.Find(actionId);

                if (available != null)
                {
                    if (!available.Actions.Contains(a))
                    {
                        available.Actions.Add(a);
                        context.SaveChanges();
                    }
                }
                else
                {
                    mr = new ModulesInRoles()
                    {
                        Id       = Guid.NewGuid(),
                        RoleId   = r.role_id,
                        ModuleId = new Guid(temp.First())
                    };
                    mr.Actions.Add(a);
                    r.ModulesInRoles.Add(mr);
                    context.SaveChanges();
                }
            }
        }
示例#3
0
        public void Delete(string actionName, bool fk)
        {
            Business.Entities.Actions a = context.Actions.Where(x => x.ActionName == actionName).FirstOrDefault();

            if (!fk)
            {
                a.Modules.Clear();
                a.ModulesInRoles.Clear();
            }

            context.Actions.Remove(a);
            context.SaveChanges();
        }
示例#4
0
 public void Create(Business.Entities.Actions action)
 {
     context.Actions.Add(action);
     context.SaveChanges();
 }