Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, AddBikeMakerViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var path = model.ImageUrl;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile, "Makers");

                    //TODO: investigar borrar imagen anterior
                    _imageHelper.DeleteImageAsync(model.ImageUrl);
                }

                var bikeMakerEntity = _converterHelper.ToBikeMakerEntity(model, path);

                try
                {
                    _context.BikeMakers.Update(bikeMakerEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException err)
                {
                    ModelState.AddModelError(string.Empty, err.Message);
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, AddSpareBrandViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var path = model.ImageUrl;

                if (model.ImageFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile, "SpareBrands");

                    //TODO: investigar borrar imagen anterior
                    _imageHelper.DeleteImageAsync(model.ImageUrl);
                }

                var sparebrand = _converterHelper.ToSpareBrandEntity(model, path);


                try
                {
                    _context.SpareBrands.Update(sparebrand);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SpareBrandEntityExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }