public async Task <IActionResult> ClockInLunch(string moniker) { try { var jobsite = await _repository.GetJobsiteAsync(moniker); if (jobsite == null) { return(NotFound()); } var user = await _userRepository.GetUser(_userAccessor.GetCurrentUsername()); //If not already clocked in, bad request var currentlyClockedin = await _timestampRepository.GetClockedInTimestamp(user); if (currentlyClockedin == null) { return(BadRequest($"You must first be clocked in to {jobsite.Moniker} to clock in for lunch. ")); } //if clocked in to another job, bad request if (currentlyClockedin.JobsiteId != jobsite.JobsiteId) { return(BadRequest($"You're currently clocked in to another job: {currentlyClockedin.Jobsite.Moniker}")); } //if already clocked in for lunch, bad request if (currentlyClockedin.LunchStamp != System.DateTimeOffset.MinValue) { return(BadRequest($"You've already clocked in for lunch.")); } //if clockedin to the correct jobsite, clockinLunch var success = await _timestampRepository.ClockInLunch(user); if (success) { return(Ok("Successfully clocked in for lunch")); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Server Error: Failed to clock in for lunch")); } return(BadRequest()); }