//[HandleErrorWithJson]
        //[HttpPost]
        //public async Task<ActionResult> Validate(TakeRateParameters parameters)
        //{
        //    var validationResults = Enumerable.Empty<ValidationResult>();

        //    TakeRateParametersValidator.ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.TakeRateIdentifier);

        //    var filter = TakeRateFilter.FromTakeRateParameters(parameters);
        //    filter.Action = TakeRateDataItemAction.Validate;
        //    var takeRateView = await TakeRateViewModel.GetModel(DataContext, filter);

        //    try
        //    {
        //        var interimResults = Validator.Validate(takeRateView.RawData);
        //        validationResults = await Validator.Persist(DataContext, filter, interimResults);
        //    }
        //    catch (ValidationException vex)
        //    {
        //        // Just in case someone has thrown an exception from the validation, which we don't actually want
        //        Log.Warning(vex);
        //    }
        //    catch (Exception ex)
        //    {
        //        Log.Error(ex);
        //    }

        //    return JsonGetSuccess(validationResults);
        //}

        public ActionResult IgnoreValidationError(TakeRateParameters parameters)
        {
            TakeRateParametersValidator.ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.TakeRateIdentifier);
            DataContext.TakeRate.IgnoreValidationError(TakeRateFilter.FromTakeRateParameters(parameters));

            return(RedirectToRoute("TakeRateDataByMarket", new { takeRateId = parameters.TakeRateId, marketId = parameters.MarketId }));
        }
        private static async Task <IEnumerable <FdpModel> > ListAvailableModels(IDataContext context, TakeRateDocument forVolume)
        {
            var filteredModels = Enumerable.Empty <FdpModel>();

            if (forVolume.UnderlyingOxoDocument is EmptyOxoDocument || forVolume.Vehicle is EmptyVehicle)
            {
                return(filteredModels);
            }

            var filter = new TakeRateFilter()
            {
                TakeRateId  = forVolume.TakeRateId,
                ProgrammeId = forVolume.UnderlyingOxoDocument.ProgrammeId,
                Gateway     = forVolume.UnderlyingOxoDocument.Gateway,
                DocumentId  = forVolume.UnderlyingOxoDocument.Id,
                PageSize    = forVolume.PageSize,
                PageIndex   = forVolume.PageIndex,
                BMC         = forVolume.BMC,
                DPCK        = forVolume.DPCK,
                FeatureCode = forVolume.FeatureCode
            };

            filteredModels = (await context.Market.ListAvailableModelsByMarket(filter));

            // Bit of a hack here. We have introduced model level paging and the easiest way to return the page values is in the original filter object

            forVolume.TotalRecords        = filter.TotalRecords;
            forVolume.TotalDisplayRecords = filter.TotalDisplayRecords;
            forVolume.TotalPages          = filter.TotalPages;

            return(filteredModels);
        }
        public async Task <ActionResult> ListTakeRates(TakeRateParameters parameters)
        {
            TakeRateParametersValidator
            .ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.NoValidation);

            var js     = new JavaScriptSerializer();
            var filter = new TakeRateFilter()
            {
                FilterMessage    = parameters.FilterMessage,
                TakeRateStatusId = parameters.TakeRateStatusId,
                Action           = TakeRateDataItemAction.TakeRates
            };

            filter.InitialiseFromJson(parameters);

            var results = await TakeRateViewModel.GetModel(DataContext, filter);

            var jQueryResult = new JQueryDataTableResultModel(results);

            foreach (var result in results.TakeRates.CurrentPage)
            {
                jQueryResult.aaData.Add(result.ToJQueryDataTableResult());
            }

            return(Json(jQueryResult));
        }
        public async Task <JsonResult> TakeRateFeatureData(TakeRateParameters parameters)
        {
            Log.Debug(MethodBase.GetCurrentMethod().Name);

            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.TakeRateDataPage;
            var model = await TakeRateViewModel.GetModel(DataContext, filter);

            var rows = new List <Dictionary <string, object> >();

            foreach (DataRow dr in model.Document.TakeRateData.RawData.Rows)
            {
                var row = new Dictionary <string, object>();
                foreach (DataColumn col in model.Document.TakeRateData.RawData.Columns)
                {
                    row.Add(col.ColumnName, dr[col]);
                }
                rows.Add(row);
            }

            Response.AddHeader("Content-Encoding", "gzip");
            Response.Filter = new GZipStream(Response.Filter,
                                             CompressionMode.Compress);

            return(Json(new
            {
                FeatureData = rows,
                model.Document.Market
            }));
        }
 public static IEnumerable <ValidationResult> Persist(IDataContext context,
                                                      TakeRateFilter filter,
                                                      FluentValidation.Results.ValidationResult results,
                                                      bool global)
 {
     return(context.TakeRate.PersistValidationErrors(filter, results, global));
 }
        public async Task <ActionResult> Clone(TakeRateParameters parameters)
        {
            var filter = TakeRateFilter.FromTakeRateParameters(parameters);
            var clone  = await DataContext.TakeRate.CloneTakeRateDocument(filter);

            // Revalidate the clone, as the new document may have different feature applicability
            filter = new TakeRateFilter()
            {
                TakeRateId = clone.TakeRateId
            };

            var markets = await DataContext.Market.ListMarkets(filter);

            foreach (var market in markets)
            {
                try
                {
                    filter.MarketId = market.Id;
                    var rawData = await DataContext.TakeRate.GetRawData(filter);

                    //var validationResults = Validator.Validate(rawData);
                    //Validator.Persist(DataContext, filter, validationResults);
                }
                catch (ValidationException vex)
                {
                    // Sink the exception, as we don't want any validation errors propagating up
                }
                catch (Exception ex)
                {
                }
            }

            return(JsonGetSuccess(clone));
        }
