Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Description,State")] Brand brand)
        {
            if (id != brand.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(brand);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrandExists(brand.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(brand));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, int brandId, [Bind("Id,Description,State")] Model model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    model.Brand = await _context.Brands.SingleOrDefaultAsync(b => b.Id == brandId);

                    _context.Update(model);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ModelExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,IdentificationCardNumber,WorkSchedule,CommissionPercentage,EntryDate,State")] Employee employee)
        {
            if (id != employee.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(employee);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Naziv,ReleaseDate,Model,Cijena,MarkaID")] Cars cars)
        {
            if (id != cars.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cars);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarsExists(cars.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["MarkaID"] = new SelectList(_context.Set <Marka>(), "ID", "ID", cars.MarkaID);
            return(View(cars));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,naziv")] Marka marka)
        {
            if (id != marka.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(marka);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MarkaExists(marka.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(marka));
        }
Exemplo n.º 7
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));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,IdentificationCardNumber,PersonType,CreditCarNumber,CreditLimit,State")] Client client)
        {
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(client));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Edit(int id, int vehicleTypeId, int modelId, int fuelTypeId, [Bind("Id,Description,ChassisNumber,EngineNumber,PlateNumber,State")] Vehicle vehicle)
        {
            if (id != vehicle.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    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.Update(vehicle);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VehicleExists(vehicle.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }

            AddDataToViewBag(vehicleTypeId, modelId, fuelTypeId);
            return(View(vehicle));
        }