public async Task <IActionResult> Edit(int id, [Bind("Id,SizeId,ColorId,ModelId")] SizeColorModel sizeColorModel)
        {
            if (id != sizeColorModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(sizeColorModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SizeColorModelExists(sizeColorModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ColorId"] = new SelectList(_context.Colors, "Id", "ColorName", sizeColorModel.ColorId);
            ViewData["ModelId"] = new SelectList(_context.BicycleModels, "Id", "ModelName", sizeColorModel.ModelId);
            ViewData["SizeId"]  = new SelectList(_context.Sizes, "Id", "SizeName", sizeColorModel.SizeId);
            return(View(sizeColorModel));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,ColorName")] Color color)
        {
            if (id != color.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(color);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ColorExists(color.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(color));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,DealerName,WebsiteAddress,Description")] AuthorizedDealer authorizedDealer)
        {
            if (id != authorizedDealer.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(authorizedDealer);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AuthorizedDealerExists(authorizedDealer.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(authorizedDealer));
        }
        public async Task <IActionResult> Edit(int id, BicycleModelViewModel bicycleModel)//[Bind("Id,Price,ModelName,ModelYear,BrandId,GenderId,CategoryId,Description")] BicycleModel bicycleModel)
        {
            if (id != bicycleModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var tempBicycle = await _context.BicycleModels.Where(b => b.Id == bicycleModel.Id).FirstOrDefaultAsync();

                    tempBicycle.BrandId         = bicycleModel.BrandId;
                    tempBicycle.CategoryId      = bicycleModel.CategoryId;
                    tempBicycle.GenderId        = bicycleModel.GenderId;
                    tempBicycle.Description     = bicycleModel.Description;
                    tempBicycle.Id              = bicycleModel.Id;
                    tempBicycle.ModelName       = bicycleModel.ModelName;
                    tempBicycle.ModelYear       = bicycleModel.ModelYear;
                    tempBicycle.Price           = bicycleModel.Price;
                    tempBicycle.SizeColorModels = bicycleModel.SizeColorModels;

                    if (bicycleModel.Image != null)
                    {
                        byte[] imageData = null;
                        using (var binaryReader = new BinaryReader(bicycleModel.ImageFile.OpenReadStream()))
                        {
                            imageData = binaryReader.ReadBytes((int)bicycleModel.Image.Length);
                        }
                        tempBicycle.Image = imageData;
                    }
                    _context.Update(tempBicycle);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BicycleModelExists(bicycleModel.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BrandId"]    = new SelectList(_context.Brands, "Id", "BrandName", bicycleModel.BrandId);
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "CategoryName", bicycleModel.CategoryId);
            ViewData["GenderId"]   = new SelectList(_context.Genders, "Id", "GenderName", bicycleModel.GenderId);
            return(View(bicycleModel));
        }
示例#5
0
        public async Task <IActionResult> Edit(int id, BrandViewModel brand)//[Bind("Id,BrandName,CountryId,DealerId,Description")] Brand brand)
        {
            if (id != brand.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var person = await _context.Brands.Where(b => b.Id == brand.Id).FirstOrDefaultAsync();

                    person.Id            = brand.Id;
                    person.BrandName     = brand.BrandName;
                    person.BicycleModels = brand.BicycleModels;
                    person.Country       = brand.Country;
                    person.CountryId     = brand.CountryId;
                    person.Dealer        = brand.Dealer;
                    person.DealerId      = brand.DealerId;
                    person.Description   = brand.Description;

                    if (brand.Image != null)
                    {
                        byte[] imageData = null;
                        using (var binaryReader = new BinaryReader(brand.Image.OpenReadStream()))
                        {
                            imageData = binaryReader.ReadBytes((int)brand.Image.Length);
                        }
                        person.Image = imageData;
                    }
                    _context.Update(person);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrandExists(brand.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CountryId"] = new SelectList(_context.Countries, "Id", "CountryName", brand.CountryId);
            ViewData["DealerId"]  = new SelectList(_context.AuthorizedDealers, "Id", "DealerName", brand.DealerId);
            return(View(brand));
        }