Exemplo n.º 1
0
        /// <summary>
        /// Searches Projects
        /// </summary>
        /// <remarks>Used for the project search page.</remarks>
        /// <param name="localareasCSV">Local areas (comma seperated list of id numbers)</param>
        /// <param name="project">name or partial name for a Project</param>
        /// <param name="status">Status</param>
        /// <param name="startDate">Inspection start date</param>
        /// <param name="endDate">Inspection end date</param>
        /// <response code="200">OK</response>
        public virtual IActionResult RentalrequestsSearchGetAsync(string localareasCSV, string project, string status, DateTime?startDate, DateTime?endDate)
        {
            int?[] localareas = ParseIntArray(localareasCSV);

            var data = _context.RentalRequests
                       .Include(x => x.LocalArea.ServiceArea.District.Region)
                       .Include(x => x.DistrictEquipmentType.EquipmentType)
                       .Include(x => x.Project.PrimaryContact)
                       .Select(x => x);

            // Default search results must be limited to user
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            data = data.Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId));

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

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

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

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

            if (status != null)
            {
                // TODO: Change to enumerated type
                data = data.Where(x => x.Status.ToLower() == status.ToLower());
            }

            var result = new List <RentalRequestSearchResultViewModel>();

            foreach (var item in data)
            {
                if (item != null)
                {
                    RentalRequestSearchResultViewModel newItem = item.ToViewModel();
                    result.Add(newItem);
                }
            }

            // no calculated fields in a RentalRequest search yet.
            return(new ObjectResult(result));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Searches rental requests
        /// </summary>
        /// <remarks>Used for the rental request search page.</remarks>
        /// <param name="localareas">Local areas (comma seperated list of id numbers)</param>
        /// <param name="project">name or partial name for a Project</param>
        /// <param name="status">Status</param>
        /// <param name="startDate">Inspection start date</param>
        /// <param name="endDate">Inspection end date</param>
        /// <response code="200">OK</response>
        public virtual IActionResult RentalrequestsSearchGetAsync(string localareas, string project, string status, DateTime?startDate, DateTime?endDate)
        {
            int?[] localareasArray = ParseIntArray(localareas);

            IQueryable <RentalRequest> data = _context.RentalRequests
                                              .Include(x => x.LocalArea.ServiceArea.District.Region)
                                              .Include(x => x.DistrictEquipmentType.EquipmentType)
                                              .Include(x => x.Project.PrimaryContact)
                                              .Select(x => x);

            // Default search results must be limited to user
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            data = data.Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId));

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

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

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

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

            if (status != null)
            {
                data = data.Where(x => String.Equals(x.Status, status, StringComparison.CurrentCultureIgnoreCase));
            }

            List <RentalRequestSearchResultViewModel> result = new List <RentalRequestSearchResultViewModel>();

            foreach (RentalRequest item in data)
            {
                if (item != null)
                {
                    RentalRequestSearchResultViewModel newItem = item.ToViewModel();
                    result.Add(newItem);
                }
            }

            // no calculated fields in a RentalRequest search yet
            return(new ObjectResult(new HetsResponse(result)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get all condition types
        /// </summary>
        /// <remarks>Returns a list of condition types</remarks>
        /// <response code="200">OK</response>
        public virtual IActionResult ConditionTypesGetAsync()
        {
            // return for the current users district only
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            var result = _context.ConditionTypes.AsNoTracking()
                         .Include(x => x.District)
                         .Where(x => x.Active &&
                                x.District.Id == districtId)
                         .ToList();

            return(new ObjectResult(new HetsResponse(result)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get district equipment types
        /// </summary>
        /// <response code="200">OK</response>
        public virtual IActionResult DistrictEquipmentTypesGetAsync()
        {
            // return for the current users district only
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            List <DistrictEquipmentType> result = _context.DistrictEquipmentTypes.AsNoTracking()
                                                  .Include(x => x.District)
                                                  .ThenInclude(y => y.Region)
                                                  .Include(x => x.EquipmentType)
                                                  .Where(x => x.District.Id == districtId)
                                                  .ToList();

            return(new ObjectResult(new HetsResponse(result)));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Search Projects
        /// </summary>
        /// <remarks>Used for the project search page.</remarks>
        /// <param name="districts">Districts (comma seperated list of id numbers)</param>
        /// <param name="project">name or partial name for a Project</param>
        /// <param name="hasRequests">if true then only include Projects with active Requests</param>
        /// <param name="hasHires">if true then only include Projects with active Rental Agreements</param>
        /// <param name="status">if included, filter the results to those with a status matching this string</param>
        /// <response code="200">OK</response>
        public virtual IActionResult ProjectsSearchGetAsync(string districts, string project, bool?hasRequests, bool?hasHires, string status)
        {
            int?[] districtTokens = ParseIntArray(districts);

            // default search results must be limited to user
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            IQueryable <Project> data = _context.Projects
                                        .Where(x => x.DistrictId.Equals(districtId))
                                        .Include(x => x.District.Region)
                                        .Include(x => x.PrimaryContact)
                                        .Include(x => x.RentalAgreements)
                                        .Include(x => x.RentalRequests)
                                        .Select(x => x);

            if (districtTokens != null && districts.Length > 0)
            {
                data = data.Where(x => districtTokens.Contains(x.District.Id));
            }

            if (project != null)
            {
                // allow for case insensitive search of project name
                data = data.Where(x => x.Name.ToLowerInvariant().Contains(project.ToLowerInvariant()));
            }

            List <ProjectSearchResultViewModel> result = new List <ProjectSearchResultViewModel>();

            foreach (Project item in data)
            {
                item.ToViewModel();
                result.Add(item.ToViewModel());
            }

            // second pass to do calculated fields.
            foreach (ProjectSearchResultViewModel projectSearchResultViewModel in result)
            {
                // calculated fields.
                projectSearchResultViewModel.Requests = _context.RentalRequests
                                                        .Include(x => x.Project)
                                                        .Count(x => x.Project.Id == projectSearchResultViewModel.Id);

                projectSearchResultViewModel.Hires = _context.RentalAgreements
                                                     .Include(x => x.Project)
                                                     .Count(x => x.Project.Id == projectSearchResultViewModel.Id);
            }

            return(new ObjectResult(new HetsResponse(result)));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Searches Equipment
        /// </summary>
        /// <remarks>Used for the equipment search page.</remarks>
        /// <param name="localareasCSV">Local Areas (array of id numbers)</param>
        /// <param name="typesCSV">Equipment Types (array of id numbers)</param>
        /// <param name="equipmentAttachment">Equipment Attachments </param>
        /// <param name="owner"></param>
        /// <param name="status">Status</param>
        /// <param name="hired">Hired</param>
        /// <param name="notverifiedsincedate">Not Verified Since Date</param>
        /// <response code="200">OK</response>
        public virtual IActionResult EquipmentSearchGetAsync(string localareasCSV, string typesCSV, string equipmentAttachment, int?owner, string status, bool?hired, DateTime?notverifiedsincedate)
        {
            int?[] localareas = ParseIntArray(localareasCSV);
            int?[] types      = ParseIntArray(typesCSV);

            var data = _context.Equipments
                       .Include(x => x.LocalArea.ServiceArea.District.Region)
                       .Include(x => x.DistrictEquipmentType)
                       .Include(x => x.DumpTruck)
                       .Include(x => x.Owner)
                       .Include(x => x.EquipmentAttachments)
                       .Include(x => x.Notes)
                       .Include(x => x.Attachments)
                       .Include(x => x.History)
                       .Select(x => x);

            // Default search results must be limited to user
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            data = data.Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId));

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

            if (equipmentAttachment != null)
            {
                data = data.Where(x => x.EquipmentAttachments.Any(y => y.TypeName.ToLower().Contains(equipmentAttachment.ToLower())));
            }

            if (owner != null)
            {
                data = data.Where(x => x.Owner.Id == owner);
            }

            if (status != null)
            {
                // TODO: Change to enumerated type
                data = data.Where(x => x.Status.ToLower() == status.ToLower());
            }

            if (hired == true)
            {
                IQueryable <int?> hiredEquipmentQuery = _context.RentalAgreements
                                                        .Where(agreement => agreement.Status == "Active")
                                                        .Select(agreement => agreement.EquipmentId)
                                                        .Distinct();

                data = data.Where(e => hiredEquipmentQuery.Contains(e.Id));
            }

            if (types != null && types.Length > 0)
            {
                data = data.Where(x => types.Contains(x.DistrictEquipmentType.Id));
            }

            if (notverifiedsincedate != null)
            {
                data = data.Where(x => x.LastVerifiedDate >= notverifiedsincedate);
            }

            List <EquipmentViewModel> result = new List <EquipmentViewModel>();

            foreach (var item in data)
            {
                EquipmentViewModel newItem = item.ToViewModel();
                result.Add(newItem);
            }

            // second pass to do calculated fields.
            foreach (var equipmentViewModel in result)
            {
                CalculateViewModel(equipmentViewModel);
            }

            return(new ObjectResult(result));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Search Owners
        /// </summary>
        /// <remarks>Used for the owner search page.</remarks>
        /// <param name="localAreas">Local Areas (array of id numbers)</param>
        /// <param name="equipmentTypes">Equipment Types (array of id numbers)</param>
        /// <param name="owner"></param>
        /// <param name="status">Status</param>
        /// <param name="hired">Hired</param>
        /// <response code="200">OK</response>
        public virtual IActionResult OwnersSearchGetAsync(string localAreas, string equipmentTypes, int?owner, string status, bool?hired)
        {
            int?[] localAreasArray     = ParseIntArray(localAreas);
            int?[] equipmentTypesArray = ParseIntArray(equipmentTypes);

            // default search results must be limited to user
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            IQueryable <Owner> data = _context.Owners
                                      .Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId))
                                      .Include(x => x.LocalArea.ServiceArea.District.Region)
                                      .Include(x => x.Attachments)
                                      .Include(x => x.Contacts)
                                      .Select(x => x);

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

            if (status != null)
            {
                data = data.Where(x => String.Equals(x.Status, status, StringComparison.CurrentCultureIgnoreCase));
            }

            if (hired == true)
            {
                IQueryable <int?> hiredOwnersQuery = _context.RentalAgreements
                                                     .Where(agreement => agreement.Status == "Active")
                                                     .Join(
                    _context.Equipments,
                    agreement => agreement.EquipmentId,
                    equipment => equipment.Id,
                    (agreement, equipment) => new
                {
                    tempAgreement = agreement,
                    tempEqiupment = equipment
                }
                    )
                                                     .Where(projection => projection.tempEqiupment.OwnerId != null)
                                                     .Select(projection => projection.tempEqiupment.OwnerId)
                                                     .Distinct();

                data = data.Where(o => hiredOwnersQuery.Contains(o.Id));
            }

            if (equipmentTypesArray != null)
            {
                var equipmentTypeQuery = _context.Equipments
                                         .Where(x => equipmentTypesArray.Contains(x.DistrictEquipmentTypeId))
                                         .Select(x => x.OwnerId)
                                         .Distinct();

                data = data.Where(x => equipmentTypeQuery.Contains(x.Id));
            }

            if (owner != null)
            {
                data = data.Where(x => x.Id == owner);
            }

            List <Owner> result = data.ToList();

            return(new ObjectResult(new HetsResponse(result)));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Searches Owners
        /// </summary>
        /// <remarks>Used for the owner search page.</remarks>
        /// <param name="localAreasCSV">Local Areas (array of id numbers)</param>
        /// <param name="equipmentTypesCSV">Equipment Types (array of id numbers)</param>
        /// <param name="owner"></param>
        /// <param name="status">Status</param>
        /// <param name="hired">Hired</param>
        /// <response code="200">OK</response>
        public virtual IActionResult OwnersSearchGetAsync(string localAreasCSV, string equipmentTypesCSV, int?owner, string status, bool?hired)
        {
            int?[] localAreas     = ParseIntArray(localAreasCSV);
            int?[] equipmentTypes = ParseIntArray(equipmentTypesCSV);

            var data = _context.Owners
                       .Include(x => x.LocalArea.ServiceArea.District.Region)
                       .Include(x => x.Notes)
                       .Include(x => x.Attachments)
                       .Include(x => x.History)
                       .Include(x => x.Contacts)
                       .Select(x => x);

            // Default search results must be limited to user
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            data = data.Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId));

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

            if (status != null)
            {
                // TODO: Change to enumerated type
                data = data.Where(x => x.Status.ToLower() == status.ToLower());
            }

            if (hired == true)
            {
                IQueryable <int?> hiredOwnersQuery = _context.RentalAgreements
                                                     .Where(agreement => agreement.Status == "Active")
                                                     .Join(
                    _context.Equipments,
                    agreement => agreement.EquipmentId,
                    equipment => equipment.Id,
                    (agreement, equipment) => new
                {
                    tempAgreement = agreement,
                    tempEqiupment = equipment
                }
                    )
                                                     .Where(projection => projection.tempEqiupment.OwnerId != null)
                                                     .Select(projection => projection.tempEqiupment.OwnerId)
                                                     .Distinct();

                data = data.Where(o => hiredOwnersQuery.Contains(o.Id));
            }

            if (equipmentTypes != null)
            {
                var equipmentTypeQuery = _context.Equipments
                                         .Where(x => equipmentTypes.Contains(x.DistrictEquipmentTypeId))
                                         .Select(x => x.OwnerId)
                                         .Distinct();

                data = data.Where(x => equipmentTypeQuery.Contains(x.Id));
            }

            if (owner != null)
            {
                data = data.Where(x => x.Id == owner);
            }

            var result = data.ToList();

            return(new ObjectResult(result));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Searches Equipment
        /// </summary>
        /// <remarks>Used for the equipment search page.</remarks>
        /// <param name="localareas">Local Areas (array of id numbers)</param>
        /// <param name="types">Equipment Types (array of id numbers)</param>
        /// <param name="equipmentAttachment">Equipment Attachments </param>
        /// <param name="owner"></param>
        /// <param name="status">Status</param>
        /// <param name="hired">Hired</param>
        /// <param name="notverifiedsincedate">Not Verified Since Date</param>
        /// <response code="200">OK</response>
        public virtual IActionResult EquipmentSearchGetAsync(string localareas, string types, string equipmentAttachment,
                                                             int?owner, string status, bool?hired, DateTime?notverifiedsincedate)
        {
            int?[] localareasArray = ParseIntArray(localareas);
            int?[] typesArray      = ParseIntArray(types);

            // **********************************************************************
            // get initial resultset - results must be limited to user's dsitrict
            // **********************************************************************
            int?districtId = _context.GetDistrictIdByUserId(GetCurrentUserId()).Single();

            IQueryable <Equipment> data = _context.Equipments
                                          .Where(x => x.LocalArea.ServiceArea.DistrictId.Equals(districtId))
                                          .Include(x => x.LocalArea)
                                          .Include(x => x.DistrictEquipmentType)
                                          .ThenInclude(y => y.EquipmentType)
                                          .Include(x => x.Owner)
                                          .Include(x => x.EquipmentAttachments)
                                          .Select(x => x);

            // **********************************************************************
            // filter results based on search critera
            // **********************************************************************
            if (localareasArray != null && localareasArray.Length > 0)
            {
                data = data.Where(x => localareasArray.Contains(x.LocalArea.Id));
            }

            if (equipmentAttachment != null)
            {
                data = data.Where(x => x.EquipmentAttachments.Any(y => y.TypeName.ToLower().Contains(equipmentAttachment.ToLower())));
            }

            if (owner != null)
            {
                data = data.Where(x => x.Owner.Id == owner);
            }

            if (status != null)
            {
                data = data.Where(x => String.Equals(x.Status, status, StringComparison.CurrentCultureIgnoreCase));
            }

            // is the equipment is hired (search criteria)
            if (hired == true)
            {
                IQueryable <int?> hiredEquipmentQuery = _context.RentalAgreements
                                                        .Where(agreement => agreement.Status == "Active")
                                                        .Select(agreement => agreement.EquipmentId)
                                                        .Distinct();

                data = data.Where(e => hiredEquipmentQuery.Contains(e.Id));
            }

            if (typesArray != null && typesArray.Length > 0)
            {
                data = data.Where(x => typesArray.Contains(x.DistrictEquipmentType.Id));
            }

            if (notverifiedsincedate != null)
            {
                data = data.Where(x => x.LastVerifiedDate >= notverifiedsincedate);
            }

            // **********************************************************************
            // convert Equipment Model to View Model
            // **********************************************************************
            List <EquipmentViewModel> result = new List <EquipmentViewModel>();

            foreach (Equipment item in data)
            {
                EquipmentViewModel newItem = item.ToViewModel();

                newItem.NumberOfBlocks = GetNumberOfBlocks(item) + 1;
                result.Add(newItem);
            }

            // resort list using: LocalArea / District Equipment Type and SenioritySortOrder (desc)
            result = result.OrderBy(e => e.LocalArea.Name)
                     .ThenBy(e => e.DistrictEquipmentType.DistrictEquipmentName)
                     .ThenByDescending(e => e.SenioritySortOrder).ToList();

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