public override async void Update(NccEventArgs eventArgs) { try { var dataAccess = (IDataAccess)eventArgs.Controller.HttpContext.RequestServices.GetService(typeof(IDataAccess)); var gridContext = (NccGridContext)eventArgs.NccControlContext; if (gridContext == null) { throw new Exception("Could not obtain NccGridContext to process Update. Wrong control type?"); } var model = new List <Products>(); var ok = await eventArgs.Controller.TryUpdateModelAsync(model, gridContext.Id); if (!ok) { throw new Exception("Error binding model to object or list"); } ok = NccEventService.NccBindDataKeys(model, gridContext.DataKeysValues); if (!ok) { throw new Exception("DataKeys list is bigger than submited list. No match possible!!"); } foreach (var product in model) { dataAccess.UpdateProduct(product); } eventArgs.Controller.ViewBag.Message = "All grid products updated successfully!"; eventArgs.Controller.ViewBag.MessageType = "success"; } catch (Exception e) { eventArgs.Controller.ViewBag.Message = "An error occured updating products info!"; eventArgs.Controller.ViewBag.MessageType = "danger"; } }
public virtual void PreRender(NccEventArgs eventArgs) { }
public virtual void PostBack(NccEventArgs eventArgs) { }
/// <summary> /// Properties available: /// - /// - ViewContext /// </summary> /// <param name="eventArgs"></param> public virtual void Load(NccEventArgs eventArgs) { eventArgs.NccControlContext.NccSetPropertyValue("Visible", true); }
public virtual void DataBound(NccEventArgs eventArgs) { }
public virtual async void Update(NccEventArgs eventArgs) { var detailsContext = (NccDetailsContext)eventArgs.NccControlContext; if (detailsContext == null) { return; } var type = Type.GetType(detailsContext.DatabaseModelType); if (type == null) { throw new Exception("The DatabaseModelType was incorrectly set. Please correct it on the Grid context."); } dynamic model = Activator.CreateInstance(type); if (model == null) { throw new Exception("The DatabaseModelType specified could not be instantiated. Is it public?"); } var ok = await eventArgs.Controller.TryUpdateModelAsync(model, detailsContext.Id); if (!ok) { throw new Exception("Error binding model to object or list"); } ok = NccEventService.NccBindDataKeys(model, detailsContext.DataKeysValues, 0); if (!ok) { throw new Exception("DataKeys list is bigger than submited list. No match possible!!"); } if (model == null) { throw new Exception("It was not possible to bind the forms value to model."); } var options = NccReflectionService.NccGetClassInstanceWithDi(eventArgs.Controller.HttpContext, NccConstants.OptionsAssemblyName); var nccSettings = options != null ? ((IOptions <NccSettings>)options).Value : new NccSettings(); var dbService = nccSettings.UseDependencyInjection ? NccReflectionService.NccGetClassInstanceWithDi(eventArgs.Controller.HttpContext, detailsContext.DataAccessClass) : NccReflectionService.NccGetClassInstance(detailsContext.DataAccessClass, detailsContext.DataAccessParameters); if (dbService == null) { throw new Exception("Could not get an instance of DataAccessClass. Wrong assembly full name?"); } var updateParameters = detailsContext.UpdateParameters?.ToDictionary(x => x.Key, x => x.Value).NccToExpando() ?? new ExpandoObject() as IDictionary <string, object>; updateParameters["model"] = model; try { var result = dbService.NccInvokeMethod(detailsContext.UpdateMethod, (ExpandoObject)updateParameters); eventArgs.Controller.ViewBag.Message = "Updated successfully!"; eventArgs.Controller.ViewBag.MessageType = "success"; } catch (Exception) { eventArgs.Controller.ViewBag.Message = "An error occured!"; eventArgs.Controller.ViewBag.MessageType = "danger"; } }
public virtual void ItemDataBound(NccEventArgs eventArgs, object itemData) { }
public virtual void DeleteRow(NccEventArgs eventArgs, int rowPos) { }
public virtual void RowCreated(NccEventArgs eventArgs, GridRow row) { }
public virtual void RowDataBound(NccEventArgs eventArgs, object rowData) { }
public virtual void Update(NccEventArgs eventArgs) { }
public virtual void OptionBound(NccEventArgs eventArgs, object elemData, TagBuilder tag) { }