コード例 #1
0
        public async Task <IActionResult> Edit(int id, EditCorporateViewModel viewModel)
        {
            if (id != viewModel.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var corporate = new Corporate(
                    viewModel.Id,
                    viewModel.Name,
                    viewModel.ImageUrl);
                try
                {
                    context.Update(corporate);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CorporateExists(corporate.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(viewModel));
        }
コード例 #2
0
        // GET: Admin/Corporates/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var corporate = await context.Corporates.FindAsync(id);

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

            var viewModel = new EditCorporateViewModel
            {
                Id       = corporate.Id,
                Name     = corporate.Name,
                ImageUrl = corporate.ImageUrl
            };

            return(View(viewModel));
        }