Exemple #1
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            _isAuthenticated = base.AuthorizeCore(httpContext);
            if (_isAuthenticated)
            {
                if (string.IsNullOrEmpty(Groups))
                {
                    _isAuthorized = true;
                    return(_isAuthorized);
                }

                var groups   = Groups.Split(',');
                var username = httpContext.User.Identity.Name;

                try
                {
                    _isAuthorized = GroupsHelper.UserIsMemberOfGroups(username, groups);
                    return(_isAuthorized);
                }
                catch (Exception exception)
                {
                    throw exception;

                    //_isAuthorized = false;
                    //return _isAuthorized;
                }
            }

            _isAuthorized = false;

            return(_isAuthorized);
        }
        public async Task <int> AssignMembers(int groupId, AssignScope scope, string search = null)
        {
            if (!string.IsNullOrWhiteSpace(search))
            {
                search = UsersHelper.ReplaceWildcardCharacters(search);
            }

            var parameters = new DynamicParameters();

            parameters.Add("@GroupId", groupId);
            parameters.Add("@GroupsIds", SqlConnectionWrapper.ToDataTable(GroupsHelper.ParsingTypesToUserTypeArray(scope.Members, UserType.Group)));
            parameters.Add("@UsersIds", SqlConnectionWrapper.ToDataTable(GroupsHelper.ParsingTypesToUserTypeArray(scope.Members, UserType.User)));
            parameters.Add("@SelectAll", scope.SelectAll);
            parameters.Add("@Search", search);
            parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output);
            var result = await _connectionWrapper.ExecuteScalarAsync <int>("AssignGroupMembers", parameters, commandType : CommandType.StoredProcedure);

            var errorCode = parameters.Get <int?>("ErrorCode");

            if (errorCode.HasValue)
            {
                switch (errorCode.Value)
                {
                case (int)SqlErrorCodes.GroupWithCurrentIdNotExist:
                    throw new ResourceNotFoundException(ErrorMessages.GroupNotExist, ErrorCodes.ResourceNotFound);

                case (int)SqlErrorCodes.GeneralSqlError:
                    throw new Exception(ErrorMessages.GeneralErrorOfUpdatingGroup);
                }
            }

            return(result);
        }
        public async Task <int> DeleteMembersFromGroupAsync(int groupId, AssignScope body)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@GroupId", groupId);
            parameters.Add("@GroupsIds", SqlConnectionWrapper.ToDataTable(GroupsHelper.ParsingTypesToUserTypeArray(body.Members, UserType.Group)));
            parameters.Add("@UsersIds", SqlConnectionWrapper.ToDataTable(GroupsHelper.ParsingTypesToUserTypeArray(body.Members, UserType.User)));
            parameters.Add("@SelectAll", body.SelectAll);
            parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output);

            var result = await _connectionWrapper.ExecuteScalarAsync <int>("DeleteMembersFromGroup", parameters, commandType : CommandType.StoredProcedure);

            var errorCode = parameters.Get <int?>("ErrorCode");

            if (errorCode.HasValue)
            {
                switch (errorCode.Value)
                {
                case (int)SqlErrorCodes.GeneralSqlError:
                    throw new Exception(ErrorMessages.GeneralErrorOfRemovingMembersFromGroup);

                case (int)SqlErrorCodes.GroupWithCurrentIdNotExist:
                    throw new ResourceNotFoundException(ErrorMessages.GroupNotExist, ErrorCodes.ResourceNotFound);
                }
            }

            return(result);
        }
        public JsonResult TransactionListNoDT_DatasourceAggregators()
        {
            object aggregatorsResponse = null;
            var    postedData          = _LoadViewModel();
            var    datasourceRequest   = DeserializeDatasourceRequest(postedData["datasourceRequest"].ToString());
            var    queryable           = Get_TransactionListNoDT_DatasourceQueryable(datasourceRequest);

            queryable = DatasourceRetriever.ApplyDynamicFilterToQueryable(datasourceRequest, queryable);
            var formattings = new Dictionary <string, string>();

            formattings.Add("TransactionDateOccured", "dd/MM/yyyy");
            formattings.Add("TransactionValue", "#,0.00;'-'#,0.00;'0'");
            formattings.Add("FundedAmount", "#,0.00;'-'#,0.00;'0'");
            formattings.Add("ToBePaidAmount", "#,0.00;'-'#,0.00;'0'");
            formattings.Add("PaymentDate", "dd/MM/yyyy");
            formattings.Add("RestPaymentAmount", "#,0.00;'-'#,0.00;'0'");
            if (datasourceRequest.GroupBy.Any() /* && datasourceRequest.GroupBy.First().GetGroupsClosed*/)
            {
                var groups = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, postedData, true);
                GroupsHelper.FormatGroupedAggregators(groups, formattings);
                aggregatorsResponse = new ListResponse()
                {
                    Groups = groups
                };
            }
            else
            {
                var aggregatorsInfo = DeserializeAggregatorsRequest <DSS5_SupplyChainFinancialsOptimisation.BO.Transaction>(postedData["aggregatorsRequest"].ToString());
                var aggregators     = RuntimePredicateBuilder.BuildAggregatorPredicates(aggregatorsInfo);
                foreach (var a in aggregators)
                {
                    var formatting = formattings.ContainsKey(a.Column) ? formattings[a.Column] : null;
                    a.Calculate(queryable, formatting);
                }
                aggregatorsResponse = aggregators;
            }
            var __result = Json(new
            {
                Type = "DatasourceData", Data = Serialize(aggregatorsResponse)
            }, JsonRequestBehavior.AllowGet);

            __result.MaxJsonLength = int.MaxValue;
            return(__result);
        }
