public virtual IActionResult DistrictEquipmentTypesGet()
        {
            // get current users district id
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, HttpContext);

            // not found
            if (districtId == null)
            {
                return(new ObjectResult(new List <HetDistrictEquipmentType>()));
            }

            List <HetDistrictEquipmentType> equipmentTypes = _context.HetDistrictEquipmentType.AsNoTracking()
                                                             .Include(x => x.District)
                                                             .Include(x => x.EquipmentType)
                                                             .Include(x => x.HetEquipment)
                                                             .ThenInclude(y => y.LocalArea)
                                                             .Include(x => x.HetEquipment)
                                                             .ThenInclude(x => x.EquipmentStatusType)
                                                             .Where(x => x.District.DistrictId == districtId &&
                                                                    !x.Deleted)
                                                             .OrderBy(x => x.DistrictEquipmentName)
                                                             .ToList();

            foreach (HetDistrictEquipmentType equipmentType in equipmentTypes)
            {
                IEnumerable <HetEquipment> approvedEquipment = equipmentType.HetEquipment
                                                               .Where(x => x.EquipmentStatusType.EquipmentStatusTypeCode == HetEquipment.StatusApproved);

                List <HetEquipment> hetEquipments = approvedEquipment.ToList();
                equipmentType.EquipmentCount = hetEquipments.Count;

                foreach (HetEquipment equipment in hetEquipments)
                {
                    LocalAreaEquipment localAreaEquipment = equipmentType.LocalAreas
                                                            .FirstOrDefault(x => x.Id == equipment.LocalAreaId);

                    if (localAreaEquipment == null)
                    {
                        localAreaEquipment = new LocalAreaEquipment
                        {
                            Id             = equipment.LocalArea.LocalAreaId,
                            Name           = equipment.LocalArea.Name,
                            EquipmentCount = 1
                        };

                        equipmentType.LocalAreas.Add(localAreaEquipment);
                    }
                    else
                    {
                        localAreaEquipment.EquipmentCount = localAreaEquipment.EquipmentCount + 1;
                    }
                }

                // remove unnecessary data
                equipmentType.HetEquipment = null;
            }

            return(new ObjectResult(new HetsResponse(equipmentTypes)));
        }
예제 #2
0
        public virtual IActionResult RentalRequestsSearchGet([FromQuery] string localAreas, [FromQuery] string project, [FromQuery] string status, [FromQuery] DateTime?startDate, [FromQuery] DateTime?endDate)
        {
            int?[] localAreasArray = ArrayHelper.ParseIntArray(localAreas);

            // get initial results - must be limited to user's district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            IQueryable <HetRentalRequest> data = _context.HetRentalRequest.AsNoTracking()
                                                 .Include(x => x.LocalArea.ServiceArea.District.Region)
                                                 .Include(x => x.DistrictEquipmentType)
                                                 .ThenInclude(y => y.EquipmentType)
                                                 .Include(x => x.Project.PrimaryContact)
                                                 .Include(x => x.RentalRequestStatusType)
                                                 .Include(x => x.HetRentalRequestRotationList)
                                                 .OrderByDescending(x => x.AppCreateTimestamp)
                                                 .Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId));

            if (localAreasArray != null && localAreasArray.Length > 0)
            {
                data = data.Where(x => localAreasArray.Contains(x.LocalArea.LocalAreaId));
            }

            if (project != null)
            {
                data = data.Where(x => x.Project.Name.ToLower().Contains(project.ToLower()));
            }

            if (startDate != null)
            {
                data = data.Where(x => x.ExpectedStartDate >= startDate);
            }

            if (endDate != null)
            {
                data = data.Where(x => x.ExpectedStartDate <= endDate);
            }

            if (status != null)
            {
                int?statusId = StatusHelper.GetStatusId(status, "rentalRequestStatus", _context);

                if (statusId != null)
                {
                    data = data.Where(x => x.RentalRequestStatusTypeId == statusId);
                }
            }

            // convert Rental Request Model to the "RentalRequestLite" Model
            List <RentalRequestLite> result = new List <RentalRequestLite>();

            foreach (HetRentalRequest item in data)
            {
                result.Add(RentalRequestHelper.ToLiteModel(item));
            }

            // return to the client
            return(new ObjectResult(new HetsResponse(result)));
        }
