public void OnActionExecuted(ActionExecutedContext filterContext) { EcardModel model = filterContext.Controller.ViewData.Model as EcardModel; if (model != null && model.Container == null) { var controller = filterContext.RouteData.Values["controller"].ToString(); var action = filterContext.RouteData.Values["action"].ToString(); var controllerType = _controllerFinder.FindController(controller); if (controllerType == null) { return; } var controllerTypeDesc = ViewModelDescriptor.GetTypeDescriptor(controllerType); PageContainer c = new PageContainer(); c.Description = controllerTypeDesc.Description; c.DisplayName = controllerTypeDesc.LongName; c.Name = controllerTypeDesc.Name; model.Container = c; } }
protected override void WriteFile(HttpResponseBase response) { var type = ViewModelDescriptor.GetTypeDescriptor(_itemType); Grid grid = new Grid(); var user = _securityHelper.GetCurrentUser(); var properties = type.Properties.Where(x => x.Show && (user == null || x.Permission.Check(user.CurrentUser))).OrderBy(x => x.Order).ToList(); foreach (var propertyDescriptor in properties) { grid.Columns.Add(new GridColumn(propertyDescriptor.ShortName, 80)); } foreach (var item in _items) { var row = grid.NewRow(); for (int i = 0; i < properties.Count; i++) { var propertyDescriptor = properties[i]; row[i].Text = string.Format(propertyDescriptor.ShortNameFormat, propertyDescriptor.GetValue(item)); } grid.Rows.Add(row); } ExcelExport export = new ExcelExport(); var bytes = export.Export(grid); response.BinaryWrite(bytes); response.End(); }
public void Query() { var request = new TaskRequest(); if (this.State != TaskStates.All) { request.State = State; } request.CommandTypeName = this.CommandType; var query = this.TaskService.Query(request); // fill condition List = query.ToList(this, x => new ListTask(x)); // commandName, descripton object foreach (var task in List) { var type = Type.GetType(task.InnerObject.CommandTypeName, false, true); if (type != null) { var desc = ViewModelDescriptor.GetTypeDescriptor(type); task.CommandName = desc.Name; } } // users var userids = List.Select(x => x.InnerObject.CreatorId).Union(List.Select(x => x.InnerObject.EditorId)).ToArray(); var users = MembershipService.GetByIds(userids).ToList(); foreach (var task in List) { var user = users.FirstOrDefault(x => x.UserId == task.InnerObject.CreatorId); if (user != null) { task.CreatorUserName = user.DisplayName; } user = users.FirstOrDefault(x => x.UserId == task.InnerObject.EditorId); if (user != null) { task.EditorUserName = user.DisplayName; } } var accountIds = List.Select(x => x.InnerObject.AccountId).ToArray(); var accounts = AccountService.GetByIds(accountIds); foreach (var task in List) { var account = accounts.FirstOrDefault(x => x.AccountId == task.InnerObject.AccountId); if (account != null) { task.AccountName = account.Name; } } }
public void Ready() { var user = SecurityHelper.GetCurrentUser(); var dashboardItemModels = (from x in DashboardItemRepository.Query() let controllerType = ControllerFinder.FindController(x.Controller) let method = ViewModelDescriptor.GetTypeDescriptor(controllerType).GetMethod(x.Action) where method != null && method.Permission.Check(user.CurrentUser) select new DashboardItemModel(method, x)).ToList(); List = dashboardItemModels; }
public static int PropertyCount(this HtmlHelper htmlHelper, Type itemType) { var helper = EcardContext.Container.Resolve <SecurityHelper>(); User currentUser = helper.GetCurrentUser(); var buffer = new StringBuilder(); int count = ViewModelDescriptor.GetTypeDescriptor(itemType).Properties.Where( x => x.Permission.Check(currentUser) && x.Show).OrderBy(x => x.Order).Count(); return(count); }
public static MvcHtmlString Tds <TModel>(this HtmlHelper <TModel> htmlHelper, object item, Type itemType) { var helper = EcardContext.Container.Resolve <SecurityHelper>(); User currentUser = helper.GetCurrentUser(); var buffer = new StringBuilder(); foreach ( PropertyDescriptor propertyDescriptor in ViewModelDescriptor.GetTypeDescriptor(itemType).Properties.Where(x => x.Permission.Check(currentUser) && x.Show).OrderBy(x => x.Order)) { buffer.Append(htmlHelper.Td(propertyDescriptor, item).ToHtmlString()); } return(MvcHtmlString.Create(buffer.ToString())); }
public static MvcHtmlString Ths <TModel>(this HtmlHelper <TModel> htmlHelper, IEnumerable collection, Type itemType) { var helper = EcardContext.Container.Resolve <SecurityHelper>(); User currentUser = helper.GetCurrentUser().CurrentUser; IPageOfList pagedList = null; pagedList = collection as IPageOfList; var buffer = new StringBuilder(); foreach ( PropertyDescriptor propertyDescriptor in ViewModelDescriptor.GetTypeDescriptor(itemType).Properties.Where(x => x.Permission.Check(currentUser) && x.Show).OrderBy(x => x.Order)) { buffer.Append(htmlHelper.Th(propertyDescriptor, pagedList).ToHtmlString()); } return(MvcHtmlString.Create(buffer.ToString())); }
private MenuItem AddChildren(XElement parent, int level) { var children = parent.Elements("node"); if (children.Count() == 0) { var controllerType = _controllerFinder.FindController((string)parent.Attribute("controller")); if (controllerType == null) { return(null); } var typeDescriptor = ViewModelDescriptor.GetTypeDescriptor(controllerType); var actionMethod = typeDescriptor.GetMethod((string)parent.Attribute("action")); if (actionMethod == null) { return(null); } return(new MenuItem("", (string)parent.Attribute("title") ?? actionMethod.Name, actionMethod.Description, actionMethod.Permission, (string)parent.Attribute("controller"), (string)parent.Attribute("action"), (string)parent.Attribute("parameterObject")) { Level = level }); } else { var menuItem = new MenuItem((string)parent.Attribute("name"), (string)parent.Attribute("title"), (string)parent.Attribute("desc"), new Allow()) { Level = level }; if (parent.Attribute("controller") != null) { var controllerType = _controllerFinder.FindController((string)parent.Attribute("controller")); if (controllerType != null) { var typeDescriptor = ViewModelDescriptor.GetTypeDescriptor(controllerType); var actionMethod = typeDescriptor.GetMethod((string)parent.Attribute("action")); if (actionMethod == null) { return(null); } menuItem = new MenuItem("", (string)parent.Attribute("title") ?? actionMethod.Name, actionMethod.Description, actionMethod.Permission, (string)parent.Attribute("controller"), (string)parent.Attribute("action"), (string)parent.Attribute("parameterObject")) { Level = level }; } } foreach (var xnode in children) { var childMenuItem = AddChildren(xnode, level + 1); if (childMenuItem != null) { menuItem.Add(childMenuItem); } } return(menuItem); } }
public static MvcHtmlString Link(this HtmlHelper htmlHelper, string action, string controller, object routeValues, bool textEnabled, string template, bool?isPost = null) { action = action ?? htmlHelper.ViewContext.RouteData.Values["action"] as string; controller = controller ?? htmlHelper.ViewContext.RouteData.Values["controller"] as string; var controllerFinder = ExtensionsHelper.Resolve <IControllerFinder>(); Type controllerType = controllerFinder.FindController(controller); if (controllerType == null) { return(MvcHtmlString.Empty); } MethodInfo method = controllerType.GetMethods().FirstOrDefault(x => string.Equals(x.Name, action, StringComparison.InvariantCultureIgnoreCase)); if (method == null) { return(MvcHtmlString.Empty); } isPost = isPost ?? method.GetAttribute <HttpPostAttribute>(false) != null; ViewModelDescriptor controllerTypeDesc = ViewModelDescriptor.GetTypeDescriptor(controllerType); MethodDescriptor methodDesc = controllerTypeDesc.GetMethod(action); if (methodDesc == null) { return(MvcHtmlString.Empty); } User user = EcardContext.Container.Resolve <SecurityHelper>().GetCurrentUser(); if (user != null) { if (!methodDesc.Permission.Check(user)) { return(MvcHtmlString.Empty); } } string text = textEnabled ? methodDesc.Name : ""; string icon = methodDesc.ToolbarIcon; string description = methodDesc.Description; string confirm = methodDesc.Confirm; RouteValueDictionary routeValueDictionary = HtmlHelper.AnonymousObjectToHtmlAttributes(routeValues); if (routeValues is RouteValueDictionary) { routeValueDictionary = (RouteValueDictionary)routeValues; } return(htmlHelper.Partial(GetTemplateName(template), new ActionModel { IsPost = (bool)isPost, ConfirmMessage = confirm, Text = text, Icon = icon, Description = description, Action = action, Controller = controller, RouteValues = routeValueDictionary })); }