public static string GetConclusion(FireHazardReport report) { string conclusion; var coefficient = report.FireHazardCoefficient; if (coefficient < 300) { conclusion = "1 классу пожарной опасности (отсутствие опасности)."; } else if (coefficient < 1000) { conclusion = "2 классу пожарной опасности (малая пожарная опасность)."; } else if (coefficient < 4000) { conclusion = "3 классу пожарной опасности (средняя пожарная опасность)."; } else if (coefficient < 10000) { conclusion = "4 классу пожарной опасности (высокая пожарная опасность)."; } else { conclusion = "5 классу пожарной опасности (чрезвычайная пожарная опасность)."; } return(string.Format("Комплексный показатель (К) равен {0:0.00}, что соответствует {1}", coefficient, conclusion)); }
public void Delete(FireHazardReport report) { using (var db = new DataConnection(_configurationString)) { db.Delete(report); } }
public FireHazardReport BuildReport(WeatherRecord record) { if (record == null) { throw new ArgumentNullException("record"); } if (record.Location == null) { throw new ArgumentException("record.Location"); } if (record.LocationId == null) { throw new ArgumentException("record.LocationId"); } var lastRainyWeather = _weatherRecordManager.GetLastRainyDay(record.LocationId.Value, record.Created.AddMonths(-2), record.Created.Date); var daysWithoutRain = DaysWithoutRain(record, lastRainyWeather); var report = new FireHazardReport { Created = DateTime.Now, WeatherRecordId = record.Id, Weather = record, LocationId = record.LocationId, Location = record.Location, LastRainyDate = lastRainyWeather, FireHazardCoefficient = CalculateFireHazardCoefficient(record, daysWithoutRain) }; return(report); }
private void SaveReportToDbIfNotExists(FireHazardReport report) { if (_isSaved) { return; } var saveTask = Task.Run(() => _fireHazardReportManager.Save(report)); saveTask.ContinueWith(task => GetRecentReports()); saveTask.ContinueWith(task => _isSaved = !task.IsFaulted); }
public void Save(FireHazardReport report) { using (var db = new DataConnection(_configurationString)) { if (report.Id.HasValue) { db.Update(report); } else { report.Id = Convert.ToInt32(db.InsertWithIdentity(report)); } } }
public void BuildReportTest(WeatherRecord current, DateTime lastRainyDay, FireHazardReport expectedReport) { var manager = new Mock <IWeatherRecordManager>(); manager.Setup( recordManager => recordManager.GetLastRainyDay(current.LocationId.Value, It.IsAny <DateTime>(), It.IsAny <DateTime>())) .Returns(lastRainyDay); var builder = new FireHazardReportBuilder(manager.Object); var actualReport = builder.BuildReport(current); Assert.Equal(expectedReport.FireHazardCoefficient, actualReport.FireHazardCoefficient, 0); }