public ActionResult Create()
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();

            RunningchartModel model = new RunningchartModel();
            model.BillDate = DateTime.Now;
            model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());

            ViewBag.Mode = "create";
            return View(model);
        }
        public ActionResult Create(RunningchartModel model)
        {
            try
            {
                Runningchart runningChart = ModelMapper.GetRunningchartFromRunningchartModel(model);
                runningChart.EnteredBy = (Session[SessionKeys.UserInfo] as UserModel).Id; // Set DEO
                int chartId = runningchartService.AddRunningchart(runningChart);
                return RedirectToAction("index", new { lastChartId = chartId });
            }
            catch
            {
                IVehicleService vehicleServcie = new VehicleService();
                IProjectService projectService = new ProjectService();

                model.RunningchartId = runningchartService.GetNextRunningchartId();
                model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
                model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
                model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());

                return View(model);
            }
        }
        public ActionResult Print(int id)
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();
            IPumpstationService pumpstationService = new PumpstationService();
            var pumpstations = pumpstationService.GetAllPumpstations();
            var projects = projectService.GetAllActiveProjects();
            var lubricants = vehicleServcie.GetAllLubricantTypes();
            var vehicles = vehicleServcie.GetAllVehicles();
            var chart = runningchartService.GetRunningChart(id);

            dsRunningchart ds = new dsRunningchart();
            DataTable runningchartTable = ds.Tables["Runningchart"].Clone();
            DataTable runningchartDetailsTable = ds.Tables["RunningchartDetails"].Clone();
            DataTable runningchartPumpstationsTable = ds.Tables["RunningchartPumpstation"].Clone();
            DataTable runningchartLubricantsTable = ds.Tables["RunningchartLubricant"].Clone();

            PopulateRunningchartTable(chart, runningchartTable, vehicles);
            PopulateRunningchartDetailsTable(chart.RunningchartDetails, runningchartDetailsTable, projects);
            PopulateRunningchartPumpstationTable(chart.RunningchartPumpstation, runningchartPumpstationsTable, pumpstations);
            PopulateRunningchartLubricantTable(chart.RunningchartLubricants, runningchartLubricantsTable, pumpstations, lubricants);

            ReportClass reportClass = new ReportClass();
            reportClass.FileName = Server.MapPath("~/Reports/Runningchart.rpt");
            reportClass.Load();
            reportClass.SummaryInfo.ReportTitle = "Running Chart";
            reportClass.Database.Tables["Runningchart"].SetDataSource(runningchartTable);
            reportClass.Database.Tables["RunningchartDetails"].SetDataSource(runningchartDetailsTable);
            reportClass.Database.Tables["RunningchartPumpstation"].SetDataSource(runningchartPumpstationsTable);
            reportClass.Database.Tables["RunningchartLubricant"].SetDataSource(runningchartLubricantsTable);

            Stream compStream = reportClass.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            return File(compStream, "application/pdf");
        }
        private RunningchartModel GetRunningchartModel(int runningChartId)
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();
            IPumpstationService pumpstationService = new PumpstationService();
            var chart = runningchartService.GetRunningChart(runningChartId);
            var model = ModelMapper.GetRunningchartModel(chart);
            model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());
            model.Pumpstations = ModelMapper.GetPumpStationModelList(pumpstationService.GetAllPumpstations());
            model.VehicleRentalTypes = new List<VehicleRentalTypeModel>()
            {
                new VehicleRentalTypeModel() { Id = (int)RentalType.Company, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Company) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.CompanyHired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.CompanyHired) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.Hired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Hired) }
            }; // Not worth to do a DB call since this is very static

            return model;
        }
        public ActionResult PoulateLubricantItems(bool isAddingNewItem)
        {
            IVehicleService vehicleServcie = new VehicleService();
            RunningchartModel model = new RunningchartModel();
            List<ChartLubricantItemModel> existingLubricantItems = new List<ChartLubricantItemModel>();
            UpdateModel<List<ChartLubricantItemModel>>(existingLubricantItems);

            IPumpstationService pumpstationService = new PumpstationService();
            model.Pumpstations = ModelMapper.GetPumpStationModelList(pumpstationService.GetAllPumpstations());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.SelectedLubricants = new List<ChartLubricantItemModel>();

            // Add existing chart items
            foreach (var item in existingLubricantItems)
            {
                if (!item.IsRemoving)
                {
                    model.SelectedLubricants.Add(item);
                }
            }

            // Add new chart item
            if (isAddingNewItem)
            {
                model.SelectedLubricants.Add(new ChartLubricantItemModel()
                {
                    SelectedPumpstationId = 0,
                    SelectedLubricantTypeId = 0,
                    PumpAmount = 0
                });
            }

            return PartialView("_Lubricants", model);
        }