/// <summary> /// Indicates whether the <see cref="DbDVIRDefect"/> differs from the <see cref="DVIRDefect"/>, thereby requiring the <see cref="DbDVIRDefect"/> to be updated in the database. /// </summary> /// <param name="dbDVIRDefect">The <see cref="DbDVIRDefect"/> to be evaluated.</param> /// <param name="dvirDefect">The <see cref="DVIRDefect"/> to compare against.</param> /// <returns></returns> public static bool DbDVIRDefectRequiresUpdate(DbDVIRDefect dbDVIRDefect, DVIRDefect dvirDefect) { if (dbDVIRDefect.GeotabId != dvirDefect.Id.ToString()) { throw new ArgumentException($"Cannot compare DVIRDefect '{dvirDefect.Id}' with DbDVIRDefect '{dbDVIRDefect.GeotabId}' because the IDs do not match."); } DateTime dbDVIRDefectRepairDateTimeUtc = dbDVIRDefect.RepairDateTime.GetValueOrDefault().ToUniversalTime(); if (dbDVIRDefect.RepairDateTime != dvirDefect.RepairDateTime && dbDVIRDefectRepairDateTimeUtc != dvirDefect.RepairDateTime) { return(true); } User dvirDefectRepairUser = dvirDefect.RepairUser; if (dvirDefectRepairUser != null && dbDVIRDefect.RepairUserId != dvirDefectRepairUser.Id.ToString()) { return(true); } if (dvirDefect.RepairStatus != null && dbDVIRDefect.RepairStatus != dvirDefect.RepairStatus.ToString()) { return(true); } return(false); }
/// <summary> /// Creates and returns a <see cref="DbDVIRDefect"/> using information from the supplied inputs. /// </summary> /// <param name="dvirLog">The <see cref="DVIRLog"/> from which to capture information.</param> /// <param name="dvirDefect">The <see cref="DVIRDefect"/> from which to capture information.</param> /// <param name="defect">The <see cref="Defect"/> from which to capture information.</param> /// <param name="defectListPartDefect">The <see cref="DefectListPartDefect"/> from which to capture information.</param> /// <returns></returns> public static DbDVIRDefect GetDbDVIRDefect(DVIRLog dvirLog, DVIRDefect dvirDefect, Defect defect, DefectListPartDefect defectListPartDefect) { DbDVIRDefect dbDVIRDefect = new DbDVIRDefect { GeotabId = dvirDefect.Id.ToString(), DVIRLogId = dvirLog.Id.ToString(), DefectId = defect.Id.ToString(), DefectListAssetType = defectListPartDefect.DefectListAssetType, DefectListId = defectListPartDefect.DefectListID, DefectListName = defectListPartDefect.DefectListName, PartId = defectListPartDefect.PartID, PartName = defectListPartDefect.PartName, DefectName = defectListPartDefect.DefectName, DefectSeverity = defectListPartDefect.DefectSeverity }; if (dvirDefect.RepairDateTime != null) { dbDVIRDefect.RepairDateTime = dvirDefect.RepairDateTime; } if (dvirDefect.RepairStatus != null) { dbDVIRDefect.RepairStatus = dvirDefect.RepairStatus.ToString(); } User repairUser = dvirDefect.RepairUser; if (repairUser != null) { dbDVIRDefect.RepairUserId = repairUser.Id.ToString(); } return(dbDVIRDefect); }