public IActionResult StartTime(int registratorId) { Registrator registrator = new Registrator { RegistratorId = registratorId }; try { registrator = _iRegTempus.GetRegistratorBasedOnRegistratorId(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Did not succed in fetching userdata"; return(View("Index")); } registrator.UserHaveStartedTimeMeasure = true; registrator.StartedTimeMeasurement = 0; TimeMeasurement timeRegistration = TimeMeasurement.startClock(registrator); try { timeRegistration = _iRegTempus.CreateNewMeasurement(timeRegistration); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Saving the new time registration did not succed"; return(View("Index")); } registrator.StartedTimeMeasurement = timeRegistration.TimeMeasurementId; try { registrator = _iRegTempus.UpdateRegistrator(registrator); } catch (NullReferenceException) { ViewBag.ErrorMessage = "Error: Updating your data did not succed"; return(View("Index")); } if (registrator.StartedTimeMeasurement != timeRegistration.TimeMeasurementId) { ViewBag.ErrorMessage = "Error: changing your details did not succed"; } ViewBag.SuccessMessage = "Your start time is registered."; UserTimeRegistrationViewModel konvertedRegistrator = UserTimeRegistrationViewModel.RestructureTheRegistratorData(registrator); return(View("Index", konvertedRegistrator)); }