Пример #1
0
        public async Task <IActionResult> AddNewVehicleType([Bind("NewVehicleType", "NewVehicleTypeSize", "RegistrationNumber", "NumberOfWheels", "Year", "Model", "Make", "Color", "VehicleTypesId", "MembershipId", "MemberName")] ParkVehicleCreateViewModel parkVehicleCreateViewModel)
        {
            bool bVehicleTypeExist = m_ParkVehicleService.IsVehicleTypeExisting(parkVehicleCreateViewModel.NewVehicleType);

            if (bVehicleTypeExist)
            {
                TempData["message"]       = "Vehicle type already exist";
                TempData["typeOfMessage"] = "error";

                //var member = await dbGarage.Membership.Where(i => i.MembershipId == parkVehicleCreateViewModel.MembershipId).FirstOrDefaultAsync();

                // Set up viewbag with messages
                GetMessageFromTempData();

                var model = new ParkVehicleCreateViewModel();
                model.VehicleId          = parkVehicleCreateViewModel.VehicleId;
                model.VehicleTypesId     = parkVehicleCreateViewModel.VehicleTypesId;
                model.RegistrationNumber = parkVehicleCreateViewModel.RegistrationNumber;
                model.NumberOfWheels     = parkVehicleCreateViewModel.NumberOfWheels;
                model.Year               = parkVehicleCreateViewModel.Year;
                model.Model              = parkVehicleCreateViewModel.Model;
                model.Make               = parkVehicleCreateViewModel.Make;
                model.Color              = parkVehicleCreateViewModel.Color;
                model.NewVehicleType     = parkVehicleCreateViewModel.NewVehicleType;
                model.NewVehicleTypeSize = parkVehicleCreateViewModel.NewVehicleTypeSize;
                model.MemberName         = parkVehicleCreateViewModel.MemberName;

                //if (member != null)
                //    model.MemberName = member.FirstName + " " + member.LastName;

                model.MembershipId      = parkVehicleCreateViewModel.MembershipId;
                model.ParkingPlaceId    = parkVehicleCreateViewModel.ParkingPlaceId;
                model.MembershipId      = parkVehicleCreateViewModel.MembershipId;
                model.VehicleTypes      = m_ParkVehicleService.CreateVehicleTypeDropDown();
                model.IsGarageFull      = m_ParkVehicleService.IsGarageFull();
                model.FreeParkingPlaces = m_ParkVehicleService.CreateFreeParkingPlaceDropDown();

                return(View(nameof(ParkNewVehicle), model));
            }

            VehicleType vehicleType = new VehicleType();

            vehicleType.Size      = 1;// TODO. Size is optional. parkVehicleCreateViewModel.NewVehicleTypeSize;
            vehicleType.Type_Name = parkVehicleCreateViewModel.NewVehicleType;
            dbGarage.VehicleType.Add(vehicleType);
            dbGarage.SaveChanges();

            TempData["message"]       = $"Has added Vehicle type {parkVehicleCreateViewModel.NewVehicleType}";
            TempData["typeOfMessage"] = "info";

            return(RedirectToAction(nameof(ParkNewVehicle)));
        }
Пример #2
0
        public async Task <IActionResult> ParkCreatedVehicle([Bind("MembershipId", "ParkingPlaceId", "RegistrationNumber", "NumberOfWheels", "Year", "Model", "Make", "Color", "VehicleTypesId")] ParkVehicleCreateViewModel parkVehicleCreateViewModel)
        {
            if (ModelState.IsValid)
            {
                var parkingPlace = await dbGarage.ParkingPlace.Where(i => i.ParkingPlaceId == parkVehicleCreateViewModel.ParkingPlaceId).FirstOrDefaultAsync();

                if (parkingPlace != null)
                {
                    Vehicle vehicle = new Vehicle();
                    vehicle.RegistrationNumber = parkVehicleCreateViewModel.RegistrationNumber;
                    vehicle.NumberOfWheels     = parkVehicleCreateViewModel.NumberOfWheels;
                    vehicle.Year          = parkVehicleCreateViewModel.Year;
                    vehicle.Model         = parkVehicleCreateViewModel.Model;
                    vehicle.Make          = parkVehicleCreateViewModel.Make;
                    vehicle.Color         = parkVehicleCreateViewModel.Color;
                    vehicle.CheckInTime   = DateTime.Now;
                    vehicle.IsParked      = true;
                    vehicle.MembershipId  = parkVehicleCreateViewModel.MembershipId;
                    vehicle.VehicleTypeId = parkVehicleCreateViewModel.VehicleTypesId;
                    vehicle.CheckInTime   = DateTime.Now;

                    // TODO. För närvarande kan ett fordon bara parkera i en parkeringsplats. Flera platser är överkurs..
                    vehicle.ParkingPlaceId = parkVehicleCreateViewModel.ParkingPlaceId;

                    try
                    {
                        dbGarage.Vehicle.Add(vehicle);
                        await dbGarage.SaveChangesAsync();

                        parkingPlace.IsOccupied = true;
                        parkingPlace.VehicleId  = vehicle.VehicleId;
                        await dbGarage.SaveChangesAsync();

                        TempData["message"]       = "You have parked vehicle " + parkVehicleCreateViewModel.RegistrationNumber;
                        TempData["typeOfMessage"] = "info";

                        return(RedirectToAction(nameof(Index)));
                    }
                    catch (Exception e)
                    {
                    }
                }

                TempData["message"]       = "We cant park vehicle";
                TempData["typeOfMessage"] = "error";
            }

            return(RedirectToAction(nameof(ParkNewVehicle)));
        }
Пример #3
0
        public async Task <IActionResult> ParkNewVehicle(int MembershipId)
        {
            // Set up viewbag with messages
            GetMessageFromTempData();

            var model = new ParkVehicleCreateViewModel();

            var member = await dbGarage.Membership.Where(i => i.MembershipId == MembershipId).FirstOrDefaultAsync();

            if (member != null)
            {
                model.MemberName = member.FirstName + " " + member.LastName;
            }

            model.MembershipId      = MembershipId;
            model.VehicleTypes      = m_ParkVehicleService.CreateVehicleTypeDropDown();
            model.IsGarageFull      = m_ParkVehicleService.IsGarageFull();
            model.FreeParkingPlaces = m_ParkVehicleService.CreateFreeParkingPlaceDropDown();

            return(View(model));
        }