예제 #3
0
        public virtual IActionResult ConditionTypesGet()
        {
            // get current users district id
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, HttpContext);

            // not found
            if (districtId == null)
            {
                return(new ObjectResult(new List <HetConditionType>()));
            }

            // get condition types for this district
            List <HetConditionType> conditionTypes = _context.HetConditionType.AsNoTracking()
                                                     .Include(x => x.District)
                                                     .Where(x => x.Active &&
                                                            x.District.DistrictId == districtId)
                                                     .ToList();

            return(new ObjectResult(new HetsResponse(conditionTypes)));
        }
        public virtual IActionResult DistrictEquipmentTypesGetAgreementSummary()
        {
            // get user's district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, HttpContext);

            IEnumerable <DistrictEquipmentTypeAgreementSummary> equipmentTypes = _context.HetRentalAgreement.AsNoTracking()
                                                                                 .Include(x => x.Equipment.DistrictEquipmentType)
                                                                                 .Where(x => x.DistrictId == districtId &&
                                                                                        !x.Number.StartsWith("BCBid"))
                                                                                 .GroupBy(x => x.Equipment.DistrictEquipmentType, (t, agreements) => new DistrictEquipmentTypeAgreementSummary
            {
                Id           = t.DistrictEquipmentTypeId,
                Name         = t.DistrictEquipmentName,
                AgreementIds = agreements.Select(y => y.RentalAgreementId).Distinct().ToList(),
                ProjectIds   = agreements.Select(y => y.ProjectId).Distinct().ToList(),
            })
                                                                                 .ToList();

            return(new ObjectResult(new HetsResponse(equipmentTypes)));
        }
예제 #5
0
        public virtual IActionResult UsersCurrentFavouritesFavouriteTypeGet([FromRoute] string favouriteType)
        {
            // get the current user id
            string userId = _context.SmUserId;

            // get initial results - must be limited to user's district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            // get favourites
            IEnumerable <HetUserFavourite> favourites = _context.HetUserFavourite.AsNoTracking()
                                                        .Include(x => x.User)
                                                        .Where(x => x.User.SmUserId == userId &&
                                                               x.DistrictId == districtId);

            if (favouriteType != null)
            {
                favourites = favourites.Where(x => x.Type == favouriteType);
            }

            return(new ObjectResult(new HetsResponse(favourites)));
        }
예제 #6
0
        public virtual IActionResult BatchReportGet()
        {
            // get users district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            IEnumerable <HetBatchReport> reports = _context.HetBatchReport.AsNoTracking()
                                                   .Where(x => x.DistrictId == districtId)
                                                   .OrderByDescending(x => x.StartDate)
                                                   .Select(x => new ReportModel
            {
                Id         = x.ReportId,
                ReportId   = x.ReportId,
                DistrictId = x.DistrictId,
                StartDate  = x.StartDate,
                EndDate    = x.EndDate,
                Complete   = x.Complete,
                Status     = x.Complete ? "Complete" : "In Progress"
            });

            return(new ObjectResult(new HetsResponse(reports)));
        }
예제 #7
0
        public virtual IActionResult NoProjectsGet()
        {
            // get current district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            int?statusIdInProgress = StatusHelper.GetStatusId(HetRentalRequest.StatusInProgress, "rentalRequestStatus", _context);

            if (statusIdInProgress == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
            }

            List <HetRentalRequest> requests = _context.HetRentalRequest.AsNoTracking()
                                               .Include(x => x.LocalArea.ServiceArea.District)
                                               .Include(x => x.DistrictEquipmentType)
                                               .Where(x => x.LocalArea.ServiceArea.DistrictId == districtId &&
                                                      x.RentalRequestStatusTypeId == statusIdInProgress &&
                                                      x.ProjectId == null)
                                               .ToList();

            return(new ObjectResult(new HetsResponse(requests)));
        }
