protected List <MvcControllerViewModel> GetControllers() { var controllers = new List <MvcControllerViewModel>(); //from web this code var items = actionDescriptorProvider .ActionDescriptors.Items .Where(descriptor => descriptor.GetType() == typeof(ControllerActionDescriptor)) .Select(descriptor => (ControllerActionDescriptor)descriptor) .GroupBy(descriptor => descriptor.ControllerTypeInfo.FullName) .ToList(); foreach (var actionDescriptors in items) { if (!actionDescriptors.Any()) { continue; } var actionDescriptor = actionDescriptors.First(); if (!actionDescriptor.MethodInfo.IsPublic) { continue; } var controllerTypeInfo = actionDescriptor.ControllerTypeInfo; var currentController = new MvcControllerViewModel() { Area = controllerTypeInfo.GetCustomAttribute <AreaAttribute>()?.RouteValue, DisplayName = controllerTypeInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName, Name = actionDescriptor.ControllerName, }; var actions = new List <MvcActionViewModel>(); foreach (var descriptor in actionDescriptors.GroupBy (a => a.ActionName).Select(g => g.First())) { var methodInfo = descriptor.MethodInfo; actions.Add(new MvcActionViewModel { Controller = currentController.Name, Name = descriptor.ActionName, DisplayName = methodInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName, Method = methodInfo.GetCustomAttribute <HttpMethodAttribute>()?.Name ?? "GET", }); } currentController.Actions = actions; controllers.Add(currentController); } return(controllers); }
/// <summary> /// MvcActions Discovery Service /// </summary> public MvcActionsDiscoveryService(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider) { if (actionDescriptorCollectionProvider == null) { throw new ArgumentNullException(nameof(actionDescriptorCollectionProvider)); } MvcControllers = new List <MvcControllerViewModel>(); var lastControllerName = string.Empty; MvcControllerViewModel currentController = null; var actionDescriptors = actionDescriptorCollectionProvider.ActionDescriptors.Items; foreach (var actionDescriptor in actionDescriptors) { if (actionDescriptor is not ControllerActionDescriptor descriptor) { continue; } var controllerTypeInfo = descriptor.ControllerTypeInfo; var actionMethodInfo = descriptor.MethodInfo; if (lastControllerName != descriptor.ControllerName) { currentController = new MvcControllerViewModel { AreaName = controllerTypeInfo.GetCustomAttribute <AreaAttribute>()?.RouteValue, ControllerAttributes = getAttributes(controllerTypeInfo), ControllerDisplayName = controllerTypeInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName ?? controllerTypeInfo.GetCustomAttribute <DisplayAttribute>()?.Name, ControllerName = descriptor.ControllerName, }; MvcControllers.Add(currentController); lastControllerName = descriptor.ControllerName; } currentController?.MvcActions.Add(new MvcActionViewModel { ControllerId = currentController.ControllerId, ActionName = descriptor.ActionName, ActionDisplayName = actionMethodInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName ?? actionMethodInfo.GetCustomAttribute <DisplayAttribute>()?.Name, ActionAttributes = getAttributes(actionMethodInfo), IsSecuredAction = isSecuredAction(controllerTypeInfo, actionMethodInfo) }); } }
public void Update(MvcControllerViewModel vmMVCContr, string UserName) { MvcController objMVCContr = Find(vmMVCContr.ControllerId); objMVCContr.ControllerName = vmMVCContr.ControllerName; objMVCContr.IsActive = vmMVCContr.IsActive; objMVCContr.ParentControllerId = vmMVCContr.ParentControllerId; objMVCContr.PubModuleName = vmMVCContr.PubModuleName; objMVCContr.ModifiedBy = UserName; objMVCContr.ModifiedDate = DateTime.Now; objMVCContr.ObjectState = Model.ObjectState.Modified; _MvcControllerRepository.Update(objMVCContr); _unitOfWork.Save(); }
public MvcControllerViewModel Create(MvcControllerViewModel pt, string UserName) { MvcController obj = new MvcController(); obj = Mapper.Map <MvcController>(pt); obj.CreatedBy = UserName; obj.CreatedDate = DateTime.Now; obj.ModifiedBy = UserName; obj.ModifiedDate = DateTime.Now; obj.ObjectState = Model.ObjectState.Added; _MvcControllerRepository.Add(obj); _unitOfWork.Save(); pt.ControllerId = obj.ControllerId; return(pt); }