Exemple #5
0
        public JsonResult List_DatasourceAggregators()
        {
            object aggregatorsResponse = null;
            var    postedData          = _LoadViewModel();
            var    datasourceRequest   = DeserializeDatasourceRequest(postedData["datasourceRequest"].ToString());
            var    queryable           = Get_List_DatasourceQueryable(datasourceRequest);

            queryable = DatasourceRetriever.ApplyDynamicFilterToQueryable(datasourceRequest, queryable);
            var formattings = new Dictionary <string, string>();

            formattings.Add("OrderForecast_CreatedOn", "dd/MM/yyyy");
            formattings.Add("OrderForecast_StartDate", "dd/MM/yyyy");
            formattings.Add("OrderForecast_EndDate", "dd/MM/yyyy");
            formattings.Add("RecommendedOrderDate", "dd/MM/yyyy");
            formattings.Add("SalesForecastDate", "dd/MM/yyyy");
            if (datasourceRequest.GroupBy.Any() /* && datasourceRequest.GroupBy.First().GetGroupsClosed*/)
            {
                var groups = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, postedData, true);
                GroupsHelper.FormatGroupedAggregators(groups, formattings);
                aggregatorsResponse = new ListResponse()
                {
                    Groups = groups
                };
            }
            else
            {
                var aggregatorsInfo = DeserializeAggregatorsRequest <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>(postedData["aggregatorsRequest"].ToString());
                var aggregators     = RuntimePredicateBuilder.BuildAggregatorPredicates(aggregatorsInfo);
                foreach (var a in aggregators)
                {
                    var formatting = formattings.ContainsKey(a.Column) ? formattings[a.Column] : null;
                    a.Calculate(queryable, formatting);
                }
                aggregatorsResponse = aggregators;
            }
            var __result = Json(new
            {
                Type = "DatasourceData", Data = Serialize(aggregatorsResponse)
            }, JsonRequestBehavior.AllowGet);

            __result.MaxJsonLength = int.MaxValue;
            return(__result);
        }
        public JsonResult List_DatasourceAggregators()
        {
            object aggregatorsResponse = null;
            var    postedData          = _LoadViewModel();
            var    datasourceRequest   = DeserializeDatasourceRequest(postedData["datasourceRequest"].ToString());
            var    queryable           = Get_List_DatasourceQueryable(datasourceRequest);

            queryable = DatasourceRetriever.ApplyDynamicFilterToQueryable(datasourceRequest, queryable);
            var formattings = new Dictionary <string, string>();

            if (datasourceRequest.GroupBy.Any() /* && datasourceRequest.GroupBy.First().GetGroupsClosed*/)
            {
                var groups = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, postedData, true);
                GroupsHelper.FormatGroupedAggregators(groups, formattings);
                aggregatorsResponse = new ListResponse()
                {
                    Groups = groups
                };
            }
            else
            {
                var aggregatorsInfo = DeserializeAggregatorsRequest <zAppDev.DotNet.Framework.Identity.Model.ApplicationOperation>(postedData["aggregatorsRequest"].ToString());
                var aggregators     = RuntimePredicateBuilder.BuildAggregatorPredicates(aggregatorsInfo);
                foreach (var a in aggregators)
                {
                    var formatting = formattings.ContainsKey(a.Column) ? formattings[a.Column] : null;
                    a.Calculate(queryable, formatting);
                }
                aggregatorsResponse = aggregators;
            }
            var __result = Json(new
            {
                Type = "DatasourceData", Data = Serialize(aggregatorsResponse)
            }, JsonRequestBehavior.AllowGet);

            __result.MaxJsonLength = int.MaxValue;
            return(__result);
        }
        public string List_ExportV2Implementation(DatasourceRequest datasourceRequest, ExportOptionsV2 exportOptions, List <AggregatorInfo <zAppDev.DotNet.Framework.Identity.Model.ApplicationOperation> > aggregatorsInfo)
        {
            var  watch = System.Diagnostics.Stopwatch.StartNew();
            long elapsedMilliseconds = 0;

            switch (exportOptions.Range)
            {
            case ExportHelper.Range.ALL:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = int.MaxValue;
                break;

            case ExportHelper.Range.TOP100:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = 100;
                break;
            }
            var queryable    = Get_List_DatasourceQueryable(datasourceRequest);
            var formattings  = new Dictionary <string, string>();
            var path         = "";
            var exportHelper = new ExportHelperV2 <zAppDev.DotNet.Framework.Identity.Model.ApplicationOperation>(exportOptions, new Dictionary <string, Func <zAppDev.DotNet.Framework.Identity.Model.ApplicationOperation, object> >
            {
                { "ParentControllerName", item => item?.ParentControllerName }, { "Name", item => item?.Name }, { "IsAvailableToAllAuthorizedUsers", item => item?.IsAvailableToAllAuthorizedUsers }, { "IsAvailableToAnonymous", item => item?.IsAvailableToAnonymous },
            });

            if (exportHelper.Options.ColumnInfo == null)
            {
                exportHelper.Options.ColumnInfo = new List <ColumnOptionsV2>
                {
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("OperationsList", "RES_LIST_List_COLUMN_ParentControllerName"), Formatting = "", Name = "ParentControllerName", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("OperationsList", "RES_LIST_List_COLUMN_Name"), Formatting = "", Name = "Name", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("OperationsList", "RES_LIST_List_COLUMN_IsAvailableToAllAuthorizedUsers"), Formatting = "", Name = "IsAvailableToAllAuthorizedUsers", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("OperationsList", "RES_LIST_List_COLUMN_IsAvailableToAnonymous"), Formatting = "", Name = "IsAvailableToAnonymous", ExcelFormat = @""
                    },
                };
            }
            if (string.IsNullOrWhiteSpace(exportHelper.Options.Filename))
            {
                exportHelper.Options.Filename = "List";
            }
            if (datasourceRequest.GroupBy.Any())
            {
                var groups      = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, aggregatorsInfo);
                var aggregators = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, aggregatorsInfo, true);
                GroupsHelper.FormatGroupedAggregators(aggregators, formattings);
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: List export query with grouping and range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(groups, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: List export to excel with grouping and range {exportOptions.Range} took {watch.ElapsedMilliseconds}ms");
            }
            else
            {
                var items       = DatasourceRetriever.Retrieve(datasourceRequest, queryable);;
                var aggregators = RuntimePredicateBuilder.BuildAggregatorPredicates(aggregatorsInfo);
                foreach (var a in aggregators)
                {
                    var formatting = formattings.ContainsKey(a.Column) ? formattings[a.Column] : null;
                    a.Calculate(queryable, formatting);
                }
                var loadedItems = items.ToList();
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: List export query with range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(loadedItems, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: List export to excel with range {exportOptions.Range} took {elapsedMilliseconds}ms");
            }
            var content     = System.IO.File.ReadAllBytes(Path.Combine(Path.GetTempPath(), path));
            var fileName    = Path.GetFileName(path);
            var downloadKey = FileHelper.PendingDownloadInstance.Add("OperationsList", content, fileName);

            _logger.Info($"ExportV2 Performance: Total export time for List: {elapsedMilliseconds}ms");
            return(downloadKey);
        }
        public string DeliveryNoteListNoDT_ExportV2Implementation(DatasourceRequest datasourceRequest, ExportOptionsV2 exportOptions, List <AggregatorInfo <DSS5_SupplyChainFinancialsOptimisation.BO.DeliveryNote> > aggregatorsInfo)
        {
            var  watch = System.Diagnostics.Stopwatch.StartNew();
            long elapsedMilliseconds = 0;

            switch (exportOptions.Range)
            {
            case ExportHelper.Range.ALL:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = int.MaxValue;
                break;

            case ExportHelper.Range.TOP100:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = 100;
                break;
            }
            var queryable    = Get_DeliveryNoteListNoDT_DatasourceQueryable(datasourceRequest);
            var formattings  = new Dictionary <string, string>();
            var path         = "";
            var exportHelper = new ExportHelperV2 <DSS5_SupplyChainFinancialsOptimisation.BO.DeliveryNote>(exportOptions, new Dictionary <string, Func <DSS5_SupplyChainFinancialsOptimisation.BO.DeliveryNote, object> >
            {
                { "Transaction.Id", item => item?.Transaction?.Id }, { "DeliveryNoteNumber", item => item?.DeliveryNoteNumber }, { "Description", item => item?.Description }, { "DateIssued", item => item?.DateIssued }, { "Amount", item => item?.Amount }, { "Transaction.Supplier.Company", item => item?.Transaction?.Supplier?.Company },
            });

            if (exportHelper.Options.ColumnInfo == null)
            {
                exportHelper.Options.ColumnInfo = new List <ColumnOptionsV2>
                {
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("AdminDeliveryNoteList", "RES_LIST_DeliveryNoteListNoDT_COLUMN_Transaction.Id"), Formatting = "", Name = "Transaction.Id", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("AdminDeliveryNoteList", "RES_LIST_DeliveryNoteListNoDT_COLUMN_DeliveryNoteNumber"), Formatting = "", Name = "DeliveryNoteNumber", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("AdminDeliveryNoteList", "RES_LIST_DeliveryNoteListNoDT_COLUMN_Description"), Formatting = "", Name = "Description", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("AdminDeliveryNoteList", "RES_LIST_DeliveryNoteListNoDT_COLUMN_DateIssued"), Formatting = "dd/MM/yyyy", Name = "DateIssued", ExcelFormat = @"dd/MM/yyyy"
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("AdminDeliveryNoteList", "RES_LIST_DeliveryNoteListNoDT_COLUMN_Amount"), Formatting = "#,0.00;'-'#,0.00;'0'", Name = "Amount", ExcelFormat = @"#,##0.00;-#,##0.00;#,##0.00"
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("AdminDeliveryNoteList", "RES_LIST_DeliveryNoteListNoDT_COLUMN_Transaction.Supplier.Company"), Formatting = "", Name = "Transaction.Supplier.Company", ExcelFormat = @""
                    },
                };
            }
            if (string.IsNullOrWhiteSpace(exportHelper.Options.Filename))
            {
                exportHelper.Options.Filename = "DeliveryNoteListNoDT";
            }
            if (datasourceRequest.GroupBy.Any())
            {
                var groups      = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, aggregatorsInfo);
                var aggregators = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, aggregatorsInfo, true);
                GroupsHelper.FormatGroupedAggregators(aggregators, formattings);
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: DeliveryNoteListNoDT export query with grouping and range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(groups, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: DeliveryNoteListNoDT export to excel with grouping and range {exportOptions.Range} took {watch.ElapsedMilliseconds}ms");
            }
            else
            {
                var items       = DatasourceRetriever.Retrieve(datasourceRequest, queryable);;
                var aggregators = RuntimePredicateBuilder.BuildAggregatorPredicates(aggregatorsInfo);
                foreach (var a in aggregators)
                {
                    var formatting = formattings.ContainsKey(a.Column) ? formattings[a.Column] : null;
                    a.Calculate(queryable, formatting);
                }
                var loadedItems = items.ToList();
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: DeliveryNoteListNoDT export query with range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(loadedItems, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: DeliveryNoteListNoDT export to excel with range {exportOptions.Range} took {elapsedMilliseconds}ms");
            }
            var content     = System.IO.File.ReadAllBytes(Path.Combine(Path.GetTempPath(), path));
            var fileName    = Path.GetFileName(path);
            var downloadKey = FileHelper.PendingDownloadInstance.Add("AdminDeliveryNoteList", content, fileName);

            _logger.Info($"ExportV2 Performance: Total export time for DeliveryNoteListNoDT: {elapsedMilliseconds}ms");
            return(downloadKey);
        }
