public DrivenVehicleStatistics FromStartStatistics(int userid) { var statistics = new DrivenVehicleStatistics(); statistics.Reports = new List <ReportModel>(); foreach (var report in DBContext.Report) { if (report.Employee_Id == userid) { var newReport = new ReportModel() { Distance = report.Distance.Value, Employee_ID = report.Employee_Id, ReportDate = report.ReportDate, TotalPrice = report.TotalPrice.Value, Vehicle_ID = report.Vehicle_Id, PrimaryFuel_ID = report.PrimaryFuel_ID, PrimaryFuelAmount = report.PrimaryFuelAmount.Value, PrimaryFuelUnitPrice = report.PrimaryFuelUnitPrice.Value }; if (report.SecondaryFuel_ID != null) { newReport.SecondaryFuel_ID = report.SecondaryFuel_ID; newReport.SecondaryFuelAmount = report.SecondaryFuelAmount; newReport.SecondaryFuelUnitPrice = report.SecondaryFuelUnitPrice; } statistics.Reports.Add(newReport); } } return(CountStatistics.FixStatistics(statistics)); }
public DrivenVehicleStatistics DrivenVehicleStatistic(string regnr, int userid) { var statistics = new DrivenVehicleStatistics(); statistics.Reports = new List <ReportModel>(); foreach (var information in DBContext.Report) { if (information.Employee_Id == userid && regnr == information.Vehicle_Id) { var yearReport = new ReportModel() { Distance = information.Distance.Value, Employee_ID = information.Employee_Id, ReportDate = information.ReportDate, TotalPrice = information.TotalPrice.Value, Vehicle_ID = information.Vehicle_Id, PrimaryFuel_ID = information.PrimaryFuel_ID, PrimaryFuelAmount = information.PrimaryFuelAmount.Value, PrimaryFuelUnitPrice = information.PrimaryFuelUnitPrice.Value }; if (information.SecondaryFuel_ID != null) { yearReport.SecondaryFuel_ID = information.SecondaryFuel_ID; yearReport.SecondaryFuelAmount = information.SecondaryFuelAmount; yearReport.SecondaryFuelUnitPrice = information.SecondaryFuelUnitPrice; } statistics.Reports.Add(yearReport); } } return(CountStatistics.FixStatistics(statistics)); }
public static DrivenVehicleStatistics FixStatistics(DrivenVehicleStatistics fixReports) { int trip = 0; decimal primaryfuelamount = 0; decimal primaryfuelunitprice = 0; decimal secondaryfuelamount = 0; decimal secondaryfuelunitPrice = 0; int reports = 0; foreach (var report in fixReports.Reports) { primaryfuelunitprice += report.PrimaryFuelUnitPrice; primaryfuelamount += report.PrimaryFuelAmount; if (report.SecondaryFuel_ID != null) { secondaryfuelunitPrice += report.SecondaryFuelUnitPrice.Value; secondaryfuelamount += report.SecondaryFuelAmount.Value; } trip += report.Distance; reports++; } fixReports.PrimaryFuelAmountBeginning = Math.Round(primaryfuelamount / reports, 2); fixReports.PrimaryFuelUnitBeginning = Math.Round(primaryfuelunitprice / reports, 2); if (secondaryfuelamount > 0) { fixReports.SecondFuelAmountBeginning = Math.Round(secondaryfuelamount / reports, 2); fixReports.SecondFuelUnitBeginning = Math.Round(secondaryfuelunitPrice / reports, 2); } return(fixReports); }
public DrivenVehicleStatistics DriverYearMonthStatisics(string regnr, int userid, int year, int month) { var statistics = new DrivenVehicleStatistics(); statistics.Reports = new List <ReportModel>(); try { if (month == 13) { foreach (var report in DBContext.Report) { if (report.Employee_Id == userid && report.Vehicle_Id == regnr) { var newReport = new ReportModel() { Distance = report.Distance.Value, Employee_ID = report.Employee_Id, ReportDate = report.ReportDate, TotalPrice = report.TotalPrice.Value, Vehicle_ID = report.Vehicle_Id, PrimaryFuel_ID = report.PrimaryFuel_ID, PrimaryFuelAmount = report.PrimaryFuelAmount.Value, PrimaryFuelUnitPrice = report.PrimaryFuelUnitPrice.Value }; if (report.SecondaryFuel_ID != null) { newReport.SecondaryFuel_ID = report.SecondaryFuel_ID; newReport.SecondaryFuelAmount = report.SecondaryFuelAmount; newReport.SecondaryFuelUnitPrice = report.SecondaryFuelUnitPrice; } statistics.Reports.Add(newReport); } } if (statistics.Reports.Count > 0) { return(CountStatistics.FixStatistics(statistics)); } } if (month == 0) { foreach (var report in DBContext.Report) { if (report.Employee_Id == userid && report.ReportDate.Year == year && report.Vehicle_Id == regnr) { var newReport = new ReportModel() { Distance = report.Distance.Value, Employee_ID = report.Employee_Id, ReportDate = report.ReportDate, TotalPrice = report.TotalPrice.Value, Vehicle_ID = report.Vehicle_Id, PrimaryFuel_ID = report.PrimaryFuel_ID, PrimaryFuelAmount = report.PrimaryFuelAmount.Value, PrimaryFuelUnitPrice = report.PrimaryFuelUnitPrice.Value }; if (report.SecondaryFuel_ID != null) { newReport.SecondaryFuel_ID = report.SecondaryFuel_ID; newReport.SecondaryFuelAmount = report.SecondaryFuelAmount; newReport.SecondaryFuelUnitPrice = report.SecondaryFuelUnitPrice; } statistics.Reports.Add(newReport); } } if (statistics.Reports.Count > 0) { return(CountStatistics.FixStatistics(statistics)); } } if (month > 0) { foreach (var report in DBContext.Report) { if (report.Vehicle_Id == regnr && report.Employee_Id == userid && report.ReportDate.Year == year && report.ReportDate.Month == month) { var newReport = new ReportModel() { Distance = report.Distance.Value, Employee_ID = report.Employee_Id, ReportDate = report.ReportDate, TotalPrice = report.TotalPrice.Value, Vehicle_ID = report.Vehicle_Id, PrimaryFuel_ID = report.PrimaryFuel_ID, PrimaryFuelAmount = report.PrimaryFuelAmount.Value, PrimaryFuelUnitPrice = report.PrimaryFuelUnitPrice.Value }; if (report.SecondaryFuel_ID != null) { newReport.SecondaryFuel_ID = report.SecondaryFuel_ID; newReport.SecondaryFuelAmount = report.SecondaryFuelAmount; newReport.SecondaryFuelUnitPrice = report.SecondaryFuelUnitPrice; } statistics.Reports.Add(newReport); } } if (statistics.Reports.Count > 0) { return(CountStatistics.FixStatistics(statistics)); } } } catch (Exception) { throw; } return(new DrivenVehicleStatistics()); }