Esempio n. 7
0
        public async Task <FdpChangeset> PersistChangeset(TakeRateFilter filter)
        {
            var changeset = await GetUnsavedChangesForUser(filter);

            changeset.Comment = filter.Comment;
            return(await Task.FromResult(_takeRateDataStore.FdpChangesetPersist(filter, changeset)));
        }
        public MarketGroup FdpMarketGroupGet(TakeRateFilter filter)
        {
            MarketGroup retVal = new EmptyMarketGroup();

            using (var conn = DbHelper.GetDBConnection())
            {
                try
                {
                    var para = new DynamicParameters();
                    para.Add("@MarketGroupId", filter.MarketGroupId, DbType.Int32);
                    para.Add("@FdpVolumeHeaderId", filter.TakeRateId, DbType.Int32);

                    using (var multi = conn.QueryMultiple("dbo.Fdp_MarketGroup_Get", para, commandType: CommandType.StoredProcedure))
                    {
                        retVal = multi.Read <MarketGroup>().FirstOrDefault();

                        var markets = multi.Read <Market>().ToList();
                        if (retVal != null)
                        {
                            retVal.Markets = markets.ToList();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                    throw;
                }
            }

            return(retVal);
        }
        //[OutputCache(Duration = 600,
        //    VaryByParam = "TakeRateParameters.TakeRateId,TakeRateParameters.MarketId,TakeRateParameters.PageSize,TakeRateParameters.PageIndex")]
        //[SiteMapTitle("DocumentName")]
        public ActionResult TakeRateDataPage(TakeRateParameters parameters)
        {
            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.TakeRateDataPage;
            var model = TakeRateViewModel.GetModel(DataContext, filter).Result;

            var title = string.Format("{0} - {1} ({2}) - {3}",
                                      model.Document.Vehicle.Code,
                                      model.Document.Vehicle.ModelYear, model.Document.UnderlyingOxoDocument.Gateway,
                                      model.Document.TakeRateSummary.First().Version);

            ViewBag.Title = title;

            string displayName;

            if (model.Document.Market is EmptyMarket)
            {
                displayName = string.Format("{0} - ALL MARKETS", title);
            }
            else
            {
                displayName = string.Format("{0} - {1}",
                                            title,
                                            model.Document.Market.Name.ToUpper());
            }

            ViewData["DocumentName"] = displayName;

            return(View("TakeRateDataPage", model));
        }
        public async Task <ActionResult> GetLatestChangeset(TakeRateParameters parameters)
        {
            TakeRateParametersValidator.ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.TakeRateIdentifier);

            var changeset = await DataContext.TakeRate.GetUnsavedChangesForUser(TakeRateFilter.FromTakeRateParameters(parameters));

            return(Json(changeset));
        }
        public static ITakeRateDocument FromFilter(TakeRateFilter filter)
        {
            var volume = new TakeRateDocument();

            if (filter.TakeRateId.HasValue)
            {
                volume.TakeRateId = filter.TakeRateId;
            }

            volume.UnderlyingOxoDocument = filter.DocumentId.HasValue ? new OXODoc()
            {
                Id = filter.DocumentId.Value
            } : new EmptyOxoDocument();

            if (filter.ProgrammeId.HasValue)
            {
                volume.Vehicle = new Vehicle()
                {
                    ProgrammeId = filter.ProgrammeId.Value, Gateway = filter.Gateway
                };
            }

            if (filter.MarketGroupId.HasValue)
            {
                volume.MarketGroup = new MarketGroup()
                {
                    Id = filter.MarketGroupId.Value
                };
            }

            if (filter.MarketId.HasValue)
            {
                volume.Market = new Market()
                {
                    Id = filter.MarketId.Value
                };
            }

            if (!string.IsNullOrEmpty(filter.BMC))
            {
                volume.BMC = filter.BMC;
            }

            if (!string.IsNullOrEmpty(filter.DPCK))
            {
                volume.DPCK = filter.DPCK;
            }

            if (!string.IsNullOrEmpty(filter.FeatureCode))
            {
                volume.FeatureCode = filter.FeatureCode;
            }

            volume.Mode = filter.Mode;

            return(volume);
        }
Esempio n. 12
0
        private async static Task <PagedResults <TakeRateSummary> > ListVolumeSummary(IDataContext context, Volume forVolume)
        {
            if (forVolume.Document is EmptyOxoDocument)
            {
                return(new PagedResults <TakeRateSummary>());
            }

            return(await context.Volume.ListTakeRateData(TakeRateFilter.FromVolume(forVolume)));
        }
Esempio n. 13
0
        private static async Task <PublishViewModel> GetFullAndPartialViewModel(IDataContext context,
                                                                                TakeRateFilter filter)
        {
            var model = new PublishViewModel(GetBaseModel(context));

            model.AvailableFiles = await context.TakeRate.ListPublish(filter);

            return(model);
        }
Esempio n. 14
0
        public async Task <TakeRateData> GetTakeRateDocumentFeatures(TakeRateFilter filter)
        {
            if (!IsFilterValidForTakeRateData(filter))
            {
                return(new TakeRateData());
            }

            return(await Task.FromResult(_takeRateDataStore.TakeRateDataItemFeatureList(filter)));
        }
        private static async Task <TakeRateData> ListTakeRateDataFeatures(IDataContext context, TakeRateViewModel takeRateViewModel)
        {
            if (takeRateViewModel.Document.UnderlyingOxoDocument is EmptyOxoDocument)
            {
                return(new TakeRateData());
            }

            return(await context.TakeRate.GetTakeRateDocumentFeatures(TakeRateFilter.FromTakeRateViewModel(takeRateViewModel)));
        }
        public async Task <ActionResult> Publish(TakeRateParameters parameters)
        {
            TakeRateParametersValidator
            .ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.TakeRateIdentifierWithCommentAndMarket);

            var publish = await DataContext.TakeRate.SetPublish(
                TakeRateFilter.FromTakeRateParameters(parameters));

            return(Json(publish));
        }
Esempio n. 17
0
        public static async Task <FdpOxoVolumeViewModel> GetModel(IDataContext context,
                                                                  TakeRateFilter filter)
        {
            FdpOxoVolumeViewModel model = null;

            if (filter.Action == TakeRateDataItemAction.SaveChanges)
            {
                model = await GetFullAndPartialViewModelForSave(context, filter);
            }
            return(model);
        }
        public async Task <ActionResult> Powertrain(TakeRateParameters parameters)
        {
            TakeRateParametersValidator.ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.TakeRateIdentifier);

            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.Powertrain;
            var takeRateView = await TakeRateViewModel.GetModel(DataContext, filter);

            return(PartialView("_Powertrain", takeRateView));
        }
Esempio n. 19
0
        public async Task <PagedResults <MarketReview> > ListMarketReview(TakeRateFilter filter)
        {
            var marketReview = await Task.FromResult(_takeRateDataStore.FdpMarketReviewGetMany(filter));

            foreach (var currentMarketReview in marketReview.CurrentPage)
            {
                currentMarketReview.Programme = _programmeDataStore.ProgrammeGet(currentMarketReview.ProgrammeId);
                currentMarketReview.Document  = _documentDataStore.OXODocGet(currentMarketReview.DocumentId,
                                                                             currentMarketReview.ProgrammeId);
            }
            return(marketReview);
        }
        public async Task <ActionResult> TakeRatePage(TakeRateParameters parameters)
        {
            TakeRateParametersValidator
            .ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.NoValidation);

            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.TakeRates;
            var takeRateView = await TakeRateViewModel.GetModel(DataContext, filter);

            return(View("TakeRatePage", takeRateView));
        }
        private void CheckModelAllowsEdit(TakeRateParameters parameters)
        {
            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.Changeset;
            var takeRateView = TakeRateViewModel.GetModel(DataContext, filter).Result;

            if (!takeRateView.AllowEdit)
            {
                throw new InvalidOperationException(NO_EDITS);
            }
        }
        public async Task <ActionResult> PersistChangeset(TakeRateParameters parameters)
        {
            TakeRateParametersValidator.ValidateTakeRateParameters(DataContext, parameters,
                                                                   TakeRateParametersValidator.TakeRateIdentifierWithChangesetAndComment);

            CheckModelAllowsEdit(parameters);

            var persistedChangeset =
                await DataContext.TakeRate.PersistChangeset(TakeRateFilter.FromTakeRateParameters(parameters));

            return(Json(persistedChangeset));
        }
