public async Task AddModuleAndActionAsync(string[] modules, string role)
        {
            Role r = await context.Roles.Where(x => x.RoleName == role).FirstOrDefaultAsync();

            IEnumerable <ModulesInRole> listModule = r.ModulesInRoles;

            foreach (ModulesInRole 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);
            await context.SaveChangesAsync().ConfigureAwait(false);

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

                ModulesInRole available = await context.ModulesInRoles.Where(x => x.RoleId == r.RoleId).Where(x => x.ModuleId == moduleId).FirstOrDefaultAsync().ConfigureAwait(false);

                Business.Entities.Action a = await context.Actions.FindAsync(actionId).ConfigureAwait(false);

                if (available != null)
                {
                    if (!available.Actions.Contains(a))
                    {
                        available.Actions.Add(a);
                        await context.SaveChangesAsync();
                    }
                }
                else
                {
                    mr = new ModulesInRole()
                    {
                        Id       = Guid.NewGuid(),
                        RoleId   = r.RoleId,
                        ModuleId = new Guid(temp.First())
                    };
                    mr.Actions.Add(a);
                    r.ModulesInRoles.Add(mr);
                    await context.SaveChangesAsync();
                }
            }
        }
        public string DrawRowModule(int level, Module m, List <Business.Entities.Action> actions, Role role)
        {
            string collumn = "col-md-" + 9 / (actions.Count + 1);
            string style   = "margin-left:" + 15 * level + "px";
            string row     = @"<div class='row' style='margin-bottom: 0; border-bottom:1px solid #000'>
                            <div class='col-md-4'><div style='" + style + "'>" + m.ModuleName + @"</div></div>";

            foreach (Business.Entities.Action a in actions)
            {
                bool found      = false;
                var  enumerator = m.Actions.GetEnumerator();
                while (enumerator.MoveNext() && !found)
                {
                    if (enumerator.Current.Id == a.Id)
                    {
                        found = true;
                    }
                }

                if (found)
                {
                    ModulesInRole mr = repoModulesInRole.FindByRoleAndModule(role.RoleId, m.Id);
                    found = false;
                    if (mr != null)//check action
                    {
                        enumerator = mr.Actions.GetEnumerator();
                        while (enumerator.MoveNext() && !found)
                        {
                            if (enumerator.Current.Id == a.Id)
                            {
                                found = true;
                            }
                        }
                    }
                    if (found)
                    {
                        row += "<div class='" + collumn + @"' style='text-align:center;'><input type='checkbox' checked='checked' value='" + m.Id + ";" + a.Id + "' /></div>";
                    }
                    else
                    {
                        row += "<div class='" + collumn + @"' style='text-align:center;'><input type='checkbox' value='" + m.Id + ";" + a.Id + "' /></div>";
                    }
                }
                else
                {
                    row += "<div class='" + collumn + @"' style='text-align:center;'>-</div>";
                }
            }

            row += " </div>";

            return(row);
        }