コード例 #1
0
        public async Task <IActionResult> Create(int id, [Bind("Id,ReturnDate,AmountPerDay,DaysQuantity,Comment,State")] Rent rent)
        {
            if (id != rent.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    rent.RentDate = DateTime.Now;
                    _context.Update(rent);
                    var vehicle = _context.Inspections.Where(i => i.RentId == id).Include(i => i.Vehicle).FirstOrDefault().Vehicle;
                    vehicle.State = VehicleState.Rented;
                    _context.Update(vehicle);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RentExists(rent.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(rent));
        }
コード例 #2
0
ファイル: BrandController.cs プロジェクト: elvis072/RentCar
        public async Task <IActionResult> Create([Bind("Id,Description,State")] Brand brand)
        {
            if (ModelState.IsValid)
            {
                _context.Add(brand);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(brand));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("ID,naziv")] Marka marka)
        {
            if (ModelState.IsValid)
            {
                _context.Add(marka);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(marka));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Name,IdentificationCardNumber,WorkSchedule,CommissionPercentage,EntryDate,State")] Employee employee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(employee);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name,IdentificationCardNumber,PersonType,CreditCarNumber,CreditLimit,State")] Client client)
        {
            if (ModelState.IsValid)
            {
                _context.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(client));
        }
コード例 #6
0
ファイル: CarsController.cs プロジェクト: mailinov/pin
        public async Task <IActionResult> Create([Bind("ID,Naziv,ReleaseDate,Model,Cijena,MarkaID")] Cars cars)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cars);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MarkaID"] = new SelectList(_context.Set <Marka>(), "ID", "ID", cars.MarkaID);
            return(View(cars));
        }
コード例 #7
0
ファイル: ModelController.cs プロジェクト: elvis072/RentCar
        public async Task <IActionResult> Create(int brandId, [Bind("Description,State")] Model model)
        {
            if (ModelState.IsValid)
            {
                model.Brand = await _context.Brands.SingleOrDefaultAsync(b => b.Id == brandId);

                _context.Add(model);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            AddBrandsToViewBag();
            return(View(model));
        }
コード例 #8
0
        public async Task <IActionResult> Create(int employeeId, int clientId, int vehicleId, [Bind("FuelQuantity,HasScratches,HasReplacementRubber,HasCarJack,HasGlassBreaks,State,InspectionRubbers,RentId")] Inspection inspection)
        {
            if (ModelState.IsValid)
            {
                Rent rent = await _context.Rents.SingleOrDefaultAsync(r => r.Id == inspection.RentId);

                inspection.Employee = await _context.Employees.SingleOrDefaultAsync(e => e.Id == employeeId);

                inspection.Client = await _context.Clients.SingleOrDefaultAsync(c => c.Id == clientId);

                inspection.Vehicle = await _context.Vehicles.SingleOrDefaultAsync(v => v.Id == vehicleId);

                inspection.Date = DateTime.Now;
                rent.Inspection = inspection;

                try
                {
                    _context.Update(rent);
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(NotFound());
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction("Create", "Rent", new { id = rent.Id }));
            }

            AddDataToViewBag(employeeId, clientId, vehicleId);
            return(View(inspection));
        }
コード例 #9
0
        public async Task <IActionResult> Create(int vehicleTypeId, int modelId, int fuelTypeId, [Bind("Description,ChassisNumber,EngineNumber,PlateNumber,State")] Vehicle vehicle)
        {
            if (ModelState.IsValid)
            {
                vehicle.VehicleType = await _context.VehicleTypes.SingleOrDefaultAsync(vt => vt.Id == vehicleTypeId);

                vehicle.Model = await _context.Models.SingleOrDefaultAsync(m => m.Id == modelId);

                vehicle.FuelType = await _context.FuelTypes.SingleOrDefaultAsync(ft => ft.Id == fuelTypeId);

                _context.Add(vehicle);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            AddDataToViewBag();
            return(View(vehicle));
        }