public async Task <IActionResult> PostDependent([FromBody] PostDependents postDependents) { if (postDependents == null) { return(Json(new { msg = "No Data" } )); } var orgId = getOrg(); var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var employeeDetails = _context.EmployeeDetails.Where(x => x.UserId == Guid.Parse(userId)).FirstOrDefault(); try { Dependant dependant = new Dependant() { Id = Guid.NewGuid(), Name = postDependents.Name, Relationship = postDependents.Relationship, Address = postDependents.Address, OrganisationId = orgId, EmployeeDetailId = employeeDetails.Id, }; _context.Add(dependant); _context.SaveChanges(); return(Json(new { msg = "Success" } )); } catch (Exception ee) { } return(Json( new { msg = "Fail" })); }
public async Task <IActionResult> editDependents([FromBody] PostDependents postDependents) { if (postDependents == null) { return(Json(new { msg = "No Data" } )); } var orgId = getOrg(); var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var employeeDetails = await _context.EmployeeDetails.Where(x => x.UserId == Guid.Parse(userId)).FirstOrDefaultAsync(); try { var EmployDependt = _context.Dependants.Where(x => x.Id == Guid.Parse(postDependents.AId)).FirstOrDefault(); EmployDependt.Name = postDependents.Name; EmployDependt.Relationship = postDependents.Relationship; EmployDependt.Address = postDependents.Address; EmployDependt.OrganisationId = orgId; EmployDependt.EmployeeDetailId = employeeDetails.Id; _context.Update(EmployDependt); _context.SaveChanges(); return(Json(new { msg = "Success" } )); } catch (Exception ee) { } return(Json( new { msg = "Fail" })); }