コード例 #1
0
        //TODO: look into validation, if everything is correct
        /// <summary>
        /// Registers new vehicle
        /// </summary>
        /// <returns>Redirect to index if success, if fail redirect to same page</returns>
        public IActionResult OnPostConfirm()
        {
            Vehicle.Email = HttpContext.Session.GetString("email");

            if (Photo != null)
            {
                var path = Path.Combine(ihostingEnvironment.WebRootPath, "images", Vehicle.License + " - " + Photo.FileName);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    Photo.CopyToAsync(stream);
                    Vehicle.Vehicle_Image = Photo.FileName;
                }
            }

            if (VehiclesRepository.AddVehicle(Vehicle))
            {
                FixedCost.Insurance      = Vehicle.Insurance;
                FixedCost.Insurance_Date = Vehicle.Insurance_Date;
                FixedCost.Road_Tax       = Vehicle.Road_Tax;
                FixedCost.Road_Tax_Date  = Vehicle.Road_Tax_Date;
                if (CostsRepository.AddFixedCosts(FixedCost, Vehicle.License))
                {
                    return(RedirectToPage("Index"));
                }
                //if (Vehicle.Vehicle_Image != null)
            }
            return(Page());
        }
コード例 #2
0
 /// <summary>
 /// Deletes vehicle
 /// </summary>
 /// <param name="license">License of vehicle</param>
 /// <returns>Redirect to index if success, if fail to same page</returns>
 public IActionResult OnGetDeleteVehicle(string license)
 {
     if (CostsRepository.DeleteVehicleCosts(license))
     {
         if (VehiclesRepository.DeleteVehicle(license))
         {
             return(RedirectToPage("Index"));
         }
     }
     return(Page());
 }
コード例 #3
0
ファイル: AddCost.cshtml.cs プロジェクト: Webdev-01/MileAway
        public IActionResult OnPost(string license)
        {
            CostType      = HttpContext.Request.Query["type"];
            Costs.License = license;

            var vehicle = VehiclesRepository.GetVehicleByLicense(license);

            if (vehicle != null)
            {
                Milage_KM = vehicle.Mileage_Km;
            }


            if (CostType == "Brandstof")
            {
                if (Vehicles.Mileage_Km != Milage_KM)
                {
                    VehiclesRepository.UpdateMileage_KM(license, Vehicles.Mileage_Km);
                }
                CostsRepository.AddCostFuel(Costs);
            }
            else if (CostType == "Reparatie")
            {
                if (Invoice != null)
                {
                    var path = Path.Combine(ihostingEnvironment.WebRootPath, "invoices", license + " - " + Costs.Invoice_Doc + " - " + Invoice.FileName);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        Invoice.CopyToAsync(stream);
                    }

                    CostsRepository.AddCostRepairFile(Costs, Invoice.FileName);
                    if (Vehicles.Mileage_Km != Milage_KM)
                    {
                        VehiclesRepository.UpdateMileage_KM(license, Vehicles.Mileage_Km);
                    }
                }
                else
                {
                    CostsRepository.AddCostRepair(Costs);
                    if (Vehicles.Mileage_Km != Milage_KM)
                    {
                        VehiclesRepository.UpdateMileage_KM(license, Vehicles.Mileage_Km);
                    }
                }
            }

            return(RedirectToPage("Index"));
        }
コード例 #4
0
 public IActionResult OnGetDeleteCost(int id)
 {
     CostsRepository.DeleteCost(id);
     return(RedirectToPage("Index"));
 }
コード例 #5
0
 public void OnGet(string license)
 {
     Vehicle = VehiclesRepository.GetVehicleByLicense(license);
     Costs   = CostsRepository.GetCostsByLicenseInner(license);
 }
コード例 #6
0
ファイル: Index.cshtml.cs プロジェクト: Webdev-01/MileAway
        public IActionResult OnGet()
        {
            if (HttpContext.Session.GetString("email") == null)
            {
                return(RedirectToPage("Login"));
            }
            Costs    = CostsRepository.GetCostsByEmail(HttpContext.Session.GetString("email"));
            Vehicles = VehiclesRepository.GetVehiclesByEmail(HttpContext.Session.GetString("email"));

            //Calculates all overdue fixedCosts
            foreach (var item in Vehicles)
            {
                CostsRepository.FixedCostsMontly(item.License);
            }

            //Chart settings
            Chart chart = new Chart();

            chart.Type = Enums.ChartType.Line;
            ChartJSCore.Models.Data data = new ChartJSCore.Models.Data();
            data.Labels = new List <string>()
            {
                "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"
            };
            data.Datasets = new List <Dataset>();
            Random random = new Random();

            var year = HttpContext.Request.Query["Year"];

            if (!string.IsNullOrWhiteSpace(year))
            {
                Year = Convert.ToInt32(year);
            }
            else
            {
                Year = DateTime.Now.Year;
            }

            //Foreach to loop through every vehicle to get AnnualCosts and set it in the chart
            foreach (var vehicle in Vehicles)
            {
                int[,] randomColor = new int[3, 1] {
                    { random.Next(0, 255) }, { random.Next(0, 255) }, { random.Next(0, 255) }
                };
                IList <double?> annualCosts = CostsRepository.GetAnnualCosts(vehicle.License, Year);
                LineDataset     dataset     = new LineDataset()
                {
                    Label            = vehicle.Brand_Name + ' ' + vehicle.Model_Name,
                    Data             = annualCosts,
                    Fill             = "false",
                    LineTension      = 0.1,
                    BackgroundColor  = ChartColor.FromRgba((byte)randomColor[0, 0], (byte)randomColor[1, 0], (byte)randomColor[2, 0], 0.4),
                    BorderColor      = ChartColor.FromRgb((byte)randomColor[0, 0], (byte)randomColor[1, 0], (byte)randomColor[2, 0]),
                    BorderCapStyle   = "butt",
                    BorderDash       = new List <int> {
                    },
                    BorderDashOffset = 0.0,
                    BorderJoinStyle  = "miter",
                    PointBorderColor = new List <ChartColor> {
                        ChartColor.FromRgb(75, 192, 192)
                    },
                    PointBackgroundColor = new List <ChartColor> {
                        ChartColor.FromHexString("#ffffff")
                    },
                    PointBorderWidth = new List <int> {
                        1
                    },
                    PointHoverRadius = new List <int> {
                        5
                    },
                    PointHoverBackgroundColor = new List <ChartColor> {
                        ChartColor.FromRgb(75, 192, 192)
                    },
                    PointHoverBorderColor = new List <ChartColor> {
                        ChartColor.FromRgb(220, 220, 220)
                    },
                    PointHoverBorderWidth = new List <int> {
                        2
                    },
                    PointRadius = new List <int> {
                        1
                    },
                    PointHitRadius = new List <int> {
                        10
                    },
                    SpanGaps = false
                };
                data.Datasets.Add(dataset);
            }
            chart.Data = data;

            ViewData["chart"] = chart;


            return(Page());
        }