public async Task <IActionResult> Edit(int?id) { if (id == null) { return(RedirectToAction(nameof(Index))); } var appointment = _context.Appointment.FirstOrDefault(f => f.AppointmentPk == id); if (appointment == null) { return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { try { int userPk = Int32.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value); appointment.Fkclient = userPk; _context.Update(appointment); await _context.SaveChangesAsync(); } catch { TempData["failure"] = $"Unable to Book Appointment."; return(RedirectToAction(nameof(Index))); } TempData["success"] = "Appointment successfully booked."; return(RedirectToAction(nameof(Index))); } return(View(appointment)); }
// GET: Appointments/Edit public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var appointment = await _context.Appointment.FindAsync(id); if (appointment == null) { return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { try { int userPk = Int32.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value); appointment.Fkclient = 1; _context.Update(appointment); await _context.SaveChangesAsync(); } catch { TempData["message"] = $"Unable to Cancel Appointment."; return(RedirectToAction(nameof(Index))); } TempData["message"] = "Appointment Cancelled."; return(RedirectToAction(nameof(Index))); } //var appointment = await _context.Appointment.FindAsync(id); //if (appointment == null) //{ // return NotFound(); //} //ViewData["Fkclient"] = new SelectList(_context.User, "UserPk", "Email", appointment.Fkclient); //ViewData["Fkmassage"] = new SelectList(_context.Massage, "MassagePk", "Description", appointment.Fkmassage); //ViewData["Fkstaff"] = new SelectList(_context.User, "UserPk", "Email", appointment.Fkstaff); return(View(appointment)); }
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")); }
public async Task <IActionResult> Create([Bind("FeelingWell,Surgeries,Medications,Sensitives,FocusAreas,IsComplete, Fkappointment,Fkclient,Fkstaff")] Intake intake) { //if appointment Pk is not valid var appointment = _context.Appointment.FirstOrDefault(f => f.AppointmentPk == intake.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); intake.Fkclient = userPK; intake.Fkstaff = appointment.Fkstaff; try { _context.Add(intake); await _context.SaveChangesAsync(); //update intake survey foreign key value in appointment table var enteredSurvey = await _context.Intake.FirstOrDefaultAsync(surv => surv.Fkappointment == appointment.AppointmentPk); appointment.Fkintake = enteredSurvey.IntakePk; _context.Update(appointment); await _context.SaveChangesAsync(); } catch { TempData["failure"] = $"Your intake form was not added"; return(RedirectToAction("Index", "Appointments")); } //set IsComplete to true intake.IsComplete = true; TempData["success"] = $"Your intake form was sucessfully added"; return(RedirectToAction("Index", "Appointments")); //return View(intake); }
public async Task <IActionResult> Deactivate(int id, [Bind("UserPk, NameFirst, NameLast, Email, Phone, Username, Password, IsAdmin")] User user) { if (id != user.UserPk) { return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { //find count of future appointments scheduled to user int countAppointments = _context.Appointment.Where(appt => appt.Fkstaff == user.UserPk).Where(appt => appt.Date > DateTime.Now).Count(); if (countAppointments == 0) { try { user.IsActive = false; _context.Update(user); await _context.SaveChangesAsync(); } catch { TempData["message"] = $"Cannot deactivate {user.NameFull}."; return(RedirectToAction(nameof(Index))); } TempData["message"] = $"{user.NameFull} deactivated."; return(RedirectToAction(nameof(Index))); } else { TempData["message"] = $"{user.NameFull} has scheduled appointments and cannot be deactivated."; return(RedirectToAction(nameof(Index))); } } return(View(user)); }
public async Task <IActionResult> Edit(int id, [Bind("AppointmentPk,Duration,Time,Date,Price,Fkmassage,Fkstaff,Fkclient")] Appointment appointment) { if (id != appointment.AppointmentPk) { return(RedirectToAction(nameof(Index))); } List <SelectListItem> massageList = new SelectList(_context.Massage.OrderBy(massage => massage.Name), "MassagePk", "Name", appointment.Fkmassage).ToList(); List <SelectListItem> clientList = new SelectList(_context.User.Where(staff => staff.IsAdmin != true).OrderBy(client => client.NameLast), "UserPk", "NameFull", appointment.Fkclient).ToList(); List <SelectListItem> staffList = new SelectList(_context.User.Where(staff => staff.IsActive == true).Where(staff => staff.IsAdmin == true).OrderBy(staff => staff.NameLast), "UserPk", "NameFull", appointment.Fkstaff).ToList(); ViewData["Fkmassage"] = massageList; ViewData["Fkclient"] = clientList; ViewData["Fkstaff"] = staffList; DateTime apptDate = appointment.Date; if (ModelState.IsValid) { if (apptDate >= DateTime.Today) { try { _context.Update(appointment); await _context.SaveChangesAsync(); } catch { TempData["message"] = $"Unable to Modify Appointment."; return(RedirectToAction(nameof(Index))); } TempData["message"] = "Appointment successfully updated."; return(RedirectToAction(nameof(Index))); } else { TempData["message"] = $"Cannot reschedule appointment for a past date."; return(View(appointment)); } } return(View(appointment)); }
public async Task <IActionResult> Edit(int id, [Bind("UserPk, NameFirst, NameLast, Email, Phone, Username, Password")] User user) { if (id != user.UserPk) { return(RedirectToAction(nameof(Index))); } //finds the id of user logged in from their claim int?userID = Convert.ToInt32(HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Sid).Value); var aUser = await _context.User.FirstOrDefaultAsync(u => u.UserPk == userID); if (aUser is null || aUser.UserPk != id) { return(RedirectToAction(nameof(Index))); } if (ModelState.IsValid) { try { aUser.NameFirst = user.NameFirst; aUser.NameLast = user.NameLast; aUser.Phone = user.Phone; aUser.Email = user.Email; aUser.Password = user.Password; _context.Update(aUser); await _context.SaveChangesAsync(); } catch { TempData["message"] = $"Unable to Update Account Info."; return(RedirectToAction(nameof(Index))); } TempData["message"] = "Account Info succesfully updated."; return(RedirectToAction(nameof(Index))); } return(View(user)); }