Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,StreetAdr,ZipCode")] Publisher publisher)
        {
            if (id != publisher.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(publisher);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PublisherExists(publisher.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(publisher));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,TitleName,PublicationYear")] Title title)
        {
            if (id != title.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(title);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TitleExists(title.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(title));
        }
Пример #3
0
        public async Task <IActionResult> Edit(Address_ViewModel vm)
        {
            if (ModelState.IsValid)
            {
                int     id   = vm.ID;
                Address item = await _context.Address.SingleOrDefaultAsync(m => m.ID == id);

                _mapper.Map(vm, item);
                _context.Update(item);

                int updated = 0;


                try
                {
                    updated = await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }
                if (updated > 0)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Update failed.");
                }
            }
            return(View("EditVM", vm));
        }
Пример #4
0
        public async Task <IActionResult> Edit(Customer_VM vm)
        {
            if (ModelState.IsValid)
            {
                int      id   = vm.ID;
                Customer item = await _context.Customer.SingleOrDefaultAsync(m => m.ID == id);

                _mapper.Map(vm, item);
                _context.Update(item);
                int updated = await _context.SaveChangesAsync();

                if (updated > 0)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Update failed.");
                }
            }
            return(View(vm));
        }