Esempio n. 23
0
        public async Task <PagedResults <Publish> > ListPublish(TakeRateFilter filter)
        {
            var publish = await Task.FromResult(_takeRateDataStore.FdpPublishGetMany(filter));

            foreach (var currentPublish in publish.CurrentPage)
            {
                currentPublish.Programme = _programmeDataStore.ProgrammeGet(currentPublish.ProgrammeId);
                currentPublish.Document  = _documentDataStore.OXODocGet(currentPublish.DocumentId,
                                                                        currentPublish.ProgrammeId);
            }
            return(publish);
        }
        private bool IsVolumeGreaterThanVolumeForMarket(DataChange change)
        {
            if (!change.IsModelSummary)
            {
                return(false);
            }

            var filter       = TakeRateFilter.FromTakeRateParameters(Parameters);
            var marketVolume = _context.TakeRate.GetVolumeForMarket(filter).Result;

            return(change.Volume > marketVolume);
        }
        private static async Task <MarketReviewViewModel> GetFullAndPartialViewModel(IDataContext context,
                                                                                     TakeRateFilter filter)
        {
            var model = new MarketReviewViewModel(GetBaseModel(context));

            if (filter.Action == TakeRateDataItemAction.MarketReview)
            {
                model.AvailableMarketReviews = await context.TakeRate.ListMarketReview(filter);
            }
            ;
            return(model);
        }
