public async Task <IActionResult> Create([Bind("ServiceBookLogId,Date,Mileage,ServiceType,NextServiceDate,NextServiceMileage,VehicleWork,Details")] ServiceBookLog serviceBookLog)
        {
            var currentUserId = userManager.GetUserId(User);

            if (ModelState.IsValid)
            {
                _context.Add(serviceBookLog);
                await _context.SaveChangesAsync();

                int?id = int.Parse(RouteData.Values["id"].ToString());

                if (id != null)
                {
                    var serviceBooks = new ServiceBook[]
                    {
                        new ServiceBook {
                            VehicleId = (int)id, ServiceBookLogId = serviceBookLog.ServiceBookLogId
                        }
                    };

                    foreach (ServiceBook serviceBook in serviceBooks)
                    {
                        _context.ServiceBooks.Add(serviceBook);
                    }
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction("Details", "Vehicles", new { id }));
            }
            return(View(serviceBookLog));
        }
        public async Task <IActionResult> Edit(int id, [Bind("ServiceBookLogId,Date,Mileage,ServiceType,NextServiceDate,NextServiceMileage,VehicleWork,Details")] ServiceBookLog serviceBookLog)
        {
            var currentUserId = userManager.GetUserId(User);

            if (id != serviceBookLog.ServiceBookLogId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(serviceBookLog);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ServiceBookLogExists(serviceBookLog.ServiceBookLogId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                var carId = _context.ServiceBooks.Where(x => x.ServiceBookId == id).Select(x => x.VehicleId).First();
                id = carId;

                return(RedirectToAction("Details", "Vehicles", new { id }));
            }
            return(View(serviceBookLog));
        }