Exemplo n.º 1
0
        public async Task <IActionResult> Parkthis(int vehicleid)
        {
            var thisvehicle = await _context.Vehicles.Where(v => v.Id == vehicleid).FirstOrDefaultAsync();

            var           memberid        = thisvehicle.MemberId;
            ParkedVehicle InparkedVehicle = new ParkedVehicle
            {
                MemberId  = memberid,
                Member    = await _context.Members.Where(m => m.Id == memberid).FirstOrDefaultAsync(),
                VehicleId = vehicleid,
                Vehicle   = thisvehicle
            };

            if (parkhouse.Park(InparkedVehicle))
            {
                _context.Add(InparkedVehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = InparkedVehicle.Id }));
            }
            else
            {
                var svar = new SingelViewModel
                {
                    ParkedVehicle = new ParkedViewModel
                    {
                        Vehicle = new Vehicle
                        {
                            RegNr = thisvehicle.RegNr
                        }
                    }
                };
                return(View("GarageFull", svar));
            }
        }
Exemplo n.º 2
0
        // GET: ParkedVehicles/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var res  = (await AddTimeAndPrice(true));
            var svar = new SingelViewModel
            {
                ParkedVehicle = new ParkedViewModel
                {
                    Vehicle = res.Select(o => o.Vehicle).Where(v => v.ParkedVehicles.Any(pv => pv.Id == id)).FirstOrDefault()
                    ,
                    VehicleTyp = res.Select(o => o.VehicleTyp).Where(vt => vt.Vehicles.Any(v => v.ParkedVehicles.Any(pv => pv.Id == id))).FirstOrDefault()
                    ,
                    Member = res.Select(o => o.Member).Where(m => m.Vehicles.Any(v => v.ParkedVehicles.Any(pv => pv.Id == id))).FirstOrDefault()
                }
            };

            svar.ParkedVehicle.ParkedVehicles = svar.ParkedVehicle.Vehicle.ParkedVehicles.Where(pv => pv.Id == id).Select(x => new SubParkedViewModel
            {
                ParkedVehicle = x
            }).ToList();
            //await RePark();
            if (svar.ParkedVehicle == null)
            {
                return(NotFound());
            }

            return(View(svar));
        }
