public async Task <IActionResult> Create(ViajeViewModel vm) { var services = new WorkflowServices(_context, _userManager, _getterUtils, _signInManager); var iterCmd = new ItinerarioCommand() { UsuarioID = _userManager.GetUserId(User) }; services.RegisterItinerarioAsync(iterCmd); var user = await _userManager.GetUserAsync(User); var iterID = user.Itinerarios.Last().ItinerarioID; for (int i = 0; i < vm.Motivo.Count; ++i) { if (vm.Motivo[i] is null) { vm.Motivo[i] = ""; } } for (int i = 0; i < vm.Country.Count(); i++) { var viajeCmd = new ViajeCommand(iterID, user.Id, vm.Country[i], vm.City[i], vm.Motivo[i], vm.Start[i], vm.End[i]); services.RegisterViajeAsync(viajeCmd); } services.CalculateDates(services.GetItinerario(iterID)); services.CreateItinerarioWorkflow(iterID, User.Claims.Where(x => x.Type == "Institucion").Single().Value); return(RedirectToAction("ViewTrips")); }
public long RegisterViajeAsync(ViajeCommand cmd) { //cmd.Institucion = _institucionDbAccess.GetInstitucion(cmd.InstitucionName); cmd.Pais = _paisDbAccess.GetPais(cmd.PaisName); try { cmd.Itinerario = _userDbAccess.GetItinerario(cmd.UsuarioId, cmd.ItinerarioID); } catch (InvalidOperationException) { return(-1); } var viaje = _runnerViaje.RunAction(cmd); return(viaje.ViajeID); }