public async Task <IActionResult> Add(AddTodoViewModel model) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } if (ModelState.IsValid) { var todoItem = new TodoItem(model.Text, new Guid(user.Id)) { DateDue = model.DateDue }; await _repository.Add(todoItem); if (model.Labels != null) { string[] split = model.Labels.Split(",".ToCharArray()); foreach (var label in split) { var lab = await _repository.AddLabelToDb(new TodoItemLabel(label.ToUpper().Trim())); await _repository.AddLabelToTodoItem(lab, todoItem); } } return(RedirectToAction("Index")); } return(View(model)); }