public IActionResult StopTime(int registratorId) { Registrator registrator = new Registrator { RegistratorId = registratorId }; TimeMeasurement measuredTime = new TimeMeasurement(); try { registrator = _iRegTempus.GetRegistratorBasedOnRegistratorId(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Fetching your data did not succed. Please make a manual note of present time."; return(View("Index")); } registrator.UserHaveStartedTimeMeasure = false; try { measuredTime = _iRegTempus.GetTimeMeasurement(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Fetching your start time did not succed. Please make a manual note of present time."; return(View("Index")); } DateTime stopTime = DateTime.Now; if (measuredTime.TimeStart.DayOfYear == stopTime.DayOfYear) { measuredTime = TimeMeasurement.stopClock(measuredTime, stopTime); } else { measuredTime = TimeMeasurement.complexStopClock(measuredTime); TimeMeasurement newMeasuredTime = TimeMeasurement.complexStartAndStopClock(registrator, stopTime); try { newMeasuredTime = _iRegTempus.CompleteTimeMeasurement(newMeasuredTime); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your stop time did not succed. Please make a manual note of present time."; return(View("Index")); } } try { measuredTime = _iRegTempus.CompleteTimeMeasurement(measuredTime); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your stop time did not succed. Please make a manual note of present time."; return(View("Index")); } registrator.StartedTimeMeasurement = 0; try { registrator = _iRegTempus.UpdateRegistrator(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your data did not succed. Please make a manual note of present time."; return(View("Index")); } ViewBag.SuccessMessage = "Your stop time is registered."; UserTimeRegistrationViewModel konvertedRegistrator = UserTimeRegistrationViewModel.RestructureTheRegistratorData(registrator); return(View("Index", konvertedRegistrator)); }