Exemplo n.º 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));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(Int32?id, WardStaffViewModel model)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var wardStaff = await this._context.WardStaffs
                            .Include(x => x.Ward)
                            .SingleOrDefaultAsync(m => m.StaffId == id);

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

            if (ModelState.IsValid)
            {
                wardStaff.Name     = model.Name;
                wardStaff.Position = model.Position;
                await this._context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { wardId = wardStaff.WardId }));
            }
            this.ViewBag.WardStaff = wardStaff;
            return(this.View(model)); //здесь с wardStaff тоже сработало О_о
        }
Exemplo n.º 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));
        }
Exemplo n.º 4
0
        // GET: WardStaffs/Edit/5
        public async Task <IActionResult> Edit(Int32?id, Int32?wardId)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var wardStaff = await this._context.WardStaffs
                            .Include(x => x.Ward)
                            .SingleOrDefaultAsync(m => m.StaffId == id && m.WardId == wardId);

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

            var model = new WardStaffViewModel
            {
                Name     = wardStaff.Name,
                Position = wardStaff.Position
            };

            this.ViewBag.WardStaff = wardStaff;
            return(this.View(model));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(Int32?id, WardStaffViewModel model)
        {
            if (id == null)
            {
                return(this.NotFound());
            }

            var wardStaff = await this._context.WardStaffs.SingleOrDefaultAsync(m => m.Id == id);

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

            if (this.ModelState.IsValid)
            {
                wardStaff.Name     = model.Name;
                wardStaff.Position = model.Position;
                await this._context.SaveChangesAsync();

                return(this.RedirectToAction("Index", new { wardId = wardStaff.WardId }));
            }

            return(this.View(model));
        }