Esempio n. 26
0
 public async Task <TakeRateDataItem> GetDataItem(TakeRateFilter filter)
 {
     if (filter.FeatureId.HasValue || filter.FdpFeatureId.HasValue)
     {
         return(await Task.FromResult(_takeRateDataStore.TakeRateDataItemGet(filter)));
     }
     if (filter.ModelId.HasValue || filter.FdpModelId.HasValue)
     {
         return(await Task.FromResult(_takeRateDataStore.TakeRateModelSummaryItemGet(filter)));
     }
     return(new EmptyTakeRateDataItem());
 }
        public async Task <ActionResult> ChangesetHistory(TakeRateParameters parameters)
        {
            TakeRateParametersValidator.ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.TakeRateIdentifier);

            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.Changeset;
            var takeRateView = await TakeRateViewModel.GetModel(DataContext, filter);

            takeRateView.History = await DataContext.TakeRate.GetChangesetHistory(filter);

            return(PartialView("_ChangesetHistory", takeRateView));
        }
        public async Task <ActionResult> PersistChangesetConfirm(TakeRateParameters parameters)
        {
            TakeRateParametersValidator.ValidateTakeRateParameters(DataContext, parameters, TakeRateParametersValidator.TakeRateIdentifierWithChangeset);

            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.TakeRateDataItemDetails;
            var takeRateView = await TakeRateViewModel.GetModel(DataContext, filter);

            takeRateView.Changes = await DataContext.TakeRate.GetUnsavedChangesForUser(filter);

            return(PartialView("_PersistChangesetConfirm", takeRateView));
        }
Esempio n. 29
0
        public async Task <ActionResult> ProcessTakeRateData(ImportExceptionParameters parameters)
        {
            var filter     = new ImportQueueFilter(parameters.ImportQueueId.GetValueOrDefault());
            var queuedItem = DataContext.Import.GetImportQueue(filter).Result;
            var results    = DataContext.Import.ProcessTakeRateData(queuedItem).Result;

            if (queuedItem.HasErrors)
            {
                return(Json(JsonActionResult.GetFailure("Import file still contains errors, unable to process take rate data")));
            }

            if (results == null || !results.TakeRateId.HasValue)
            {
                return(Json(JsonActionResult.GetFailure("Take Rate file not created"), JsonRequestBehavior.AllowGet));
            }

            // Validate the data for each market

            var takeRateParameters = new TakeRateParameters()
            {
                TakeRateId = results.TakeRateId
            };
            var takeRateFilter = TakeRateFilter.FromTakeRateParameters(takeRateParameters);

            // Get the markets and iterate through them, validating in turn

            //var availableMarkets = DataContext.Market.ListMarkets(takeRateFilter).Result;
            //foreach (var market in availableMarkets)
            //{
            //    takeRateFilter.Action = TakeRateDataItemAction.Validate;
            //    takeRateFilter.MarketId = market.Id;
            //    var takeRateView = await TakeRateViewModel.GetModel(DataContext, takeRateFilter);

            //    try
            //    {
            //        var interimResults = Validator.Validate(takeRateView.RawData);
            //        await Validator.Persist(DataContext, takeRateFilter, interimResults, true);
            //    }
            //    catch (ValidationException vex)
            //    {
            //        // Just in case someone has thrown an exception from the validation, which we don't actually want
            //        Log.Warning(vex);
            //    }
            //    catch (Exception ex)
            //    {
            //        Log.Error(ex);
            //    }
            //}

            return(Json(JsonActionResult.GetSuccess(), JsonRequestBehavior.AllowGet));
        }
        private async Task CheckModelAllowsEdit(TakeRateParameters parameters)
        {
            var filter = TakeRateFilter.FromTakeRateParameters(parameters);

            filter.Action = TakeRateDataItemAction.Publish;
            var takeRateView = await TakeRateViewModel.GetModel(
                DataContext,
                filter);

            if (!takeRateView.AllowEdit)
            {
                throw new InvalidOperationException(NoEdits);
            }
        }