public RedirectToActionResult Submit(SortApplicationViewModel inputNumbers)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var sortId = ProcessSort(inputNumbers);
             return RedirectToAction("Index", new { sortId = sortId });
         }
         catch
         {
             return RedirectToAction("SortFailure");
         }
     }
     else return RedirectToAction("ModelNotValid", inputNumbers);
 }
        public IActionResult Index(Guid sortId)
        {
            var sortDetailsHistory = _sortDetailsRepository.GetAllSortDetails();
            if (sortId != Guid.Empty)
            {
                var sortDetails = _sortDetailsRepository.GetSortDetailsBySortId(sortId);
                if(sortDetails is null)
                {
                    return SortFailure();
                }

                var viewModel = new SortApplicationViewModel() { UnsortedNumbers = sortDetails.UnsortedNumbers, SortedNumbers = sortDetails.SortedNumbers, SortTime = sortDetails.SortTime.ToString(), 
                    SortType = sortDetails.SortType, SortStatus = "Sort Success", SortStatusColour = "Green", SortDetailsList = sortDetailsHistory };

                return View(viewModel);
            }
            else
            {
                return View(new SortApplicationViewModel() { SortDetailsList = sortDetailsHistory });
            }
        }
        public Guid ProcessSort(SortApplicationViewModel inputNumbers)
        {
            var unsortedNumbersList = inputNumbers.UnsortedNumbers.Split(',').Select(Int32.Parse).ToList();
            
            var watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            var sortedNumbersList = SortIntegers(unsortedNumbersList, inputNumbers.SortType);
            watch.Stop();
            var sortDuration = watch.ElapsedMilliseconds;
            var sortId = Guid.NewGuid();

            _sortDetailsRepository.Insert(new SortDetails
            {
                SortId = sortId,
                UnsortedNumbers = string.Join(",", unsortedNumbersList),
                SortedNumbers = string.Join(",", sortedNumbersList),
                SortType = inputNumbers.SortType,
                SortTime = sortDuration
            });
            return sortId;
        }
 public IActionResult ModelNotValid(SortApplicationViewModel invalidModel)
 {
     var sortDetailsHistory = _sortDetailsRepository.GetAllSortDetails();
     invalidModel.SortDetailsList = sortDetailsHistory;
     return View("Index", invalidModel);
 }