예제 #1
0
        public async Task <IActionResult> Edit(int bID, BrandViewModel model)
        {
            var brand = await _context.Brands.FindAsync(bID);

            if (brand == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    brand.BrandName = model.BrandName;
                    _context.Update(brand);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrandExists(brand.BrandID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(brand));
        }
예제 #2
0
        public async Task <IActionResult> Edit(string id, [Bind("CarID,Description,Model,Color,BrandID,Transmission,Condition,FuelType,GearType,BodyType,EngineSize,NoOfSeats,Price,Mileage,Category,Images,DisplayImage")] CarViewModel car)
        {
            if (id != car.CarID)
            {
                return(NotFound());
            }



            if (ModelState.IsValid)
            {
                try
                {
                    Car Car = new Car
                    {
                        CarID        = car.CarID,
                        Description  = car.Description,
                        Model        = car.Model,
                        Category     = car.Category,
                        BrandID      = car.BrandID,
                        Transmission = car.Transmission,
                        Condition    = car.Condition,
                        FuelType     = car.FuelType,
                        GearType     = car.GearType,
                        BodyType     = car.BodyType,
                        EngineSize   = car.EngineSize,
                        NoOfSeats    = car.NoOfSeats,
                        Mileage      = car.Mileage,
                        Price        = car.Price,
                        DisplayImage = car.DisplayImage,
                        Color        = car.Color
                    };

                    List <string> images = null;
                    if (car.Images != null && car.Images.Count > 0)
                    {
                        images = UploadedFile(car);
                    }

                    if (images != null)
                    {
                        foreach (var image in images)
                        {
                            Image photo = new Image
                            {
                                ImageLocation = image,
                                CarID         = car.CarID
                            };
                            _context.Images.Add(photo);
                        }
                    }



                    _context.Update(Car);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarExists(car.CarID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            } // if model state ends
            ViewData["BrandID"] = new SelectList(_context.Brands, "BrandID", "BrandName", car.BrandID);
            return(View(car));
        }