示例#1
0
        public ActionResult Handle(PowerTablesData data, IResponseModifiersApplier responseModifiers)
        {
            // queryable reveals here
            var mapped = data.Mapped.Value;
            PowerTablesResponse ptr = new PowerTablesResponse()
            {
                PageIndex      = data.CurrentPage,
                ResultsCount   = data.ResultsCount,
                Data           = data.Configuration.EncodeResults(mapped),
                AdditionalData = new Dictionary <string, object>(),
                Success        = false
            };

            try
            {
                responseModifiers.ApplyResponseModifiers(data, ptr);
            }
            catch (Exception ex)
            {
                ptr.FormatException(ex);
            }

            ptr.Success = true;
            return(new JsonNetResult()
            {
                Data = ptr, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#2
0
 public void ModifyResponse(PowerTablesData data, PowerTablesResponse response)
 {
     if (_action != null)
     {
         _action(data, response);
     }
 }
示例#3
0
        public async Task <ActionResult> HandleAsync(PowerTablesData data, IResponseModifiersApplier responseModifiers)
        {
            PowerTablesData <TSourceData, TTargetData> typedData = new PowerTablesData <TSourceData, TTargetData>(data);
            TResponse response;

            if (_asynchandlerMethod != null)
            {
                response = await _asynchandlerMethod(typedData).ConfigureAwait(false);
            }
            else
            {
                response = _handlerMethod(typedData);
            }

            if (typeof(PowerTablesResponse).IsAssignableFrom(typeof(TResponse)))
            {
                responseModifiers.ApplyResponseModifiers(data, (PowerTablesResponse)(object)response);
            }
            var o = response as ActionResult;

            if (o != null)
            {
                return(o);
            }
            return(new JsonNetResult()
            {
                Data = response, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#4
0
        public ActionResult Handle(PowerTablesData data, IResponseModifiersApplier responseModifiers)
        {
            if (_handlerMethod == null)
            {
                throw new Exception("This is asynchronous command handler. Please use it with .HandleAsync, not .Handle.");
            }

            PowerTablesData <TSourceData, TTargetData> typedData = new PowerTablesData <TSourceData, TTargetData>(data);
            var response = _handlerMethod(typedData);

            if (typeof(PowerTablesResponse).IsAssignableFrom(typeof(TResponse)))
            {
                responseModifiers.ApplyResponseModifiers(data, (PowerTablesResponse)(object)response);
            }
            var o = response as ActionResult;

            if (o != null)
            {
                return(o);
            }
            return(new JsonNetResult()
            {
                Data = response, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#5
0
        public ActionResult Handle(PowerTablesData data, IResponseModifiersApplier responseModifiers)
        {
            var ar = SelectCheckboxes(data).ToArray();

            return(new JsonNetResult()
            {
                Data = ar, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#6
0
        public OperationResult Delete(PowerTablesData <Toy, Row> request)
        {
            int[] selectedIds = request.Request.GetSelectionIds <int>();
            var   rc          = Data.SourceData.RemoveAll(c => selectedIds.Contains(c.Id));

            return(new OperationResult()
            {
                Message = String.Format("All went ok. {0} items removed", rc), Success = true
            });
        }
示例#7
0
        private IQueryable <string> SelectCheckboxes(PowerTablesData data)
        {
            var column     = data.Request.Query.AdditionalData["SelectionColumn"];
            var columnProp = data.Configuration.SourceType.GetProperty(column);
            var selection  = LambdaHelpers.MemberExpression(columnProp);
            var q          = ReflectionCache.CallSelect(data.Ordered, selection, data.Configuration.SourceType,
                                                        columnProp.PropertyType);

            return(q.Cast <object>().Select(c => c.ToString()));
        }
示例#8
0
        private TableUpdateResult RemoveSelected(PowerTablesData <Toy, Row> arg)
        {
            EditionResult er = new EditionResult();
            var           editResultWrapper = new EditionResultWrapper <Row>(er);
            var           selected          = arg.Request.GetSelectionIds <int>();

            foreach (var i in selected)
            {
                editResultWrapper.Adjustments.Remove(new Row()
                {
                    Id = i
                });
            }
            return(new TableUpdateResult(editResultWrapper));
        }
示例#9
0
        public void ModifyResponse(PowerTablesData data, PowerTablesResponse response)
        {
            TotalResponse tr = new TotalResponse()
            {
                TotalsForColumns = new Dictionary <string, object>()
            };
            var gData = new PowerTablesData <TSourceData, TTableData>(data);

            foreach (var keyValuePair in _calculator.Calculators)
            {
                var result = keyValuePair.Value.DynamicInvoke(gData);
                tr.TotalsForColumns[keyValuePair.Key] = result;
            }
            response.AdditionalData[TotalExtensions.PluginId] = tr;
        }
示例#10
0
        private TableUpdateResult UpdateSelected(PowerTablesData <Toy, Row> arg)
        {
            var           form = arg.Request.ConfirmationForm <SimpleConfirmationModel>();
            EditionResult er   = new EditionResult();
            var           editResultWrapper = new EditionResultWrapper <Row>(er);
            var           selected          = arg.Request.GetSelectionIds <int>();

            foreach (var i in selected)
            {
                var data = Data.SourceData.Single(c => c.Id == i);
                data.ToyName   = form.ToyName;
                data.GroupType = form.ToyType.Value;

                editResultWrapper.Adjustments.AddOrUpdate(arg.Configuration.Map(data));
            }
            return(new TableUpdateResult(editResultWrapper));
        }
示例#11
0
        private void EditData(PowerTablesData <Toy, Row> powerTablesData, EditionResultWrapper <Row> edit)
        {
            edit.ConfirmedObject.Name      = edit.ConfirmedObject.Name + " - Edited";
            edit.ConfirmedObject.TypeOfToy = ToyType.Dolls;

            var idsToUpdate = new[] { 2750, 2747, 2744 };
            var src         = Data.SourceData.Where(c => idsToUpdate.Contains(c.Id)).ToArray();
            var mapped      = powerTablesData.Configuration.MapRange(src);

            foreach (var row in mapped)
            {
                row.Name   = "UFO edited this label";
                row.IsPaid = true;
            }
            edit.Adjustments.AddOrUpdateAll(mapped);
            edit.Message(TableMessage.User("info", "Objects were updated", "Successful"));
        }
示例#12
0
        public ActionResult Handle(PowerTablesData data, IResponseModifiersApplier responseModifiers)
        {
            if (_handlerMethod == null)
            {
                throw new Exception("This is asynchronous command handler. Please use it with .HandleAsync, not .Handle.");
            }

            PowerTablesData <TSourceData, TTargetData> typedData = new PowerTablesData <TSourceData, TTargetData>(data);
            var editionResult = new EditionResult();
            var wrapper       = new EditionResultWrapper <TTargetData>(editionResult);

            wrapper.Confirm(data.Request.RetrieveAdditionalObject <TTargetData>(EditorExtensions.EditAdditionalDataKey));
            _handlerMethod(typedData, wrapper);
            return(new JsonNetResult()
            {
                Data = editionResult, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#13
0
        public async Task <ActionResult> HandleAsync(PowerTablesData data, IResponseModifiersApplier responseModifiers)
        {
            PowerTablesData <TSourceData, TTargetData> typedData = new PowerTablesData <TSourceData, TTargetData>(data);
            var editionResult = new EditionResult();
            var wrapper       = new EditionResultWrapper <TTargetData>(editionResult);

            wrapper.Confirm(data.Request.RetrieveAdditionalObject <TTargetData>(EditorExtensions.EditAdditionalDataKey));
            if (_asynchandlerMethod != null)
            {
                await _asynchandlerMethod(typedData, wrapper).ConfigureAwait(false);
            }
            else
            {
                _handlerMethod(typedData, wrapper);
            }
            return(new JsonNetResult()
            {
                Data = editionResult, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#14
0
 public Task <ActionResult> HandleAsync(PowerTablesData data, IResponseModifiersApplier responseModifiers)
 {
     return(Task.FromResult(Handle(data, responseModifiers)));
 }
示例#15
0
 public FileResult DownloadSome(PowerTablesData <Toy, Row> request)
 {
     return(File(@"K:\Temp\mr-101-20150608-002.csv", "text/csv"));
 }