public async Task <IActionResult> Create(RouteCreateViewModel model) { // Create Route Route route = new Route { Note = model.Note, RouteID = model.RouteID, GripColour = model.GripColor, Type = model.Type }; _routeService.AddRoute(route, model.Date, model.RouteDifficultyID); // Create Section Relation _routeService.AddRouteToSections(route, model.RouteSectionID.ToList()); //Find all the users by id in model.Builders, in parallel, then discard missing results IEnumerable <ApplicationUser> builders = ( await Task.WhenAll ( model.Builders .Distinct() .Select(userId => _userService.FindByIdAsync(userId)) ) ) .Where(user => user != null); _routeService.AddBuildersToRoute(route, builders.ToList()); // Add the image(s) and imagepaths to the database, and the videourl string[] relativeImagePaths = await UploadImages(); _routeService.AddAttachment(route, model.VideoUrl, relativeImagePaths); return(RedirectToAction(nameof(List), "Route")); }