public async Task <IActionResult> Create([Bind("NameFirst, NameLast, Email, Phone, Username, Password")] User user) /*UserPk,IsAdmin,IsActive*/ { if (ModelState.IsValid) { var aUser = await _context.User.FirstOrDefaultAsync(u => u.Username == user.Username); if (aUser is null) { user.IsAdmin = true; user.IsActive = true; _context.Add(user); await _context.SaveChangesAsync();//commits data TempData["success"] = $"New staff member {user.NameFull} successfully added."; return(RedirectToAction(nameof(Index))); } else { ViewData["message"] = $"Username {user.Username} already taken"; } } return(View(user)); }
public async Task <IActionResult> Create([Bind("AppointmentPk,Duration,Time,Date,Price,Fkmassage,Fkstaff,Fkclient")] Appointment appointment) { DateTime apptDate = appointment.Date;//find date of entered item 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; if (ModelState.IsValid) { if (apptDate >= DateTime.Today)//can only add appointments for a date in future { _context.Add(appointment); await _context.SaveChangesAsync(); TempData["message"] = $"Appointment added"; return(RedirectToAction(nameof(Index))); } else { TempData["message"] = $"Cannot create appointment for a past date."; return(View(appointment)); } } return(View(appointment)); }
public async Task <IActionResult> Register([Bind("NameFirst, NameLast, Email, Phone, Username, Password")] User user) { if (ModelState.IsValid) { var aUser = await _context.User.FirstOrDefaultAsync(newUser => newUser.Username == user.Username); if (aUser is null) { user.IsAdmin = false; user.IsActive = false; _context.Add(user); await _context.SaveChangesAsync(); //added TempData["success"] = $"Welcome {user.NameFull}. Please login to book a massage and review your account."; return(RedirectToAction(nameof(Login))); } else { ViewData["message"] = $"Username {user.Username} already taken"; } } return(View(user)); }
public async Task <IActionResult> Create([Bind("AppointmentPk,Duration,Time,Date,Price,Fkmassage,Fkstaff,Fkclient")] Appointment appointment) { if (ModelState.IsValid) { _context.Add(appointment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } 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); }