public async Task <IActionResult> Edit(int id, [Bind("ID,Name")] Brand brand)
      {
          if (id != brand.ID)
          {
              return(NotFound());
          }

          if (ModelState.IsValid)
          {
              try
              {
                  _context.Update(brand);
                  await _context.SaveChangesAsync();
              }
              catch (DbUpdateConcurrencyException)
              {
                  if (!BrandExists(brand.ID))
                  {
                      return(NotFound());
                  }
                  else
                  {
                      throw;
                  }
              }
              return(RedirectToAction(nameof(Index)));
          }
          return(View(brand));
      }
Exemplo n.º 2
0
      public async Task <IActionResult> Edit(int id, [Bind("ID,BrandID,name,price,Colours")] Serie serie)
      {
          if (id != serie.ID)
          {
              return(NotFound());
          }

          if (ModelState.IsValid)
          {
              try
              {
                  _context.Update(serie);
                  await _context.SaveChangesAsync();
              }
              catch (DbUpdateConcurrencyException)
              {
                  if (!SerieExists(serie.ID))
                  {
                      return(NotFound());
                  }
                  else
                  {
                      throw;
                  }
              }
              return(RedirectToAction(nameof(Index)));
          }
          ViewData["BrandID"] = new SelectList(_context.Set <Brand>(), "ID", "ID", serie.BrandID);
          return(View(serie));
      }
Exemplo n.º 3
0
      public async Task <IActionResult> Edit(int id, [Bind("ID,Name,price")] Accessorie accessorie)
      {
          if (id != accessorie.ID)
          {
              return(NotFound());
          }

          if (ModelState.IsValid)
          {
              try
              {
                  _context.Update(accessorie);
                  await _context.SaveChangesAsync();
              }
              catch (DbUpdateConcurrencyException)
              {
                  if (!AccessorieExists(accessorie.ID))
                  {
                      return(NotFound());
                  }
                  else
                  {
                      throw;
                  }
              }
              return(RedirectToAction(nameof(Index)));
          }
          return(View(accessorie));
      }
Exemplo n.º 4
0
        public async Task <ActionResult <Car> > Upsert(Guid id, [Bind("Make,Price")] CarBase carBase)
        {
            Car car = new Car
            {
                Make  = carBase.Make,
                Price = carBase.Price
            };

            if (!CarExists(id))
            {
                car.ID = id;
                _context.Add(car);
                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(GetById), new { id = car.ID }, car));
            }

            Car dbCar = await _context.Cars.FindAsync(id);

            dbCar.Price = car.Price;
            dbCar.Make  = car.Make;

            _context.Update(dbCar);
            await _context.SaveChangesAsync();

            return(Ok(dbCar));
        }