public ActionResult Details(string id)
        {
            OperationViewModel viewModel = null;

            using (AuthEntityModelContainer context = new AuthEntityModelContainer())
            {
                var op = context.Operations.FirstOrDefault(o => o.Id == id);

                if (op != null)
                {
                    viewModel = new OperationViewModel()
                    {
                        DataType = op.DataType,
                        ID       = op.Id,
                        Name     = op.Name
                    };

                    if (op.RoleOperations != null)
                    {
                        viewModel.Roles = new List <RoleViewModel>();

                        foreach (var role in op.RoleOperations)
                        {
                            viewModel.Roles.Add(new RoleViewModel()
                            {
                                ID = role.RoleId
                            });
                        }
                    }
                }
            }

            if (viewModel.Roles != null)
            {
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new IdentityDbContext(Platform.DAAS.OData.Security.ModuleConfiguration.DefaultIdentityStoreConnectionName)));

                IdentityRole identityRole = null;

                for (int i = 0; i < viewModel.Roles.Count; i++)
                {
                    identityRole = roleManager.FindById(viewModel.Roles[i].ID);

                    if (identityRole != null)
                    {
                        viewModel.Roles[i].Name = identityRole.Name;
                        //viewModel.Roles[i].Description = identityRole.Description;
                    }
                }
            }

            return(View(viewModel));
        }
        public ActionResult Index(string dataType)
        {
            //List<OperationViewModel> viewModel = new List<OperationViewModel>();

            OperationListViewModel viewModel = new OperationListViewModel()
            {
                DataTypes = new List <string>()
            };

            using (AuthEntityModelContainer context = new AuthEntityModelContainer())
            {
                var ops = context.Operations.ToArray();

                if (ops != null)
                {
                    foreach (var op in ops)
                    {
                        if (String.IsNullOrEmpty(dataType) || (op.DataType.ToLower() == dataType.ToLower()))
                        {
                            viewModel.Add(new OperationViewModel()
                            {
                                DataType = op.DataType,
                                ID       = op.Id,
                                Name     = op.Name
                            });
                        }

                        if (!viewModel.DataTypes.Contains(op.DataType))
                        {
                            viewModel.DataTypes.Add(op.DataType);
                        }
                    }
                }
            }

            return(View(viewModel));
        }
        public async Task <ActionResult> OperationRoles(string id, FormCollection roleItems)
        {
            try
            {
                if (roleItems != null)
                {
                    Dictionary <string, object> roleItemValues = new Dictionary <string, object>();

                    List <string> operationRoles = null;

                    foreach (string key in roleItems.Keys)
                    {
                        if (key.ToLower() != "id")
                        {
                            roleItemValues.Add(key, roleItems.GetValues(key));
                        }
                    }

                    if (roleItemValues != null)
                    {
                        operationRoles = new List <string>();

                        foreach (var key in roleItemValues.Keys)
                        {
                            if ((roleItemValues[key] != null) && (roleItemValues[key] as string[]).Length >= 1)
                            {
                                if ((roleItemValues[key] as string[])[0].ToLower() == "true")
                                {
                                    operationRoles.Add(key);
                                }
                            }
                        }
                    }

                    using (AuthEntityModelContainer context = new AuthEntityModelContainer())
                    {
                        var roleOps = context.RoleOperations.Where(ro => (ro.OperationId.ToLower() == id.ToLower()));//context.RoleOperations.Where((ro => (ro.OperationId.ToLower() == id.ToLower()) && (!operationRoles.Contains(ro.OperationId))));

                        if (roleOps != null)
                        {
                            var roleOpArray = roleOps.ToArray();

                            var deletedRoleOpes = context.RoleOperations.RemoveRange(roleOpArray);

                            context.SaveChanges();
                        }
                    }

                    if (operationRoles != null)
                    {
                        var securityManager = Provider.SecurityManager();

                        List <object> setRoleResults = new List <object>();

                        foreach (var opRole in operationRoles)
                        {
                            setRoleResults.Add(securityManager.SetRoleOperation(opRole, id));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Provider.ExceptionHandler().HandleException(ex);
                return(View());
            }

            return(RedirectToAction("Details", new { id = id })); //RedirectToAction("Index");
        }
        public ActionResult OperationRoles(string operationId)
        {
            OperationRoleViewModel opViewModel = null;

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new IdentityDbContext(ModuleConfiguration.DefaultIdentityStoreConnectionName)));

            using (AuthEntityModelContainer context = new AuthEntityModelContainer())
            {
                var op = context.Operations.FirstOrDefault(o => o.Id == operationId);

                if (op != null)
                {
                    opViewModel = new OperationRoleViewModel()
                    {
                        DataType = op.DataType,
                        ID       = op.Id,
                        Name     = op.Name
                    };

                    if (op.RoleOperations != null)
                    {
                        opViewModel.OperationRoles = new List <RoleViewModel>();

                        foreach (var role in op.RoleOperations)
                        {
                            opViewModel.OperationRoles.Add(new RoleViewModel()
                            {
                                ID = role.RoleId
                            });
                        }
                    }
                }
            }

            if (opViewModel.OperationRoles != null)
            {
                IdentityRole identityRole = null;

                for (int i = 0; i < opViewModel.OperationRoles.Count; i++)
                {
                    identityRole = roleManager.FindById(opViewModel.OperationRoles[i].ID);

                    if (identityRole != null)
                    {
                        opViewModel.OperationRoles[i].Name = identityRole.Name;
                        //opViewModel.OperationRoles[i].Description = identityRole.Description;
                        opViewModel.OperationRoles[i].IsSelected = true;
                    }
                }
            }

            var roles = roleManager.Roles;

            if (roles != null)
            {
                opViewModel.Roles = new List <RoleViewModel>();

                foreach (var role in roles)
                {
                    opViewModel.Roles.Add(new RoleViewModel()
                    {
                        ID   = role.Id,
                        Name = role.Name,
                        //Description = role.Description,
                        IsSelected = (opViewModel.OperationRoles != null && opViewModel.OperationRoles.FirstOrDefault(or => or.ID.ToLower() == role.Id.ToLower()) != null)
                    });
                }
            }

            return(View(opViewModel));
        }
        public ActionResult RoleOperations(string id, FormCollection opItems)
        {
            try
            {
                var logger = Provider.Logger();

                if (opItems != null)
                {
                    Dictionary <string, object> opItemValues = new Dictionary <string, object>();

                    List <string> roleOperations = null;

                    foreach (string key in opItems.Keys)
                    {
                        if (key.ToLower() != "id")
                        {
                            opItemValues.Add(key, opItems.GetValues(key));
                        }
                    }

                    if (opItemValues != null)
                    {
                        roleOperations = new List <string>();

                        foreach (var key in opItemValues.Keys)
                        {
                            if ((opItemValues[key] != null) && (opItemValues[key] as string[]).Length >= 1)
                            {
                                if ((opItemValues[key] as string[])[0].ToLower() == "true")
                                {
                                    roleOperations.Add(key);
                                }
                            }
                        }
                    }

                    using (AuthEntityModelContainer context = new AuthEntityModelContainer())
                    {
                        var roleOps = context.RoleOperations.Where(ro => (ro.RoleId.ToLower() == id.ToLower()));

                        if (roleOps != null)
                        {
                            var roleOpArray = roleOps.ToArray();

                            var deletedRoleOpes = context.RoleOperations.RemoveRange(roleOpArray);

                            context.SaveChanges();
                        }
                    }

                    if (roleOperations != null)
                    {
                        var           securityManager = Provider.SecurityManager();
                        List <object> setRoleResults  = new List <object>();

                        foreach (var roleOp in roleOperations)
                        {
                            setRoleResults.Add(securityManager.SetRoleOperation(id, roleOp));
                        }

                        logger.LogUserOperation(ControllerContext.HttpContext.User.Identity.Name, String.Format("User \"{0}\" dispatched operation(s) to role \"{1}\".", ControllerContext.HttpContext.User.Identity.Name, id));
                    }
                }

                return(RedirectToAction("Details", new { id = id }));
            }
            catch (Exception ex)
            {
                Provider.ExceptionHandler().HandleException(ex);
                return(View());
            }
        }
        public ActionResult RoleOperations(string id)
        {
            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(new IdentityDbContext(Platform.DAAS.OData.Security.ModuleConfiguration.DefaultIdentityStoreConnectionName)));

            var role = roleManager.FindById(id);

            if (role != null)
            {
                RoleOperationViewModel viewModel = new RoleOperationViewModel()
                {
                    ID         = role.Id,
                    Name       = role.Name,
                    Operations = new OperationListViewModel()
                    {
                        DataTypes = new List <string>()
                    },
                    RoleOperations = new List <OperationViewModel>()
                };

                using (AuthEntityModelContainer context = new AuthEntityModelContainer())
                {
                    var operations = context.Operations;

                    if (operations != null)
                    {
                        foreach (var operation in operations.ToArray())
                        {
                            viewModel.Operations.Add(new OperationViewModel()
                            {
                                DataType = operation.DataType,
                                ID       = operation.Id,
                                Name     = operation.Name
                            });

                            if (!viewModel.Operations.DataTypes.Contains(operation.DataType))
                            {
                                viewModel.Operations.DataTypes.Add(operation.DataType);
                            }
                        }
                    }

                    var roleOps = context.RoleOperations.Where(ro => ro.RoleId.ToLower() == role.Id.ToLower());

                    if (roleOps != null)
                    {
                        foreach (var roleOp in roleOps.ToArray())
                        {
                            viewModel.RoleOperations.Add(new OperationViewModel()
                            {
                                DataType = roleOp.Operation.DataType,
                                ID       = roleOp.OperationId,
                                Name     = roleOp.Operation.Name
                            });
                        }
                    }
                }

                return(View(viewModel));
            }

            return(View());
        }