public async Task <IActionResult> Edit(Int32?placementId, PlacementCreateEditViewModel model) { if (placementId == null) { return(NotFound()); } var placement = await _context.Placements.SingleOrDefaultAsync(m => m.Id == placementId); if (placement == null) { return(NotFound()); } if (ModelState.IsValid) { placement.Bed = model.Bed; placement.PatientId = model.PatientId; placement.WardId = model.WardId; await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { hospitalId = placement.HospitalId })); } return(View(placement)); }
public async Task <IActionResult> Create(Int32?hospitalId, PlacementCreateEditViewModel model) { if (hospitalId == null) { return(this.NotFound()); } var hospital = await this._context.Hospitals .SingleOrDefaultAsync(x => x.Id == hospitalId); if (hospital == null) { return(this.NotFound()); } if (ModelState.IsValid) { var placement = new Placement { Bed = model.Bed, HospitalId = hospitalId, PatientId = model.PatientId, WardId = model.WardId }; if (_context.Placements.Any(x => x.PatientId == model.PatientId)) { this.ModelState.AddModelError("error", "error mnoga"); this.ViewBag.Hospital = hospital; return(View(model)); } _context.Add(placement); await _context.SaveChangesAsync(); return(RedirectToAction("Index", new { hospitalId = hospitalId })); } this.ViewBag.Hospital = hospital; return(View(model)); }