public static TimeRecordLite GetTimeRecords(int id, DbAppContext context, IConfiguration configuration) { HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.Equipment) .ThenInclude(y => y.DistrictEquipmentType) .ThenInclude(z => z.EquipmentType) .Include(x => x.Project) .Include(x => x.HetTimeRecord) .First(x => x.RentalAgreementId == id); // get the max hours for this equipment type float? hoursYtd = 0.0F; int maxHours = 0; string equipmentCode = ""; if (agreement.Equipment?.EquipmentId != null && agreement.Equipment.DistrictEquipmentType?.EquipmentType != null) { maxHours = Convert.ToInt32(agreement.Equipment.DistrictEquipmentType.EquipmentType.IsDumpTruck ? configuration.GetSection("MaximumHours:DumpTruck").Value : configuration.GetSection("MaximumHours:Default").Value); int equipmentId = agreement.Equipment.EquipmentId; hoursYtd = EquipmentHelper.GetYtdServiceHours(equipmentId, context); equipmentCode = agreement.Equipment.EquipmentCode; } // get the project info string projectName = ""; string projectNumber = ""; if (agreement.Project != null) { projectName = agreement.Project.Name; projectNumber = agreement.Project.ProvincialProjectNumber; } TimeRecordLite timeRecord = new TimeRecordLite { TimeRecords = new List <HetTimeRecord>() }; timeRecord.TimeRecords.AddRange(agreement.HetTimeRecord); timeRecord.EquipmentCode = equipmentCode; timeRecord.ProjectName = projectName; timeRecord.ProvincialProjectNumber = projectNumber; timeRecord.HoursYtd = hoursYtd; timeRecord.MaximumHours = maxHours; return(timeRecord); }
public static TimeRecordLite GetTimeRecords(int id, int?districtId, DbAppContext context, IConfiguration configuration) { // get fiscal year HetDistrictStatus status = context.HetDistrictStatus.AsNoTracking() .First(x => x.DistrictId == districtId); int?fiscalYear = status.CurrentFiscalYear; // get agreement and time records HetRentalAgreement agreement = context.HetRentalAgreement.AsNoTracking() .Include(x => x.Equipment) .ThenInclude(y => y.DistrictEquipmentType) .ThenInclude(z => z.EquipmentType) .Include(x => x.Project) .Include(x => x.HetTimeRecord) .First(x => x.RentalAgreementId == id); // get the max hours for this equipment type float? hoursYtd = 0.0F; int maxHours = 0; string equipmentCode = ""; if (agreement.Equipment?.EquipmentId != null && agreement.Equipment.DistrictEquipmentType?.EquipmentType != null) { maxHours = Convert.ToInt32(agreement.Equipment.DistrictEquipmentType.EquipmentType.IsDumpTruck ? configuration.GetSection("MaximumHours:DumpTruck").Value : configuration.GetSection("MaximumHours:Default").Value); int equipmentId = agreement.Equipment.EquipmentId; hoursYtd = EquipmentHelper.GetYtdServiceHours(equipmentId, context); equipmentCode = agreement.Equipment.EquipmentCode; } // get the project info string projectName = ""; string projectNumber = ""; if (agreement.Project != null) { projectName = agreement.Project.Name; projectNumber = agreement.Project.ProvincialProjectNumber; } // fiscal year in the status table stores the "start" of the year TimeRecordLite timeRecord = new TimeRecordLite(); if (fiscalYear != null) { DateTime fiscalYearStart = new DateTime((int)fiscalYear, 4, 1); timeRecord.TimeRecords = new List <HetTimeRecord>(); timeRecord.TimeRecords.AddRange(agreement.HetTimeRecord.Where(x => x.WorkedDate >= fiscalYearStart)); } timeRecord.EquipmentCode = equipmentCode; timeRecord.ProjectName = projectName; timeRecord.ProvincialProjectNumber = projectNumber; timeRecord.HoursYtd = hoursYtd; timeRecord.MaximumHours = maxHours; return(timeRecord); }