public async Task <IActionResult> Edit(int id, [Bind("MemberId,FirstName,LastName,Email,Phone,Password,DateOfBirth,Address,PostalCode,Province,City,Country")] Members members) { if (HttpContext.Session.GetString("memberId") != null) { if (id != members.MemberId) { return(NotFound()); } if (ModelState.IsValid) { //keep password the same var member = _context.Members.Where(a => a.MemberId == id).AsNoTracking().FirstOrDefault(); members.Password = member.Password; var oldEmail = member.Email; var emailValid = UniqueEmail(members.Email, oldEmail); var postalValid = ValidatePostal(members.PostalCode); if (emailValid && postalValid) { try { _context.Update(members); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MembersExists(members.MemberId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Details))); } else { if (!emailValid) { ViewBag.errorEmail = "An account with this email already exists"; } if (!postalValid) { ViewBag.errorPostal = "Enter correct Postal Code Format (X1X1X1)"; } } } return(View(members)); } else { ViewBag.error = "An error occured, login again"; return(View("Login")); } }
public async Task <IActionResult> Edit(int id, [Bind("AppointmentId,MemberId,ServiceId,AppointmentDate,AppointmentTime,Description")] Appointments appointments) { if (HttpContext.Session.GetString("employeeId") != null) { if (id != appointments.AppointmentId) { return(NotFound()); } if (ModelState.IsValid) { if (DateTime.Today < appointments.AppointmentDate) { try { var apt = _context.Appointments.Where(a => a.AppointmentId == id).AsNoTracking().FirstOrDefault(); var memberId = apt.MemberId; appointments.MemberId = memberId; appointments.Approved = true; _context.Update(appointments); await _context.SaveChangesAsync(); //EMAIL CUSTOMER OF UPDATED APPOINTMENT! var member = _context.Members.Where(a => a.MemberId == memberId).FirstOrDefault(); var email = member.Email; var fname = member.FirstName; var lname = member.LastName; SendEmail("Changed", email, fname + " " + lname, appointments.AppointmentDate, appointments.AppointmentTime); } catch (DbUpdateConcurrencyException) { if (!AppointmentsExists(appointments.AppointmentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } else { ViewBag.dateError = "Choose any date after today"; } } ViewData["MemberId"] = new SelectList(_context.Members, "MemberId", "fullName", appointments.MemberId); ViewData["ServiceId"] = new SelectList(_context.Services, "ServiceId", "Name", appointments.ServiceId); //ViewData["VehicleId"] = new SelectList(_context.Vehicles.Where(a => a.MemberId == int.Parse(memberId)), "VehicleId", "fullVehicleName", appointments.VehicleId); return(View(appointments)); } else { return(RedirectToAction("Index", "Home")); } }
public async Task <IActionResult> Edit(int id, [Bind("EmployeeId,Email,Password,FirstName,LastName")] Employees employees) { if (HttpContext.Session.GetString("userType") == "admin") { if (id != employees.EmployeeId) { return(NotFound()); } if (ModelState.IsValid) { var employee = _context.Employees.Where(a => a.EmployeeId == id).AsNoTracking().FirstOrDefault(); employees.Password = employee.Password; var oldEmail = employee.Email; var emailValid = UniqueEmail(employees.Email, oldEmail); if (emailValid) { try { _context.Update(employees); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeesExists(employees.EmployeeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } else { if (!emailValid) { ViewBag.errorEmail = "An account with this email already exists"; } } } return(View(employees)); } else if (HttpContext.Session.GetString("userType") == "employee") { return(View("EmployeeHomePage")); } else { return(RedirectToAction("Login", "Members")); } }
public async Task <IActionResult> Edit(int id, [Bind("OrderStatusesId,OrderId,StatusId,EmployeeId,EstimatedFinishDate,StartDate,FinishDate")] OrderStatuses orderStatuses) { if (id != orderStatuses.OrderStatusesId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(orderStatuses); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderStatusesExists(orderStatuses.OrderStatusesId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EmployeeId"] = new SelectList(_context.Employees, "EmployeeId", "EmployeeId", orderStatuses.EmployeeId); ViewData["OrderId"] = new SelectList(_context.Orders, "OrderId", "OrderId", orderStatuses.OrderId); ViewData["StatusId"] = new SelectList(_context.Statuses, "StatusId", "StatusId", orderStatuses.StatusId); return(View(orderStatuses)); }
public async Task <IActionResult> Edit(int id, [Bind("VehicleId,Year,Make,Model,LicensePlate,MemberId")] Vehicles vehicles) { if (HttpContext.Session.GetString("memberId") != null) { if (id != vehicles.VehicleId) { return(NotFound()); } if (ModelState.IsValid) { try { var memberId = HttpContext.Session.GetString("memberId"); vehicles.MemberId = int.Parse(memberId); _context.Update(vehicles); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VehiclesExists(vehicles.VehicleId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(vehicles)); } else { ViewBag.error = "An error occured, login again"; return(RedirectToAction("Login", "Members")); } }
public async Task <IActionResult> Edit(int id, [Bind("OrderId,AppointmentId,OrderDate,OrderTotal,OrderDescription,Completed")] Orders orders) { if (HttpContext.Session.GetString("employeeId") != null) { if (id != orders.OrderId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(orders); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrdersExists(orders.OrderId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AppointmentId"] = new SelectList(_context.Appointments, "AppointmentId", "ApptInfo", orders.AppointmentId); return(View(orders)); } else if (HttpContext.Session.GetString("memberId") != null) { return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Login", "Members")); } }
public async Task <IActionResult> Edit(int id, [Bind("ServiceId,Name,Description,TimeToComplete,Cost")] Services services) { if (HttpContext.Session.GetString("employeeId") != null) { if (id != services.ServiceId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(services); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ServicesExists(services.ServiceId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(services)); } else { return(RedirectToAction("Login", "Members")); } }