public async Task <IActionResult> Edit(int id, [Bind("SurveyPk,RatingProfessional,RatingAddressedNeeds,RatingMassageQuality,TotalScore,Comments,IsComplete,Fkappointment,Fkstaff,Fkclient")] Outtake outtake) { if (id != outtake.SurveyPk) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(outtake); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OuttakeExists(outtake.SurveyPk)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["Fkappointment"] = new SelectList(_context.Appointment, "AppointmentPk", "Duration", outtake.Fkappointment); ViewData["Fkclient"] = new SelectList(_context.User, "UserPk", "Email", outtake.Fkclient); ViewData["Fkstaff"] = new SelectList(_context.User, "UserPk", "Email", outtake.Fkstaff); return(View(outtake)); }
public IActionResult Create(int?id) { //if id is null if (id == null) { return(RedirectToAction("Index", "Appointments")); } //if appointmentpk is not valid var appointment = _context.Appointment.FirstOrDefault(f => f.AppointmentPk == id); if (appointment == null) { return(RedirectToAction("Index", "Appointments")); } // retrieve user's PK from the Claims collection int userPK = Int32.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value); // Check if user already has an intake for the appointment var aSurvey = _context.Intake .FirstOrDefault(i => i.Fkappointment == id && i.Fkclient == userPK); // If user has an intake, redirect to My Appointments if (aSurvey != null) { return(RedirectToAction("Index", "Appointments")); } Outtake survey = new Outtake { Fkappointment = appointment.AppointmentPk }; //TODO need to update appointment record w/ value for intakeSurvey return(View(survey)); }
public async Task <IActionResult> Create([Bind("SurveyPk,RatingProfessional,RatingAddressedNeeds,RatingMassageQuality,TotalScore,Comments,IsComplete,Fkappointment,Fkstaff,Fkclient")] Outtake survey) { //if appointment Pk is not valid var appointment = _context.Appointment.FirstOrDefault(f => f.AppointmentPk == survey.Fkappointment); if (appointment == null) { return(RedirectToAction("Index", "Appointments")); } // retrieve user's PK from the Claims collection int userPK = Int32.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value); survey.Fkclient = userPK; survey.Fkstaff = appointment.Fkstaff; try { _context.Add(survey); await _context.SaveChangesAsync(); //update outake survey foreign key value in appointment table var enteredSurvey = await _context.Outtake.FirstOrDefaultAsync(surv => surv.Fkappointment == appointment.AppointmentPk); appointment.Fkouttake = enteredSurvey.SurveyPk; _context.Update(appointment); await _context.SaveChangesAsync(); } catch { TempData["failure"] = $"Your feedback was not added"; return(RedirectToAction("Index", "Appointments")); } //set IsComplete to true survey.IsComplete = true; TempData["success"] = $"Thank you for submitting your feedback!"; return(RedirectToAction("Index", "Appointments")); }