Esempio n. 1
0
        public ActionResult <IEnumerable <ParcelAllocationAndUsageDto> > GetParcelsWithAllocationAndUsageByYear([FromRoute] int year)
        {
            var parcelDtos = ParcelAllocationAndUsage.GetByYear(_dbContext, year);
            var parcelAllocationBreakdownForYear = ParcelAllocation.GetParcelAllocationBreakdownForYear(_dbContext, year);
            var parcelDtosWithAllocation         = parcelDtos
                                                   .GroupJoin(
                parcelAllocationBreakdownForYear,
                x => x.ParcelID,
                y => y.ParcelID,
                (x, y) => new
            {
                ParcelAllocationAndUsage  = x,
                ParcelAllocationBreakdown = y
            })
                                                   .SelectMany(
                parcelAllocationUsageAndBreakdown =>
                parcelAllocationUsageAndBreakdown.ParcelAllocationBreakdown.DefaultIfEmpty(),
                (x, y) =>
            {
                x.ParcelAllocationAndUsage.Allocations = y?.Allocations;
                return(x.ParcelAllocationAndUsage);
            });

            return(Ok(parcelDtosWithAllocation));
        }
Esempio n. 2
0
        public async Task <ActionResult> BulkSetAnnualParcelAllocationFileUpload([FromRoute] int waterYear,
                                                                                 [FromRoute] int parcelAllocationTypeID)
        {
            var fileResource = await HttpUtilities.MakeFileResourceFromHttpRequest(Request, _dbContext, HttpContext);

            var parcelAllocationTypeDisplayName =
                _dbContext.ParcelAllocationType.Single(x => x.ParcelAllocationTypeID == parcelAllocationTypeID).ParcelAllocationTypeName;

            if (!ParseBulkSetAllocationUpload(fileResource, parcelAllocationTypeDisplayName, out var records, out var badRequestFromUpload))
            {
                return(badRequestFromUpload);
            }

            if (!ValidateBulkSetAllocationUpload(records, parcelAllocationTypeDisplayName, out var badRequestFromValidation))
            {
                return(badRequestFromValidation);
            }

            _dbContext.FileResource.Add(fileResource);
            _dbContext.SaveChanges();

            ParcelAllocation.BulkSetAllocation(_dbContext, records, waterYear, parcelAllocationTypeID);

            ParcelAllocationHistory.CreateParcelAllocationHistoryEntity(_dbContext,
                                                                        UserContext.GetUserFromHttpContext(_dbContext, HttpContext).UserID, fileResource.FileResourceID, waterYear,
                                                                        parcelAllocationTypeID, null);

            return(Ok());
        }
Esempio n. 3
0
        public ActionResult BulkSetAnnualParcelAllocation([FromRoute] int userID, [FromBody] ParcelAllocationUpsertDto parcelAllocationUpsertDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var numberOfParcels = ParcelAllocation.BulkSetAllocation(_dbContext, parcelAllocationUpsertDto);

            ParcelAllocationHistory.CreateParcelAllocationHistoryEntity(_dbContext, userID, parcelAllocationUpsertDto, null);

            return(Ok(numberOfParcels));
        }
Esempio n. 4
0
        public ActionResult <List <ParcelAllocationDto> > GetAllocations([FromRoute] int parcelID)
        {
            var parcelDto = Parcel.GetByParcelID(_dbContext, parcelID);

            if (ThrowNotFound(parcelDto, "Parcel", parcelID, out var actionResult))
            {
                return(actionResult);
            }

            var parcelAllocationDtos = ParcelAllocation.ListByParcelID(_dbContext, parcelID);

            return(Ok(parcelAllocationDtos));
        }
Esempio n. 5
0
        public ActionResult <List <ParcelAllocationDto> > ListParcelsAllocationByAccountID([FromRoute] int accountID, [FromRoute] int year)
        {
            var parcelDtosEnumerable = Parcel.ListByAccountIDAndYear(_dbContext, accountID, year);

            if (parcelDtosEnumerable == null)
            {
                return(NotFound());
            }

            var parcelDtos           = parcelDtosEnumerable.ToList();
            var parcelIDs            = parcelDtos.Select(x => x.ParcelID).ToList();
            var parcelAllocationDtos = ParcelAllocation.ListByParcelID(_dbContext, parcelIDs);

            return(Ok(parcelAllocationDtos));
        }
Esempio n. 6
0
        public ActionResult <List <LandownerUsageReportDto> > GetLandOwnerUsageReport([FromRoute] int year)
        {
            var landownerUsageReportDtos = LandownerUsageReport.GetByYear(_dbContext, year);

            var landownerAllocationBreakdownForYear = ParcelAllocation.GetLandownerAllocationBreakdownForYear(_dbContext, year);

            var landownerUsageReportDtosWithAllocation = landownerUsageReportDtos.Join(
                landownerAllocationBreakdownForYear, x => x.AccountID, y => y.AccountID,
                (x, y) =>
            {
                x.Allocations = y.Allocations;
                return(x);
            });


            return(Ok(landownerUsageReportDtosWithAllocation));
        }