Example #1
0
        public async Task <ActionResult> ViewDataReturnSubmissionHistory(Guid pcsId,
                                                                         DataReturnSubmissionsHistoryOrderBy orderBy = DataReturnSubmissionsHistoryOrderBy.ComplianceYearDescending, int page = 1)
        {
            await SetBreadcrumb(pcsId, PcsAction.ViewSubmissionHistory);

            if (page < 1)
            {
                page = 1;
            }

            var model = new DataReturnSubmissionHistoryViewModel {
                OrderBy = orderBy
            };

            using (var client = apiClient())
            {
                var scheme = await client.SendAsync(User.GetAccessToken(), new GetSchemePublicInfo(pcsId));

                if (scheme != null)
                {
                    var getDataReturnSubmissionsHistoryResults =
                        new GetDataReturnSubmissionsHistoryResults(scheme.SchemeId,
                                                                   scheme.OrganisationId, ordering: orderBy);

                    var results = await client.SendAsync(User.GetAccessToken(), getDataReturnSubmissionsHistoryResults);

                    if (results.Data != null)
                    {
                        model.Results = results.Data.ToPagedList(page - 1, DefaultPageSize, results.ResultCount);
                    }
                }
            }

            return(View(model));
        }
        private async Task<ActionResult> RetrieveDataReturnsSubmissionResults(int year, Guid schemeId, DataReturnSubmissionsHistoryOrderBy orderBy)
        {
            if (Request != null &&
                !Request.IsAjaxRequest())
            {
                throw new InvalidOperationException();
            }

            if (!ModelState.IsValid)
            {
                return Json(null, JsonRequestBehavior.AllowGet);
            }
            using (var client = apiClient())
            {
                try
                {
                    var schemeData = await client.SendAsync(User.GetAccessToken(), new GetSchemeById(schemeId));

                    var getDataReturnSubmissionsHistoryResults = new GetDataReturnSubmissionsHistoryResults(
                        schemeId, schemeData.OrganisationId, year, ordering: orderBy, includeSummaryData: true, compareEeeOutputData: true);

                    DataReturnSubmissionsHistoryResult searchResults = await client.SendAsync(User.GetAccessToken(), getDataReturnSubmissionsHistoryResults);

                    var model = new DataReturnSubmissionsResultsViewModel
                    {
                        Year = year,
                        Scheme = schemeId,
                        Results = searchResults.Data,
                        OrderBy = orderBy
                    };

                    return PartialView("_dataReturnSubmissionsResults", model);
                }
                catch (ApiBadRequestException ex)
                {
                    this.HandleBadRequest(ex);
                    throw;
                }
            }
        }
 public Task<ActionResult> GetDataReturnSubmissionResults(int year, Guid schemeId, DataReturnSubmissionsHistoryOrderBy orderBy)
 {
     return RetrieveDataReturnsSubmissionResults(year, schemeId, orderBy);
 }
        public async Task<ActionResult> ViewDataReturnSubmissionHistory(Guid pcsId,
            DataReturnSubmissionsHistoryOrderBy orderBy = DataReturnSubmissionsHistoryOrderBy.ComplianceYearDescending, int page = 1)
        {
            await SetBreadcrumb(pcsId, "View submission history");

            if (page < 1)
            {
                page = 1;
            }

            var model = new DataReturnSubmissionHistoryViewModel();
            model.OrderBy = orderBy;

            using (var client = apiClient())
            {
                var scheme = await client.SendAsync(User.GetAccessToken(), new GetSchemePublicInfo(pcsId));

                if (scheme != null)
                {
                    var getDataReturnSubmissionsHistoryResults =
                        new GetDataReturnSubmissionsHistoryResults(scheme.SchemeId,
                        scheme.OrganisationId, ordering: orderBy);

                    var results = await client.SendAsync(User.GetAccessToken(), getDataReturnSubmissionsHistoryResults);
                    if (results.Data != null)
                    {
                        model.Results = results.Data.ToPagedList(page - 1, DefaultPageSize, results.ResultCount);
                    }
                }
            }

            return View(model);
        }
        private async Task <ActionResult> RetrieveDataReturnsSubmissionResults(int year, Guid schemeId, DataReturnSubmissionsHistoryOrderBy orderBy)
        {
            if (Request != null &&
                !Request.IsAjaxRequest())
            {
                throw new InvalidOperationException();
            }

            if (!ModelState.IsValid)
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            using (var client = apiClient())
            {
                try
                {
                    var schemeData = await client.SendAsync(User.GetAccessToken(), new GetSchemeById(schemeId));

                    var getDataReturnSubmissionsHistoryResults = new GetDataReturnSubmissionsHistoryResults(
                        schemeId, schemeData.OrganisationId, year, ordering: orderBy, includeSummaryData: true, compareEeeOutputData: true);

                    DataReturnSubmissionsHistoryResult searchResults = await client.SendAsync(User.GetAccessToken(), getDataReturnSubmissionsHistoryResults);

                    var model = new DataReturnSubmissionsResultsViewModel
                    {
                        Year    = year,
                        Scheme  = schemeId,
                        Results = searchResults.Data,
                        OrderBy = orderBy
                    };

                    return(PartialView("_dataReturnSubmissionsResults", model));
                }
                catch (ApiBadRequestException ex)
                {
                    this.HandleBadRequest(ex);
                    throw;
                }
            }
        }
 public Task <ActionResult> GetDataReturnSubmissionResults(int year, Guid schemeId, DataReturnSubmissionsHistoryOrderBy orderBy)
 {
     return(RetrieveDataReturnsSubmissionResults(year, schemeId, orderBy));
 }
        public async Task<List<DataReturnSubmissionsData>> GetDataReturnSubmissionsHistory(Guid schemeId, int? complianceYear = null,
            DataReturnSubmissionsHistoryOrderBy? ordering = null, bool includeSummaryData = false)
        {
            var query =
                from dru in context.DataReturnsUploads.AsNoTracking()
                join user in context.Users.AsNoTracking() on dru.DataReturnVersion.SubmittingUserId equals user.Id
                where dru.Scheme.Id == schemeId &&
                dru.DataReturnVersion != null &&
                (!complianceYear.HasValue || dru.ComplianceYear == complianceYear)
                select new DataReturnSubmissionsData
                {
                    SchemeId = dru.Scheme.Id,
                    OrganisationId = dru.Scheme.OrganisationId,
                    DataReturnUploadId = dru.Id,
                    SubmittedBy = user.FirstName + " " + user.Surname,
                    ComplianceYear = dru.ComplianceYear.Value,
                    SubmissionDateTime = dru.DataReturnVersion.SubmittedDate.Value,
                    FileName = dru.FileName,
                    Quarter = (Core.DataReturns.QuarterType)dru.Quarter,
                    DataReturnVersion = dru.DataReturnVersion,

                    EeeOutputB2b = includeSummaryData && dru.DataReturnVersion.EeeOutputReturnVersion != null ?
                            dru.DataReturnVersion.EeeOutputReturnVersion.EeeOutputAmounts.Any(x => x.DatabaseObligationType == ObligationTypeString.B2B) ?
                               (decimal?)dru.DataReturnVersion.EeeOutputReturnVersion.EeeOutputAmounts
                                  .Where(y => y.DatabaseObligationType == ObligationTypeString.B2B).Sum(z => z.Tonnage)
                               : null
                             : null,

                    EeeOutputB2c = includeSummaryData && dru.DataReturnVersion.EeeOutputReturnVersion != null ?
                            dru.DataReturnVersion.EeeOutputReturnVersion.EeeOutputAmounts.Any(x => x.DatabaseObligationType == ObligationTypeString.B2C) ?
                               (decimal?)dru.DataReturnVersion.EeeOutputReturnVersion.EeeOutputAmounts
                                  .Where(y => y.DatabaseObligationType == ObligationTypeString.B2C).Sum(z => z.Tonnage)
                               : null
                             : null,

                    WeeeCollectedB2b = includeSummaryData && dru.DataReturnVersion.WeeeCollectedReturnVersion != null ?
                            dru.DataReturnVersion.WeeeCollectedReturnVersion.WeeeCollectedAmounts.Any(x => x.DatabaseObligationType == ObligationTypeString.B2B) ?
                               (decimal?)dru.DataReturnVersion.WeeeCollectedReturnVersion.WeeeCollectedAmounts
                                  .Where(y => y.DatabaseObligationType == ObligationTypeString.B2B).Sum(z => z.Tonnage)
                               : null
                             : null,

                    WeeeCollectedB2c = includeSummaryData && dru.DataReturnVersion.WeeeCollectedReturnVersion != null ?
                            dru.DataReturnVersion.WeeeCollectedReturnVersion.WeeeCollectedAmounts.Any(x => x.DatabaseObligationType == ObligationTypeString.B2C) ?
                               (decimal?)dru.DataReturnVersion.WeeeCollectedReturnVersion.WeeeCollectedAmounts
                                  .Where(y => y.DatabaseObligationType == ObligationTypeString.B2C).Sum(z => z.Tonnage)
                               : null
                             : null,

                    WeeeDeliveredB2b = includeSummaryData && dru.DataReturnVersion.WeeeDeliveredReturnVersion != null ?
                            dru.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts.Any(x => x.DatabaseObligationType == ObligationTypeString.B2B) ?
                               (decimal?)dru.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts
                                  .Where(y => y.DatabaseObligationType == ObligationTypeString.B2B).Sum(z => z.Tonnage)
                               : null
                             : null,

                    WeeeDeliveredB2c = includeSummaryData && dru.DataReturnVersion.WeeeDeliveredReturnVersion != null ?
                            dru.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts.Any(x => x.DatabaseObligationType == ObligationTypeString.B2C) ?
                               (decimal?)dru.DataReturnVersion.WeeeDeliveredReturnVersion.WeeeDeliveredAmounts
                                  .Where(y => y.DatabaseObligationType == ObligationTypeString.B2C).Sum(z => z.Tonnage)
                               : null
                             : null,
                };

            switch (ordering)
            {
                case DataReturnSubmissionsHistoryOrderBy.ComplianceYearAscending:
                    query = query
                        .OrderBy(s => s.ComplianceYear)
                        .ThenByDescending(s => s.SubmissionDateTime);
                    break;

                case DataReturnSubmissionsHistoryOrderBy.ComplianceYearDescending:
                    query = query
                        .OrderByDescending(s => s.ComplianceYear)
                        .ThenByDescending(s => s.SubmissionDateTime);
                    break;

                case DataReturnSubmissionsHistoryOrderBy.QuarterAscending:
                    query = query
                        .OrderByDescending(s => s.ComplianceYear)
                        .ThenBy(s => s.Quarter)
                        .ThenByDescending(s => s.SubmissionDateTime);
                    break;

                case DataReturnSubmissionsHistoryOrderBy.QuarterDescending:
                    query = query
                        .OrderByDescending(s => s.ComplianceYear)
                        .ThenByDescending(s => s.Quarter)
                        .ThenByDescending(s => s.SubmissionDateTime);
                    break;

                case DataReturnSubmissionsHistoryOrderBy.SubmissionDateAscending:
                    query = query
                        .OrderBy(s => s.SubmissionDateTime);
                    break;

                case DataReturnSubmissionsHistoryOrderBy.SubmissionDateDescending:
                default:
                    query = query
                        .OrderByDescending(s => s.SubmissionDateTime);
                    break;
            }

            return await query.ToListAsync();
        }