ASP.NET Core Web API - 11. UPDATE & PUT Methods

Поділитися
Вставка
  • Опубліковано 15 жов 2024

КОМЕНТАРІ • 30

  • @jeffwoltjen3887
    @jeffwoltjen3887 Рік тому +6

    "There are a lot of people in the UK who watch my videos so let's change the country to Europe! Not everything has to be about America." As a fellow American, this is a brilliant piece of trolling. Well done.

  • @JoseAlter
    @JoseAlter Рік тому +3

    First of all, thank you very much your videos have helped me a lot and secondly I am commenting this before finishing the video, but I want to ask, how to do a dynamic update? if I want to update a single object of the model, some or all.

  • @at-tf9cc
    @at-tf9cc 2 роки тому +18

    For UpdatePokemon You get the ownerId and categoryId in the controller
    and give them to the repository but don't do anything with them,
    so owner and category of the pokemon are not updated.

    • @TeddySmithDev
      @TeddySmithDev  2 роки тому

      Can you comment exact line in code? I will go back update the repo + put update in comment. Thanks for commenting.

    • @brandonramirez2777
      @brandonramirez2777 2 роки тому +4

      ​@@TeddySmithDev In Folder 'Repository' > PokemonRepository > Method 'UpdatePokemon' in line 91 of your repo.
      I had the exact same question, thanks

    • @of_youtube
      @of_youtube 2 роки тому +3

      Yes, he fucked up a little. But I guess we dont have to change them updating Pokemon. Because the Pokemon and the Owner are linked by Id. If we change some properties of the Pokemon nothing happens with the Owner or the Category

    • @antenehshimelis3369
      @antenehshimelis3369 Рік тому +1

      @@brandonramirez2777 yes i have seen the same thing too

    • @LamNguyen-jp5vh
      @LamNguyen-jp5vh Рік тому +1

      Yeah, I also have the same question too, I think we dont have to use those.

  • @roemer024
    @roemer024 Рік тому +4

    17:28 TOTALLY WRONG WTF
    Misty resides in Celadon City, Saffron City is Sabrina's gym *flips table* 1/10 bad API.
    jk I liked every video so far huheuhe.

  • @jp_blue9222
    @jp_blue9222 2 роки тому

    Thanks for this... Will be adding to my playlist to learn 😊

  • @SerielThriller
    @SerielThriller Рік тому +4

    The error was because the JSON you sent to it was missing the " before the P in Pikatu.

  • @racmanov
    @racmanov 9 місяців тому

    I love how simple this tutorials are. They are basic so it allows us to do a bit more on our own. I have made another dtos without ids. Which is great in post but in put i dont need validation check for update since i just update the string and id is applied to mapping. This project is awesome playground.
    One question tough. I have created and abstract class since update, post and save can be done in generic way in repositories (and i dont have to repeat myself :). I mean everything works but is this good practice or bad?

    • @TeddySmithDev
      @TeddySmithDev  9 місяців тому +1

      People say generic in repos as bad but I’ve seen them work great. Plus give you something to talk about in interview 👍

    • @racmanov
      @racmanov 9 місяців тому

      @@TeddySmithDev ty for fast response. I didnt do whole repo. Juat stuff that gets repeated. Like that 2 line saving, or thins that are pretty much the same everywhere (update and create)

    • @TeddySmithDev
      @TeddySmithDev  9 місяців тому

      yeah you got it. Thanks for the comment!

  • @quocthong328
    @quocthong328 Рік тому +1

    hello, thank you for your teaching but I'm little bit confusing when we use tag ProducesResponseType 404, 400 and 204 but in the code we return return StatusCode(500, ModelState);.

  • @cryptoeric24
    @cryptoeric24 Рік тому

    You said you would never say pica pica in real life but you did in real life video!! LOL!! Also, the last error was you were missing the first quotation mark " on the title in swagger

  • @corykennedy9319
    @corykennedy9319 Рік тому

    The error at the end was because your JSON payload was malformed. You deleted the first " on property title by accident :)

  • @henrik3098
    @henrik3098 Рік тому

    thans bro!!

  • @hmilaam8907
    @hmilaam8907 6 місяців тому

    why u didn't updating the FK in reviewer

  • @joshuaarmando7765
    @joshuaarmando7765 6 місяців тому

    Category and Owner of the Pokemon not updating bro

  • @bijayshrestha7843
    @bijayshrestha7843 Рік тому

    How to update pokemon Owner and pokemon Category?

  • @si1icarus
    @si1icarus 2 роки тому +2

    Thank you for your lovely and educational videos, I have learned a lot just by watching your videos ;).
    One question though, the UpdatePokemon method in the PokemonRepository, you just passed along the ownerId and categoryId but you have not Update the relations between Pokemon, PokemonOwner (join table) and PokemonCategory (join table), another words the owner and category of the pokemon are not updating.
    My solution was to simply find the relations between the data and try to update them, but I did face couple of problems regarding updating the join tables, therefore I tried to delete the related records from join tables and insert new relations.
    Would you please take a look at the following implementation and tell me if there is a better way to update the pokemon records.
    Many thanks.
    public bool UpdatePokemon(int ownerId, int categoryId, Pokemon pokemon)
    {
    var pokemonOwnerEntity = _context.PokemonOwners.
    Where(o => o.PokemonId == pokemon.Id).FirstOrDefault();
    var OwnerEntity = _context.Owners.
    Where(o => o.Id == ownerId).FirstOrDefault();
    var pokemonCategoryEntity = _context.PokemonCategories.
    Where(c => c.PokemonId == pokemon.Id).FirstOrDefault();
    var categoryEntity = _context.Categories.Where(o => o.Id == categoryId).FirstOrDefault();
    if (pokemonOwnerEntity != null && OwnerEntity != null)
    {
    _context.Remove(pokemonOwnerEntity);
    var pokemonOwner = new PokemonOwner()
    {
    Owner = OwnerEntity,
    Pokemon = pokemon,
    };
    _context.Add(pokemonOwner);
    }
    if (pokemonCategoryEntity != null && categoryEntity != null)
    {
    _context.Remove(pokemonCategoryEntity);
    var pokemonCategory = new PokemonCategory()
    {
    Category = categoryEntity,
    Pokemon = pokemon,
    };
    _context.Add(pokemonCategory);
    }
    else
    return false;
    _context.Update(pokemon);
    return Save();
    }

    • @ianwanjala8621
      @ianwanjala8621 Рік тому +1

      I don't think you should remove the PokemonOwner or the PokemonCategory objects, the right thing to do would be to update them. Also, the checks that you are doing i.e whether the owner entity is null or not should be done in the controller