public IActionResult Insert(NumberOfBusStops numberOfBusStops)
        {
            LineNameVM lineNameVM = new LineNameVM()
            {
                NumberOfBusStops = numberOfBusStops.number,
                lineName         = new LineName(),
                busStopList      = new List <BusStopList>(),
                BusStopListItem  = _unitOfWork.BusStop.GetBusStopListDropDown(),
                IsReversedToo    = false
            };

            return(View(lineNameVM));
        }
        public IActionResult Insert(LineNameVM lineNameVM)
        {
            if (ModelState.IsValid)
            {
                if (_unitOfWork.LineName.GetFirstOrDefault(ln => ln.Name == lineNameVM.lineName.Name) != null)
                {
                    return(RedirectToAction(nameof(RepeatedName)));
                }
                else
                {
                    lineNameVM.lineName.IsActive = true;
                    _unitOfWork.LineName.Add(lineNameVM.lineName);
                    _unitOfWork.Save();

                    int iter = 1;
                    foreach (var item in lineNameVM.busStopList)
                    {
                        if (_unitOfWork.BusStop.Get(item.BusStopId).Name == "Brak")
                        {
                            break;
                        }
                        BusStopList busStopList = new BusStopList();
                        busStopList.BusStopNumber = iter;
                        busStopList.BusStopId     = item.BusStopId;
                        busStopList.LineNameId    = _unitOfWork.LineName.GetLast().Id;
                        _unitOfWork.BusStopList.Add(busStopList);
                        _unitOfWork.Save();
                        iter++;
                    }

                    if (lineNameVM.IsReversedToo)
                    {
                        LineName lineNameReversed = new LineName()
                        {
                            Name     = lineNameVM.ReversedLineName,
                            IsActive = true
                        };

                        _unitOfWork.LineName.Add(lineNameReversed);
                        _unitOfWork.Save();

                        iter = 1;
                        for (int i = lineNameVM.busStopList.Count - 1; i >= 0; i--)
                        {
                            if (_unitOfWork.BusStop.Get(lineNameVM.busStopList[i].BusStopId).Name == "Brak")
                            {
                                break;
                            }
                            BusStopList busStopList = new BusStopList();
                            busStopList.BusStopNumber = iter;
                            busStopList.BusStopId     = lineNameVM.busStopList[i].BusStopId;
                            busStopList.LineNameId    = _unitOfWork.LineName.GetLast().Id;
                            _unitOfWork.BusStopList.Add(busStopList);
                            _unitOfWork.Save();
                            iter++;
                        }
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(lineNameVM));
            }
        }