コード例 #1
0
        public async Task <IActionResult> Edit(Int32?id, DoctorCreateAndEditModel model)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var doctor = await this.context.Doctors
                         .SingleOrDefaultAsync(m => m.Id == id);

            if (doctor == null)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                doctor.Name      = model.Name;
                doctor.Specialty = model.Specialty;

                await this.context.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }

            return(this.View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Create(DoctorCreateAndEditModel model)
        {
            if (this.ModelState.IsValid)
            {
                var doctor = new Doctor
                {
                    Name      = model.Name,
                    Specialty = model.Specialty
                };


                this.context.Doctors.Add(doctor);
                await this.context.SaveChangesAsync();

                return(this.RedirectToAction("Index"));
            }

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

            var doctor = await this.context.Doctors
                         .SingleOrDefaultAsync(m => m.Id == id);

            if (doctor == null)
            {
                return(this.NotFound());
            }

            var model = new DoctorCreateAndEditModel
            {
                Name      = doctor.Name,
                Specialty = doctor.Specialty
            };

            return(this.View(model));
        }