public async Task <SavePokedexInfoResponse> UpdateAsync(Guid id, PokedexInfo pokedexInfo) { var existingRepository = await _pokedexInfoRepository.FindByIdAsync(id); if (existingRepository == null) { return(new SavePokedexInfoResponse("Informacao nao encontrada")); } existingRepository.Numero = pokedexInfo.Numero; existingRepository.Name = pokedexInfo.Name; existingRepository.Type_1 = pokedexInfo.Type_1; existingRepository.Type_2 = pokedexInfo.Type_2; existingRepository.Total = pokedexInfo.Total; existingRepository.HP = pokedexInfo.HP; existingRepository.Attack = pokedexInfo.Attack; existingRepository.Defense = pokedexInfo.Defense; existingRepository.SP_Atk = pokedexInfo.SP_Atk; existingRepository.SP_Def = pokedexInfo.SP_Def; existingRepository.Speed = pokedexInfo.Speed; existingRepository.Generation = pokedexInfo.Generation; existingRepository.Legendary = pokedexInfo.Legendary; try { _pokedexInfoRepository.Update(existingRepository); await _unitOfWork.CompleteAsync(); return(new SavePokedexInfoResponse(existingRepository)); } catch (Exception ex) { return(new SavePokedexInfoResponse($"Erro ao Atualizar: {ex.Message}")); } }
public async Task <SavePokedexInfoResponse> SaveAsync(PokedexInfo pokedexInfo) { try { await _pokedexInfoRepository.AddAsync(pokedexInfo); await _unitOfWork.CompleteAsync(); return(new SavePokedexInfoResponse(pokedexInfo)); } catch (Exception ex) { return(new SavePokedexInfoResponse($"Erro ao salvar pokedex: {ex.Message}")); } }
public SavePokedexInfoResponse(PokedexInfo pokedexInfo) : this(true, string.Empty, pokedexInfo) { }
private SavePokedexInfoResponse(bool success, string message, PokedexInfo pokedexInfo) : base(success, message) { PokedexInfo = pokedexInfo; }
public PokemonRegionViewModel(INavigationService navigationService, IAPIService apiService, IGruposRegionRepository gruposRegionRepository, IGrupoPokemonsRepository grupoPokemonsRepository) : base(navigationService) { _apiService = apiService; _navigationService = navigationService; _gruposRegionRepository = gruposRegionRepository; _grupoPokemonsRepository = grupoPokemonsRepository; #region Commands Logic CancelCreation = new Command(async() => { await _navigationService.GoBackAsync(); }); SaveGroup = new Command(async() => { try { UserDialogs.Instance.ShowLoading(null, MaskType.None); //validate pokemons number if (PokemonsCounter < 3 || PokemonsCounter > 6) { UserDialogs.Instance.HideLoading(); await App.Current.MainPage.DisplayAlert("Error", "You must add at min. 3 pokemons or max. 6 pokemons", "ok"); return; } var result1 = false; var result2 = false; if (CrossConnectivity.Current.IsConnected) { if (IsCreate) { //Create Group group first var group = new GruposRegion { GrupoId = await _gruposRegionRepository.GetLastID() + 1, GrupoName = GroupName, GrupoTipo = GroupType, PokedexDescription = PokedexDescription, Image = "", Region = PokedexInfo.FirstOrDefault().name, UserId = await SecureStorage.GetAsync("UserId"), Token = Convert.ToBase64String(Guid.NewGuid().ToByteArray()), GrupoIdFather = null }; result1 = await _gruposRegionRepository.SaveData(group); if (result1) { //then we add pokemons related var data = PokemonList.Where(x => x.IsSelected).Select(x => new GrupoPokemons { GroupId = group.GrupoId, Pokemon = x.name }); result2 = await _grupoPokemonsRepository.SaveDataRange(data); } if (result1 && result2) { await App.Current.MainPage.DisplayAlert("Success", "Your group was created successfully", "ok"); var navigationParams = new NavigationParameters(); navigationParams.Add("RegionName", group.Region); await navigationService.GoBackAsync(navigationParams); } else { UserDialogs.Instance.HideLoading(); ErrorAlert(); await navigationService.GoBackAsync(); } } else { GruposRegion.GrupoName = GroupName; GruposRegion.GrupoTipo = GroupType; GruposRegion.PokedexDescription = PokedexDescription; result1 = await _gruposRegionRepository.UpdateData(GruposRegion); if (result1) { //then we add pokemons related and delete pokemons non related var oldValues = (await _grupoPokemonsRepository.GetDataByGrupoId(GruposRegion.GrupoId)).ToList(); var data = PokemonList.Where(x => x.IsSelected).Select(x => new GrupoPokemons { GroupId = GruposRegion.GrupoId, Pokemon = x.name }); //if old data does not appear, it means it was no unselected foreach (var item in oldValues) { if (!data.Select(x => x.Pokemon).Contains(item.Pokemon)) { await _grupoPokemonsRepository.DeleteData(item.Id, string.Empty, string.Empty); } } //if new data does not appear, it means it must be added foreach (var item in data) { if (!oldValues.Select(x => x.Pokemon).Contains(item.Pokemon)) { item.Id = await _gruposRegionRepository.GetLastID() + 1; await _grupoPokemonsRepository.SaveData(item); } } result2 = true; } if (result1 && result2) { UserDialogs.Instance.HideLoading(); await App.Current.MainPage.DisplayAlert("Success", "Your group was modified successfully", "ok"); var navigationParams = new NavigationParameters(); navigationParams.Add("GrupoId", GruposRegion.GrupoId); await navigationService.GoBackAsync(navigationParams); } else { UserDialogs.Instance.HideLoading(); ErrorAlert(); await navigationService.GoBackAsync(); } } } else { NoInternetAlert(); } } catch (Exception ex) { ErrorAlert(); await navigationService.GoBackAsync(); } }); #endregion }
public override void OnNavigatedTo(INavigationParameters parameters) { Device.BeginInvokeOnMainThread(async() => { UserDialogs.Instance.ShowLoading(null, MaskType.Clear); if (parameters != null && parameters.Count > 0) { if (PokedexInfo == null) { PokedexInfo = new List <Pokedex>((IList <Pokedex>)parameters["pokedexes"]); } if (CrossConnectivity.Current.IsConnected) { if (PokedexInfo.Count() > 0) { //Get all pokemons from region selected var pokemons = new List <PokemonSpecies>(); foreach (var item in PokedexInfo) { IsEmpty = false; var url = item.url.Split('/'); var values = await _apiService.GetAsync <PokedexRequest>(string.Format("{0}/{1}", url[url.Length - 3], url[url.Length - 2])); if (values != null) { pokemons.AddRange(values.pokemon_entries.Select(x => x.pokemon_species)); } } IsCreate = (bool)parameters["IsCreate"]; if (IsCreate) { Title = "Create your group"; } else { Title = "Modify"; GruposRegion = (GruposRegion)parameters["GruposRegion"]; GroupName = GruposRegion.GrupoName; GroupType = GruposRegion.GrupoTipo; PokedexDescription = GruposRegion.PokedexDescription; Region = GruposRegion.Region; var pokemonsAdded = (ObservableCollection <GrupoPokemons>)parameters["PokemonsAdded"]; //set selected pokemons added foreach (var item in pokemonsAdded) { var value = pokemons.Where(x => x.name.Contains(item.Pokemon)).FirstOrDefault(); if (value != null) { value.IsSelected = true; } } PokemonsCounter = pokemonsAdded.Count(); } PokemonList = new ObservableCollection <PokemonSpecies>(); //avoid repeated data foreach (var item in pokemons.OrderBy(x => x.name)) { if (!PokemonList.Any(x => x.name.Contains(item.name))) { PokemonList.Add(item); } } UserDialogs.Instance.HideLoading(); } else { IsEmpty = true; } UserDialogs.Instance.HideLoading(); } else { UserDialogs.Instance.HideLoading(); ErrorAlert(); IsEmpty = true; } } UserDialogs.Instance.HideLoading(); }); }
public void Remove(PokedexInfo pokedexInfo) { _context.PokedexInfos.Remove(pokedexInfo); }
public void Update(PokedexInfo pokedexInfo) { _context.PokedexInfos.Update(pokedexInfo); }
public async Task AddAsync(PokedexInfo pokedexInfo) { await _context.PokedexInfos.AddAsync(pokedexInfo); }