Exemple #9
0
 public GroupsController(GroupsHelper groupsHelper)
 {
     _groupsHelper = groupsHelper;
 }
        public string SupplierListNoDT_ExportV2Implementation(DatasourceRequest datasourceRequest, ExportOptionsV2 exportOptions, List <AggregatorInfo <DSS5_SupplyChainFinancialsOptimisation.BO.Supplier> > aggregatorsInfo)
        {
            var  watch = System.Diagnostics.Stopwatch.StartNew();
            long elapsedMilliseconds = 0;

            switch (exportOptions.Range)
            {
            case ExportHelper.Range.ALL:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = int.MaxValue;
                break;

            case ExportHelper.Range.TOP100:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = 100;
                break;
            }
            var queryable    = Get_SupplierListNoDT_DatasourceQueryable(datasourceRequest);
            var formattings  = new Dictionary <string, string>();
            var path         = "";
            var exportHelper = new ExportHelperV2 <DSS5_SupplyChainFinancialsOptimisation.BO.Supplier>(exportOptions, new Dictionary <string, Func <DSS5_SupplyChainFinancialsOptimisation.BO.Supplier, object> >
            {
                { "UserName", item => item?.UserName }, { "Company", item => item?.Company }, { "Business", item => item?.Business }, { "PercentageOfCreditNotes", item => item?.PercentageOfCreditNotes }, { "AcceptedPolicyTerms", item => item?.AcceptedPolicyTerms }, { "SupplierStatus", item => item?.SupplierStatus },
            });

            if (exportHelper.Options.ColumnInfo == null)
            {
                exportHelper.Options.ColumnInfo = new List <ColumnOptionsV2>
                {
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("PendingRegisteredSuppliersList", "RES_LIST_SupplierListNoDT_COLUMN_UserName"), Formatting = "", Name = "UserName", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("PendingRegisteredSuppliersList", "RES_LIST_SupplierListNoDT_COLUMN_Company"), Formatting = "", Name = "Company", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("PendingRegisteredSuppliersList", "RES_LIST_SupplierListNoDT_COLUMN_Business"), Formatting = "", Name = "Business", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("PendingRegisteredSuppliersList", "RES_LIST_SupplierListNoDT_COLUMN_PercentageOfCreditNotes"), Formatting = "", Name = "PercentageOfCreditNotes", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("PendingRegisteredSuppliersList", "RES_LIST_SupplierListNoDT_COLUMN_AcceptedPolicyTerms"), Formatting = "", Name = "AcceptedPolicyTerms", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("PendingRegisteredSuppliersList", "RES_LIST_SupplierListNoDT_COLUMN_SupplierStatus"), Formatting = "", Name = "SupplierStatus", ExcelFormat = @""
                    },
                };
            }
            if (string.IsNullOrWhiteSpace(exportHelper.Options.Filename))
            {
                exportHelper.Options.Filename = "SupplierListNoDT";
            }
            if (datasourceRequest.GroupBy.Any())
            {
                var groups      = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.UserName, aggregatorsInfo);
                var aggregators = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.UserName, aggregatorsInfo, true);
                GroupsHelper.FormatGroupedAggregators(aggregators, formattings);
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: SupplierListNoDT export query with grouping and range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(groups, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: SupplierListNoDT export to excel with grouping and range {exportOptions.Range} took {watch.ElapsedMilliseconds}ms");
            }
            else
            {
                var items       = DatasourceRetriever.Retrieve(datasourceRequest, queryable);;
                var aggregators = RuntimePredicateBuilder.BuildAggregatorPredicates(aggregatorsInfo);
                foreach (var a in aggregators)
                {
                    var formatting = formattings.ContainsKey(a.Column) ? formattings[a.Column] : null;
                    a.Calculate(queryable, formatting);
                }
                var loadedItems = items.ToList();
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: SupplierListNoDT export query with range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(loadedItems, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: SupplierListNoDT export to excel with range {exportOptions.Range} took {elapsedMilliseconds}ms");
            }
            var content     = System.IO.File.ReadAllBytes(Path.Combine(Path.GetTempPath(), path));
            var fileName    = Path.GetFileName(path);
            var downloadKey = FileHelper.PendingDownloadInstance.Add("PendingRegisteredSuppliersList", content, fileName);

            _logger.Info($"ExportV2 Performance: Total export time for SupplierListNoDT: {elapsedMilliseconds}ms");
            return(downloadKey);
        }
