コード例 #1
0
        public async Task <IActionResult> Edit(Int32?id, PatientCreateEditViewModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var patient = await this._context.Patients.
                          SingleOrDefaultAsync(x => x.Id == id);

            if (patient == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                patient.Name     = model.Name;
                patient.Address  = model.Address;
                patient.Birthday = model.Birthday;
                patient.Gender   = model.Gender;

                await this._context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Create(PatientCreateEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var patient = new Patient {
                    Name     = model.Name,
                    Address  = model.Address,
                    Birthday = model.Birthday,
                    Gender   = model.Gender
                };
                _context.Add(patient);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
コード例 #3
0
        // GET: Patients/Edit/5
        public async Task <IActionResult> Edit(Int32?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var patient = await _context.Patients.SingleOrDefaultAsync(m => m.Id == id);

            if (patient == null)
            {
                return(NotFound());
            }
            var model = new PatientCreateEditViewModel
            {
                Name     = patient.Name,
                Address  = patient.Address,
                Birthday = patient.Birthday,
                Gender   = patient.Gender
            };

            return(View(model));
        }