public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,Address_1,Address_2,City,State,ZipCode,Neighborhood")] Customer customer) { if (ModelState.IsValid) { _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <IActionResult> OnPostAsync(int?id, string[] selectedTreatments) { if (!ModelState.IsValid) { return(Page()); } var employeeToUpdate = await _context.Employee .Include(q => q.User) .Include(t => t.TreatmentAssignments) .ThenInclude(t => t.Treatment) .FirstOrDefaultAsync(q => q.Id == id); if (await TryUpdateModelAsync <Employee>( employeeToUpdate, "Employee", i => i.TreatmentAssignments)) { UpdateEmployeeTreatments(_context, selectedTreatments, employeeToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } UpdateEmployeeTreatments(_context, selectedTreatments, employeeToUpdate); PopulateAssignedTreatmentData(_context, employeeToUpdate); return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (await TryUpdateModelAsync <Enrollment>( Enrollment, "enrollment", // Prefix for form value. s => s.Id, s => s.Active, s => s.Date, s => s.TreatmentAssignmentId, s => s.UserId)) { _context.Enrollment.Add(Enrollment); await _context.SaveChangesAsync(); return(RedirectToPage("./Index", new { message = "Zapisano pomyślnie!" })); } return(Page()); }
public async Task <IActionResult> OnPostAsync(int?enrolId) { if (enrolId == null) { return(NotFound()); } Enrollment = await _context.Enrollment.FindAsync(enrolId); if (Enrollment != null) { _context.Enrollment.Remove(Enrollment); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index", new { message = "Poprawnie odwo³ano wizytê." })); }
public async Task <IActionResult> OnPostAsync(int?employeeId) { if (employeeId == null) { return(NotFound()); } Employee = await _context.Employee.FindAsync(employeeId); if (Employee != null) { _context.Employee.Remove(Employee); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index", new { message = "Poprawnie usunięto pracownika" })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid || !_context.Users.Any( q => q.Email == Employee.User.Email && q.FirstName == Employee.User.FirstName && q.LastName == Employee.User.LastName)) { ModelState.AddModelError(string.Empty, "Nie znaleziono użytkownika."); return(Page()); } var user = _context.Users.FirstOrDefault(p => p.Email == Employee.User.Email); if (_context.Employee.Any(q => q.UserId == user.Id)) { ModelState.AddModelError(string.Empty, "Pracownik już istnieje."); return(Page()); } var emptyEmployee = new Employee(); emptyEmployee.User = _context.Users.FirstOrDefault( q => q.Email == Employee.User.Email && q.FirstName == Employee.User.FirstName && q.LastName == Employee.User.LastName); if (await TryUpdateModelAsync <Employee>( emptyEmployee, "employee", // Prefix for form value. s => s.Id, s => s.UserId)) { _context.Employee.Add(emptyEmployee); await _context.SaveChangesAsync(); await _userManager.AddToRoleAsync(emptyEmployee.User, "Employee"); return(RedirectToPage("./Index")); } return(Page()); }