public async Task <IActionResult> Create(TimesheetEntryViewModel viewModel) { if (ModelState.IsValid) { TimesheetEntry timesheetEntry = _mapper.MapViewModelToTimesheetEntry(viewModel); if (NoEntryExistsForSameDateAndProject(timesheetEntry)) { _context.Add(timesheetEntry); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { ViewBag.ErrorTitle = "Error"; ViewBag.ErrorMessage = "User already has a timesheet entry for the same date and project"; return(View("CustomError")); } } return(View(viewModel)); }