Exemplo n.º 3
0
        // GET: ParkedVehicles/Receipt
        public async Task <IActionResult> Receipt(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            await InitPlots();

            var res = await AddTimeAndPrice(true);

            var svar = new SingelViewModel
            {
                ParkedVehicle = new ParkedViewModel
                {
                    Vehicle = res.Select(o => o.Vehicle).Where(v => v.ParkedVehicles.Any(pv => pv.Id == id)).FirstOrDefault()
                    ,
                    VehicleTyp = res.Select(o => o.VehicleTyp).Where(vt => vt.Vehicles.Any(v => v.ParkedVehicles.Any(pv => pv.Id == id))).FirstOrDefault()
                    ,
                    Member = res.Select(o => o.Member).Where(m => m.Vehicles.Any(v => v.ParkedVehicles.Any(pv => pv.Id == id))).FirstOrDefault()
                }
            };
            var CostPerHour = res.Where(o => o.ParkedVehicles.Any(pv => pv.ParkedVehicle.Id == id)).Select(o => o.ParkedVehicles).Select(spv => spv.Select(pv => pv.CostPerHour)).FirstOrDefault().FirstOrDefault();
            var Price       = res.Where(o => o.ParkedVehicles.Any(pv => pv.ParkedVehicle.Id == id)).Select(o => o.ParkedVehicles).Select(spv => spv.Select(pv => pv.Price)).FirstOrDefault().FirstOrDefault();
            var ParkedTime  = res.Where(o => o.ParkedVehicles.Any(pv => pv.ParkedVehicle.Id == id)).Select(o => o.ParkedVehicles).Select(spv => spv.Select(pv => pv.ParkedTime)).FirstOrDefault().FirstOrDefault();

            svar.ParkedVehicle.ParkedVehicles = svar.ParkedVehicle.Vehicle.ParkedVehicles.Where(pv => pv.Id == id).Select(x => new SubParkedViewModel
            {
                ParkedVehicle = x,
                CostPerHour   = CostPerHour,
                Price         = Price,
                ParkedTime    = ParkedTime
            }).ToList();

            return(View(svar));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> VehicleDetails(int?vehicleid)
        {
            if (vehicleid == null)
            {
                return(NotFound());
            }

            var res = _context.Vehicles
                      .Include(v => v.VehicleTyp)
                      .Include(v => v.Member)
                      .Where(v => v.Id == vehicleid);

            if (res.Count() == 0)
            {
                return(NotFound());
            }

            var svar = new SingelViewModel
            {
                ParkedVehicle = new ParkedViewModel
                {
                    //        ParkedVehicles = res.
                    //   Select(o => o.ParkedVehicles).Select(pw => pw.Where(pwm => pwm.ParkedVehicle.Id == id))
                    //   .FirstOrDefault().ToList(),
                    Vehicle = await res.FirstOrDefaultAsync()
                    ,
                    VehicleTyp = await res.Select(v => v.VehicleTyp).FirstOrDefaultAsync()
                    ,
                    Member = await res.Select(v => v.Member).FirstOrDefaultAsync()
                }
            };

            svar.ParkedVehicle.ParkedVehicles = new List <SubParkedViewModel>
            {
                new SubParkedViewModel {
                    ParkedTime    = null,
                    ParkedVehicle = new ParkedVehicle
                    {
                        ParkInDate = null,
                        Where      = null
                    }
                }
            };



            return(View("Details", svar));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,VehicleTypId,VehicleTyp,RegNr,VehicleColor,VehicleModel,VehicleBrand,NumberOfWheels,ParkInDate,ParkOutDate,MemberId")] CreateSetViewModel parkedVehicle)
        //   public async Task<IActionResult> Create(CreateSetViewModel parkedVehicle)
        {
            var reg_bussey = await _context.ParkedVehicle.Where(v => v.Vehicle.RegNr == parkedVehicle.RegNr && v.ParkOutDate == null).ToListAsync();

            var svar = new SingelViewModel
            {
                ParkedVehicle = new ParkedViewModel
                {
                    Vehicle = new Vehicle
                    {
                        RegNr = parkedVehicle.RegNr
                    }
                }
            };

            if (reg_bussey.Count > 0)
            {
                // return RedirectToAction(nameof(Create));

                return(View("NotCreate", svar));
            }

            if (ModelState.IsValid)
            {
                await InitPlots();

                // if model does not exist.
                if (!(_context.Vehicles.Any(v => v.RegNr == parkedVehicle.RegNr)))
                {
                    var initVehicle = new Vehicle
                    {
                        VehicleTypId   = parkedVehicle.VehicleTypId,
                        RegNr          = parkedVehicle.RegNr,
                        VehicleColor   = parkedVehicle.VehicleColor,
                        VehicleModel   = parkedVehicle.VehicleModel,
                        VehicleBrand   = parkedVehicle.VehicleBrand,
                        NumberOfWheels = parkedVehicle.NumberOfWheels,
                        MemberId       = parkedVehicle.MemberId
                    };
                    _context.Vehicles.Add(initVehicle);
                    await _context.SaveChangesAsync();
                }

                parkedVehicle.VehicleTyp = await _context.VehicleTyp.Where(v => v.VehicleTypId == parkedVehicle.VehicleTypId).FirstOrDefaultAsync();

                ParkedVehicle InparkedVehicle = new ParkedVehicle
                {
                    MemberId  = parkedVehicle.MemberId,
                    Member    = await _context.Members.Where(m => m.Id == parkedVehicle.MemberId).FirstOrDefaultAsync(),
                    VehicleId = await _context.Vehicles.Where(m => m.RegNr == parkedVehicle.RegNr).Select(m => m.Id).FirstOrDefaultAsync(),
                    Vehicle   = await _context.Vehicles.Where(m => m.RegNr == parkedVehicle.RegNr).FirstOrDefaultAsync()
                };

                if (parkhouse.Park(InparkedVehicle))
                {
                    _context.Add(InparkedVehicle);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Details), new { id = InparkedVehicle.Id }));
                }
                else
                {
                    return(View("GarageFull", svar));
                }
            }

            return(View(svar));
        }