Exemple #11
0
        public string OrderProposalList_ExportV2Implementation(DatasourceRequest datasourceRequest, ExportOptionsV2 exportOptions, List <AggregatorInfo <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails> > aggregatorsInfo)
        {
            var  watch = System.Diagnostics.Stopwatch.StartNew();
            long elapsedMilliseconds = 0;

            switch (exportOptions.Range)
            {
            case ExportHelper.Range.ALL:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = int.MaxValue;
                break;

            case ExportHelper.Range.TOP100:
                datasourceRequest.StartRow = 0;
                datasourceRequest.PageSize = 100;
                break;
            }
            var queryable    = Get_OrderProposalList_DatasourceQueryable(datasourceRequest);
            var formattings  = new Dictionary <string, string>();
            var path         = "";
            var exportHelper = new ExportHelperV2 <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails>(exportOptions, new Dictionary <string, Func <DSS1_RetailerDriverStockOptimisation.BO.OrderForecastDetails, object> >
            {
                { "Item.SKU", item => item?.Item?.SKU }, { "Item.Description", item => item?.Item?.Description }, { "Warehouse.Description", item => item?.Warehouse?.Description }, { "Quantity", item => item?.Quantity }, { "RecommendedOrderDate", item => item?.RecommendedOrderDate }, { "SalesForecastDate", item => item?.SalesForecastDate }, { "SupplierCanDeliver", item => item?.SupplierCanDeliver }, { "SupplierMaxQuantity", item => item?.SupplierMaxQuantity },
            });

            if (exportHelper.Options.ColumnInfo == null)
            {
                exportHelper.Options.ColumnInfo = new List <ColumnOptionsV2>
                {
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_Item.SKU"), Formatting = "", Name = "Item.SKU", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_Item.Description"), Formatting = "", Name = "Item.Description", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_Warehouse.Description"), Formatting = "", Name = "Warehouse.Description", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_Quantity"), Formatting = "", Name = "Quantity", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_RecommendedOrderDate"), Formatting = "dd/MM/yyyy", Name = "RecommendedOrderDate", ExcelFormat = @"dd/MM/yyyy"
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_SalesForecastDate"), Formatting = "dd/MM/yyyy", Name = "SalesForecastDate", ExcelFormat = @"dd/MM/yyyy"
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_SupplierCanDeliver"), Formatting = "", Name = "SupplierCanDeliver", ExcelFormat = @""
                    },
                    new ColumnOptionsV2 {
                        Caption = BaseViewPage <object> .GetResourceValue("SupplierOrderForecast", "RES_LIST_OrderProposalList_COLUMN_SupplierMaxQuantity"), Formatting = "", Name = "SupplierMaxQuantity", ExcelFormat = @""
                    },
                };
            }
            if (string.IsNullOrWhiteSpace(exportHelper.Options.Filename))
            {
                exportHelper.Options.Filename = "OrderProposalList";
            }
            if (datasourceRequest.GroupBy.Any())
            {
                var groups      = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, aggregatorsInfo);
                var aggregators = DatasourceRetriever.RetrieveGrouped(datasourceRequest, queryable, q => q.Id, aggregatorsInfo, true);
                GroupsHelper.FormatGroupedAggregators(aggregators, formattings);
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: OrderProposalList export query with grouping and range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(groups, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: OrderProposalList export to excel with grouping and range {exportOptions.Range} took {watch.ElapsedMilliseconds}ms");
            }
            else
            {
                var items       = DatasourceRetriever.Retrieve(datasourceRequest, queryable);;
                var aggregators = RuntimePredicateBuilder.BuildAggregatorPredicates(aggregatorsInfo);
                foreach (var a in aggregators)
                {
                    var formatting = formattings.ContainsKey(a.Column) ? formattings[a.Column] : null;
                    a.Calculate(queryable, formatting);
                }
                var loadedItems = items.ToList();
                watch.Stop();
                elapsedMilliseconds = watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: OrderProposalList export query with range {exportOptions.Range} took {elapsedMilliseconds}ms");
                watch.Restart();
                path = exportHelper.Export(loadedItems, aggregators);
                watch.Stop();
                elapsedMilliseconds += watch.ElapsedMilliseconds;
                _logger.Info($"ExportV2 Performance: OrderProposalList export to excel with range {exportOptions.Range} took {elapsedMilliseconds}ms");
            }
            var content     = System.IO.File.ReadAllBytes(Path.Combine(Path.GetTempPath(), path));
            var fileName    = Path.GetFileName(path);
            var downloadKey = FileHelper.PendingDownloadInstance.Add("SupplierOrderForecast", content, fileName);

            _logger.Info($"ExportV2 Performance: Total export time for OrderProposalList: {elapsedMilliseconds}ms");
            return(downloadKey);
        }