Пример #1
0
        public async Task <IActionResult> Create(Int32?wardId, WardStaffViewModel model)
        {
            if (wardId == null)
            {
                return(this.NotFound());
            }

            var ward = await this._context.Wards
                       .Include(w => w.WardStaffs)
                       .SingleOrDefaultAsync(x => x.Id == wardId);

            if (ward == null)
            {
                return(this.NotFound());
            }
            if (this.ModelState.IsValid)
            {
                var wardStaff = new WardStaff
                {
                    WardId   = ward.Id,
                    Name     = model.Name,
                    Position = model.Position,
                    StaffId  = ward.WardStaffs.Any() ? ward.WardStaffs.Max(x => x.StaffId) + 1 : 1
                };
                this._context.Add(wardStaff);
                await this._context.SaveChangesAsync();

                return(this.RedirectToAction(nameof(Index), new { wardId = ward.Id }));
            }
            this.ViewBag.Ward = ward;
            return(this.View(model));
        }
Пример #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Position,WardId")] WardStaff wardStaff)
        {
            if (id != wardStaff.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    context.Update(wardStaff);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!WardStaffExists(wardStaff.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["WardId"] = new SelectList(context.Wards, "Id", "Name", wardStaff.WardId);
            return(View(wardStaff));
        }
Пример #3
0
        public async Task <IActionResult> Create(Int32?wardId, WardStaffViewModel model)
        {
            if (wardId == null)
            {
                return(this.NotFound());
            }

            var ward = await this._context.Wards
                       .SingleOrDefaultAsync(x => x.Id == wardId);

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

            if (this.ModelState.IsValid)
            {
                var wardStaff = new WardStaff
                {
                    WardId   = ward.Id,
                    Name     = model.Name,
                    Position = model.Position
                };

                this._context.Add(wardStaff);
                await this._context.SaveChangesAsync();

                return(this.RedirectToAction("Index", new { wardId = ward.Id }));
            }

            this.ViewBag.Hospital = ward;
            return(this.View(model));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Position,WardId")] WardStaff wardStaff)
        {
            if (ModelState.IsValid)
            {
                context.Add(wardStaff);
                await context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["WardId"] = new SelectList(context.Wards, "Id", "Name", wardStaff.WardId);
            return(View(wardStaff));
        }