コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Label,Phone,HcpCenterId")] CenterPhone centerPhone)
        {
            if (id != centerPhone.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(centerPhone);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CenterPhoneExists(centerPhone.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HcpCenterId"] = new SelectList(_context.HcpCenters, "Id", "Name", centerPhone.HcpCenterId);
            return(View(centerPhone));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,Label,Phone,HcpCenterId")] CenterPhone centerPhone)
        {
            if (ModelState.IsValid)
            {
                _context.Add(centerPhone);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HcpCenterId"] = new SelectList(_context.HcpCenters, "Id", "Name", centerPhone.HcpCenterId);
            return(View(centerPhone));
        }