// GET: Technicians/Edit/5 public async Task <IActionResult> Edit(int?id, TechnicianCreateViewModel model) { if (id == null) { return(NotFound()); } var tech = await _context.Technician .Include(t => t.Staff) .ThenInclude(s => s.Person) .Include(t => t.Staff) .ThenInclude(s => s.Contact) .FirstOrDefaultAsync(m => m.TechnicianId == id); model.FirstName = tech.Staff.Person.FirstName; model.LastName = tech.Staff.Person.LastName; model.Dob = tech.Staff.Person.Dob; model.Address = tech.Staff.Person.Address; model.Email = tech.Staff.Contact.Email; model.Phone = tech.Staff.Contact.Phone; model.Hours = tech.Staff.Hours; return(View(model)); }
public async Task <IActionResult> Create(TechnicianCreateViewModel model) { //Person Person person = new Person(); person.FirstName = model.FirstName; person.LastName = model.LastName; person.Dob = model.Dob; person.Address = model.Address; _context.Person.Add(person); _context.SaveChanges(); int latestPerson = person.PersonId; //Contact Contact contact = new Contact(); contact.Email = model.Email; contact.Phone = model.Phone; _context.Contact.Add(contact); _context.SaveChanges(); int latestContact = contact.ContactId; //Staff Staff staff = new Staff(); staff.PersonId = latestPerson; staff.ContactId = latestContact; staff.StartDate = model.StartDate; //Change to null staff.LeftDate = new DateTime(04 / 07 / 2020); staff.Hours = model.Hours; _context.Staff.Add(staff); _context.SaveChanges(); int latestStaff = staff.StaffId; //Tutor Technician technician = new Technician(); technician.StaffId = latestStaff; _context.Technician.Add(technician); _context.SaveChanges(); return(RedirectToAction("Details", new { id = technician.TechnicianId })); }
public async Task <IActionResult> Edit(int id, TechnicianCreateViewModel model) { var tech = await _context.Technician .Include(t => t.Staff) .ThenInclude(s => s.Person) .Include(t => t.Staff) .ThenInclude(s => s.Contact) .FirstOrDefaultAsync(m => m.TechnicianId == id); tech.Staff.Person.FirstName = model.FirstName; tech.Staff.Person.LastName = model.LastName; tech.Staff.Person.Dob = model.Dob; tech.Staff.Person.Address = model.Address; tech.Staff.Contact.Email = model.Email; tech.Staff.Contact.Phone = model.Phone; tech.Staff.Hours = model.Hours; _context.Update(tech); _context.SaveChanges(); return(RedirectToAction("Details", new { id = tech.TechnicianId })); }