public async Task <IActionResult> Create([Bind("Id,ApplicationUserId,JobId,FirstName,LastName,MiddleName,EmployeeId,Photograph,Status,DOB,Nationality,Gender,MaritalStatus,Address,MobileNo,WorkTelephone,Email,AccountNo,AccountType,SortCode,contractType,JoinDate,DateCreated,DateUpdated,DateModified,IsDeleted")] Models.HRM.Employee employee) { var userId = Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); Organisation org; var otheruser = _context.OtherUsers.Where(x => x.UserId == userId).FirstOrDefault(); if (otheruser == null) { org = _context.Organisation.Where(m => m.ApplicationUserId == userId).FirstOrDefault(); } else { org = _context.Organisation.Where(m => m.ApplicationUserId == otheruser.HostId).FirstOrDefault(); } if (ModelState.IsValid) { employee.Id = Guid.NewGuid(); employee.OrganisationId = org.Id; _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["JobId"] = new SelectList(_context.Job, "Id", "Id", employee.JobId); return(View(employee)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,ApplicationUserId,JobId,FirstName,LastName,MiddleName,EmployeeId,Photograph,Status,DOB,Nationality,Gender,MaritalStatus,Address,MobileNo,WorkTelephone,Email,AccountNo,AccountType,SortCode,contractType,JoinDate,DateCreated,DateUpdated,DateModified,IsDeleted")] Models.HRM.Employee employee) { if (id != employee.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(employee); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EmployeeExists(employee.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["JobId"] = new SelectList(_context.Job, "Id", "Id", employee.JobId); return(View(employee)); }