public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (!string.IsNullOrEmpty(EventHandler)) { Context.EventHandlerClass = EventHandler; } if (!string.IsNullOrEmpty(DataKeys) && DataKeys != Context.DataKeys) { Context.DataKeys = DataKeys; } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); //Get grid id and share it with siblings parents if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "div"; output.Attributes.SetAttribute("id", Context.Id); output.Attributes.SetAttribute("style", "position:relative"); if (Context.Visible) { if (RenderForm) { var form = new TagBuilder("form"); form.TagRenderMode = TagRenderMode.StartTag; output.PreContent.AppendHtml(form); } //Get data from datasource NccControlsService.BindData(Context, ViewContext.HttpContext, null, null); service?.NccInvokeMethod(NccEventsEnum.DataBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); var data = Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Internal.InternalDbSet") || Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable") ? ((IQueryable <object>)Context.DataObjects).FirstOrDefault() : Context.DataObjects as object; if (data != null) { if (!string.IsNullOrEmpty(Context.DataKeys)) { Context.DataKeysValues = new List <Dictionary <string, object> >(); var dataKeys = Context.DataKeys.Split(',')?.ToList(); var dataKeysRow = new Dictionary <string, object>(); foreach (var dataKey in dataKeys) { var keyValue = data.NccGetPropertyValue <object>(dataKey); if (keyValue != null) { dataKeysRow[dataKey] = keyValue; } } Context.DataKeysValues.Add(dataKeysRow); } ViewContext.ViewData.Model = data; var content = await output.GetChildContentAsync(); output.Content.SetHtmlContent(content.GetContent()); } if (RenderForm) { output.PostContent.AppendHtml(new TagBuilder("form") { TagRenderMode = TagRenderMode.EndTag }); } } else { output.SuppressOutput(); } service?.NccInvokeMethod(NccEventsEnum.PreRender.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); }
public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (Context == null) { throw new Exception("The NccRepeaterContext is null... Please check the reference."); } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); //Get grid id and share it with siblings parents if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "div"; output.Attributes.SetAttribute("id", Context.Id); output.Attributes.SetAttribute("style", "position:relative"); if (Context.Visible) { tagContext.Items.Add(typeof(NccRepeaterContext), Context); //NccActionsService.ExtraParameters<NccRepeaterContext> setExtraParameters = RepeaterService.GetExtraParameters; //NccActionsService.DataResult<NccRepeaterContext> setDataResult = RepeaterService.SetDataResult; NccControlsService.BindData(Context, ViewContext.HttpContext, null, null); service?.NccInvokeMethod(NccEventsEnum.DataBound.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); await output.GetChildContentAsync(); } var content = ""; foreach (var repeaterItem in _nccTagContext.RepeaterItems) { content += repeaterItem; } output.Content.AppendHtml(_nccTagContext.RepeaterHeader); output.Content.AppendHtml(content); output.Content.AppendHtml(_nccTagContext.RepeaterFooter); service?.NccInvokeMethod(NccEventsEnum.PreRender.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); _nccTagContext.ControlContext = Context; output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); }
public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (Context == null) { throw new Exception("The NccGridContext is null... Please check the reference."); } _nccTagContext.CssClassGrid = CssClassTable; _nccTagContext.CssClassBody = CssClassBody; _nccTagContext.CssClassHeader = CssClassHeader; _nccTagContext.CssClassFooter = CssClassFooter; _nccTagContext.CssClassHeaderContainer = CssClassHeaderContainer; _nccTagContext.CssClassTableContainer = CssClassTableContainer; _nccTagContext.CssClassFooterContainer = CssClassFooterContainer; if (!string.IsNullOrEmpty(DataKeys) && DataKeys != Context.DataKeys) { Context.DataKeys = DataKeys; } if (RenderForm.HasValue) { Context.RenderForm = RenderForm.Value; } if (AutoGenerateEditButton.HasValue) { Context.AutoGenerateEditButton = AutoGenerateEditButton.Value; } if (AllowPaging.HasValue) { Context.AllowPaging = AllowPaging.Value; } if (Context.AllowPaging) { if (PagerNavigationSize.HasValue) { Context.PagerNavigationSize = PagerNavigationSize.Value; } if (Context.Filters.ContainsKey("pageSize")) { Context.PageSize = Convert.ToInt32(Context.Filters["pageSize"]); } else if (PageSize.HasValue) { Context.PageSize = PageSize.Value; } if (Context.PageSize == 0 || Context.PageSize == int.MaxValue) { Context.PageSize = 10; } } else { Context.PageSize = int.MaxValue; } if (Context.Filters.ContainsKey("pageNumber")) { Context.PageNumber = Convert.ToInt32(Context.Filters["pageNumber"]); } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); //Get grid id and share it with siblings parents if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "div"; output.Attributes.SetAttribute("id", Context.Id); output.Attributes.SetAttribute("style", "position:relative"); if (Context.Visible) { tagContext.Items.Add(typeof(NccGridContext), Context); if (Context.RenderForm) { var form = new TagBuilder("form") { TagRenderMode = TagRenderMode.StartTag }; output.PreContent.AppendHtml(form); } NccActionsService.ExtraParameters <NccGridContext> setExtraParameters = GridService.GetExtraParameters; NccActionsService.DataResult <NccGridContext> setDataResult = GridService.SetDataResult; NccControlsService.BindData(Context, ViewContext.HttpContext, setExtraParameters, setDataResult); service?.NccInvokeMethod(NccEventsEnum.DataBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); _nccTagContext.GridHeader = new GridRow { Cells = new List <GridCell>(), CssClass = CssClassHeader }; await output.GetChildContentAsync(); var tableContainerDiv = new TagBuilder("div"); if (!string.IsNullOrEmpty(_nccTagContext.CssClassTableContainer)) { tableContainerDiv.Attributes.Add("class", _nccTagContext.CssClassTableContainer); } tableContainerDiv.InnerHtml.AppendHtml(GridService.BuildTableHtml(_nccTagContext, Context)); output.Content.SetHtmlContent(tableContainerDiv); if (Context.AllowPaging) { output.Content.AppendHtml(GridService.BuildTablePager(_nccTagContext, Context)); } output.PreContent.AppendHtml(_nccTagContext.PreContent); output.PostContent.AppendHtml(_nccTagContext.PostContent); if (Context.RenderForm) { var antiforgeryTag = Generator.GenerateAntiforgery(ViewContext); if (antiforgeryTag != null) { output.PostContent.AppendHtml(antiforgeryTag); } output.PostContent.AppendHtml(new TagBuilder("form") { TagRenderMode = TagRenderMode.EndTag }); } } service?.NccInvokeMethod(NccEventsEnum.PreRender.ToString(), new object[] { new NccEventArgs { NccTagContext = _nccTagContext, NccControlContext = Context, ViewContext = ViewContext } }); _nccTagContext.ControlContext = Context; output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); }
public override async Task ProcessAsync(TagHelperContext tagContext, TagHelperOutput output) { if (Context == null) { throw new Exception("The NccSelectContext is null... Please check the reference."); } object service = null; if (!string.IsNullOrEmpty(Context.EventHandlerClass)) { service = NccReflectionService.NccGetClassInstance(Context.EventHandlerClass, null); } service?.NccInvokeMethod(NccEventsEnum.Load, new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); if (string.IsNullOrEmpty(Context.Id)) { Context.Id = Guid.NewGuid().ToString(); } output.TagName = "select"; output.Attributes.SetAttribute("id", Context.Id); if (!string.IsNullOrEmpty(DataValue)) { Context.DataValue = DataValue; } if (string.IsNullOrEmpty(Context.DataValue)) { throw new Exception($"Please set the DataValue property on NccSelect with id {Context.Id}."); } if (!string.IsNullOrEmpty(TextValue)) { Context.TextValue = TextValue; } if (string.IsNullOrEmpty(Context.TextValue)) { throw new Exception($"Please set the TextValue property on NccSelect with id {Context.Id}."); } if (!string.IsNullOrEmpty(FirstItem)) { Context.FirstItem = FirstItem; } if (Context.Visible) { NccActionsService.ExtraParameters <NccSelectContext> setExtraParameters = SelectService.GetExtraParameters; NccActionsService.DataResult <NccSelectContext> setDataResult = SelectService.SetDataResult; NccControlsService.BindData(Context, ViewContext.HttpContext, setExtraParameters, setDataResult); output.Content.AppendHtml(await output.GetChildContentAsync()); if (!string.IsNullOrEmpty(Context.FirstItem)) { var select = new TagBuilder("option") { Attributes = { { "value", "" } } }; select.InnerHtml.SetContent(Context.FirstItem); service?.NccInvokeMethod(NccSelectEventsEnum.OptionBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); output.Content.AppendHtml(select); } //var data = Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Internal.InternalDbSet") || // Context.DataObjects.GetType().ToString().Contains("Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable") ? // ((IQueryable<object>)Context.DataObjects).ToList() : Context.DataObjects as IList; var data = Context.DataObjects as IList; if (data?.Count > 0) { foreach (var elem in data) { var val = elem.NccGetPropertyValue <string>(Context.DataValue); var txt = elem.NccGetPropertyValue <string>(Context.TextValue); var select = new TagBuilder("option") { Attributes = { { "value", val } } }; select.InnerHtml.Append(txt); if (val == SelectedValue) { select.Attributes.Add("selected", "selected"); } service?.NccInvokeMethod(NccSelectEventsEnum.OptionBound.ToString(), new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext, DataObjects = Context.DataObjects } }); output.Content.AppendHtml(select); } } else { output.Attributes.Add("disabled", "disabled"); } service?.NccInvokeMethod(NccEventsEnum.PreRender, new object[] { new NccEventArgs { NccControlContext = Context, ViewContext = ViewContext } }); output.PostContent.AppendHtml(NccControlsService.GetEncodedContext(_protector, Context.Id, Context)); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderOverlay()); output.PostContent.AppendHtml(NccControlsService.GetAjaxLoaderImage()); var divContainer = new TagBuilder("div") { Attributes = { { "id", Context.Id }, { "style", "position:relative" } }, TagRenderMode = TagRenderMode.StartTag }; output.PreElement.AppendHtml(divContainer); var endDivContainer = new TagBuilder("div") { TagRenderMode = TagRenderMode.EndTag }; output.PostElement.AppendHtml(endDivContainer); } }