예제 #8
0
        private IActionResult UpdateFavourite(HetUserFavourite item)
        {
            item.User = null;

            // get the current user id
            string userId = _context.SmUserId;

            // not found
            if (userId == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get initial results - must be limited to user's district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            // get user record
            bool userExists = _context.HetUser.Any(a => a.SmUserId == userId);

            if (!userExists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            HetUser user = _context.HetUser.AsNoTracking()
                           .First(a => a.SmUserId == userId);

            // get favourites
            bool exists = _context.HetUserFavourite.Any(a => a.UserFavouriteId == item.UserFavouriteId);

            HetUserFavourite favourite;

            if (exists)
            {
                favourite = _context.HetUserFavourite
                            .First(a => a.UserFavouriteId == item.UserFavouriteId);

                favourite.ConcurrencyControlNumber = item.ConcurrencyControlNumber;
                favourite.Value     = item.Value;
                favourite.Name      = item.Name;
                favourite.IsDefault = item.IsDefault;

                _context.HetUserFavourite.Update(favourite);
            }
            else
            {
                favourite = new HetUserFavourite
                {
                    UserId     = user.UserId,
                    DistrictId = districtId,
                    Type       = item.Type,
                    Value      = item.Value,
                    Name       = item.Name,
                    IsDefault  = item.IsDefault
                };

                _context.HetUserFavourite.Add(favourite);
            }

            // save the changes
            _context.SaveChanges();

            int favouriteId = favourite.UserFavouriteId;

            // get record and return
            favourite = _context.HetUserFavourite.AsNoTracking()
                        .First(x => x.UserFavouriteId == favouriteId);

            return(new ObjectResult(new HetsResponse(favourite)));
        }
예제 #9
0
        public virtual IActionResult TimeRecordSearchGet([FromQuery] string localAreas,
                                                         [FromQuery] string projects, [FromQuery] string owners, [FromQuery] string equipment)
        {
            int?[] localAreasArray = ArrayHelper.ParseIntArray(localAreas);
            int?[] projectArray    = ArrayHelper.ParseIntArray(projects);
            int?[] ownerArray      = ArrayHelper.ParseIntArray(owners);
            int?[] equipmentArray  = ArrayHelper.ParseIntArray(equipment);

            // get initial results - must be limited to user's district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            // get fiscal year
            HetDistrictStatus district = _context.HetDistrictStatus.AsNoTracking()
                                         .FirstOrDefault(x => x.DistrictId == districtId);

            if (district?.CurrentFiscalYear == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-30", ErrorViewModel.GetDescription("HETS-30", _configuration))));
            }

            int      fiscalYear  = (int)district.CurrentFiscalYear; // status table uses the start of the year
            DateTime fiscalStart = new DateTime(fiscalYear, 3, 31); // look for all records AFTER the 31st

            // only return active equipment / projects and agreements
            IQueryable <HetTimeRecord> data = _context.HetTimeRecord.AsNoTracking()
                                              .Include(x => x.RentalAgreement)
                                              .ThenInclude(x => x.Project)
                                              .Include(x => x.RentalAgreement)
                                              .ThenInclude(x => x.Equipment)
                                              .ThenInclude(y => y.EquipmentStatusType)
                                              .Include(x => x.RentalAgreement)
                                              .ThenInclude(x => x.Equipment)
                                              .ThenInclude(z => z.LocalArea)
                                              .ThenInclude(a => a.ServiceArea)
                                              .Include(x => x.RentalAgreement)
                                              .ThenInclude(x => x.Equipment)
                                              .ThenInclude(z => z.Owner)
                                              .Where(x => x.RentalAgreement.Equipment.LocalArea.ServiceArea.DistrictId.Equals(districtId) &&
                                                     x.WorkedDate > fiscalStart);

            if (localAreasArray != null && localAreasArray.Length > 0)
            {
                data = data.Where(x => localAreasArray.Contains(x.RentalAgreement.Equipment.LocalArea.LocalAreaId));
            }

            if (projectArray != null && projectArray.Length > 0)
            {
                data = data.Where(x => projectArray.Contains(x.RentalAgreement.ProjectId));
            }

            if (ownerArray != null && ownerArray.Length > 0)
            {
                data = data.Where(x => ownerArray.Contains(x.RentalAgreement.Equipment.OwnerId));
            }

            if (equipmentArray != null && equipmentArray.Length > 0)
            {
                data = data.Where(x => equipmentArray.Contains(x.RentalAgreement.EquipmentId));
            }

            // convert Time Model to the "TimeLite" Model
            List <TimeRecordSearchLite> result = new List <TimeRecordSearchLite>();

            foreach (HetTimeRecord item in data)
            {
                result.Add(TimeRecordHelper.ToLiteModel(item));
            }

            // return to the client
            return(new ObjectResult(new HetsResponse(result)));
        }
예제 #10
0
        public virtual IActionResult RentalRequestsHiresGet([FromQuery] string localAreas, [FromQuery] string projects,
                                                            [FromQuery] string owners, [FromQuery] string equipment)
        {
            int?[] localAreasArray = ArrayHelper.ParseIntArray(localAreas);
            int?[] projectArray    = ArrayHelper.ParseIntArray(projects);
            int?[] ownerArray      = ArrayHelper.ParseIntArray(owners);
            int?[] equipmentArray  = ArrayHelper.ParseIntArray(equipment);

            // get initial results - must be limited to user's district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            // get fiscal year
            HetDistrictStatus district = _context.HetDistrictStatus.AsNoTracking()
                                         .FirstOrDefault(x => x.DistrictId == districtId);

            if (district?.CurrentFiscalYear == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-30", ErrorViewModel.GetDescription("HETS-30", _configuration))));
            }

            int      fiscalYear  = (int)district.CurrentFiscalYear; // status table uses the start of the year
            DateTime fiscalStart = new DateTime(fiscalYear, 3, 31); // look for all records AFTER the 31st

            IQueryable <HetRentalRequestRotationList> data = _context.HetRentalRequestRotationList.AsNoTracking()
                                                             .Include(x => x.RentalRequest)
                                                             .ThenInclude(y => y.LocalArea)
                                                             .ThenInclude(z => z.ServiceArea)
                                                             .Include(x => x.RentalRequest)
                                                             .ThenInclude(y => y.Project)
                                                             .Include(x => x.Equipment)
                                                             .ThenInclude(y => y.Owner)
                                                             .Where(x => x.RentalRequest.LocalArea.ServiceArea.DistrictId.Equals(districtId) &&
                                                                    x.AskedDateTime > fiscalStart &&
                                                                    (x.IsForceHire == true || x.OfferResponse.ToLower() == "no"));

            if (localAreasArray != null && localAreasArray.Length > 0)
            {
                data = data.Where(x => localAreasArray.Contains(x.RentalRequest.LocalAreaId));
            }

            if (projectArray != null && projectArray.Length > 0)
            {
                data = data.Where(x => projectArray.Contains(x.RentalRequest.ProjectId));
            }

            if (ownerArray != null && ownerArray.Length > 0)
            {
                data = data.Where(x => ownerArray.Contains(x.Equipment.OwnerId));
            }

            if (equipmentArray != null && equipmentArray.Length > 0)
            {
                data = data.Where(x => equipmentArray.Contains(x.EquipmentId));
            }

            // convert Rental Request Model to the "RentalRequestHires" Model
            List <RentalRequestHires> result = new List <RentalRequestHires>();

            foreach (HetRentalRequestRotationList item in data)
            {
                HetUser user = _context.HetUser.AsNoTracking()
                               .FirstOrDefault(x => x.SmUserId == item.AppCreateUserid);

                result.Add(RentalRequestHelper.ToHiresModel(item, user));
            }

            // return to the client
            return(new ObjectResult(new HetsResponse(result)));
        }
예제 #11
0
        public virtual IActionResult CountsGet()
        {
            CountModel result = new CountModel();

            // limited to user's district
            int?districtId = UserAccountHelper.GetUsersDistrictId(_context, _httpContext);

            // Count 1: Unapproved Owners
            int?pendingStatusId = StatusHelper.GetStatusId(HetOwner.StatusPending, "ownerStatus", _context);

            if (pendingStatusId == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
            }

            result.UnapprovedOwners = _context.HetOwner
                                      .AsNoTracking()
                                      .Count(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId) &&
                                             x.OwnerStatusTypeId.Equals(pendingStatusId));

            // Count 2: Unapproved Equipment
            int?unapprovedStatusId = StatusHelper.GetStatusId(HetEquipment.StatusUnapproved, "equipmentStatus", _context);

            if (unapprovedStatusId == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
            }

            result.UnapprovedEquipment = _context.HetEquipment
                                         .AsNoTracking()
                                         .Count(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId) &&
                                                x.EquipmentStatusTypeId.Equals(unapprovedStatusId));

            // Count 3: Hired Equipment
            int?activeEquipmentStatusId = StatusHelper.GetStatusId(HetEquipment.StatusApproved, "equipmentStatus", _context);

            if (activeEquipmentStatusId == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
            }

            var approvedEquipmentQuery = _context.HetEquipment
                                         .AsNoTracking()
                                         .Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId) &&
                                                x.EquipmentStatusTypeId.Equals(activeEquipmentStatusId));

            int?agreementStatusId = StatusHelper.GetStatusId(HetRentalAgreement.StatusActive, "rentalAgreementStatus", _context);

            if (agreementStatusId == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
            }

            var hiredEquipmentQuery = _context.HetRentalAgreement.AsNoTracking()
                                      .Where(x => x.Equipment.LocalArea.ServiceArea.DistrictId.Equals(districtId) &&
                                             x.RentalAgreementStatusTypeId == agreementStatusId)
                                      .Select(x => x.EquipmentId)
                                      .Distinct();

            result.HiredEquipment = approvedEquipmentQuery.Count(e => hiredEquipmentQuery.Contains(e.EquipmentId));

            // Count 4: In Progress Rental Requests
            int?requestStatusId = StatusHelper.GetStatusId(HetRentalRequest.StatusInProgress, "rentalRequestStatus", _context);

            if (requestStatusId == null)
            {
                return(new BadRequestObjectResult(new HetsResponse("HETS-23", ErrorViewModel.GetDescription("HETS-23", _configuration))));
            }

            result.InProgressRentalRequests = _context.HetRentalRequest
                                              .AsNoTracking()
                                              .Count(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId) &&
                                                     x.RentalRequestStatusTypeId.Equals(requestStatusId));

            // return to the client
            return(new ObjectResult(new HetsResponse(result)));
        }