public async Task <IActionResult> CreateDeclaration1([FromBody] CreateDeclarationViewModel declarationData) { if (_context.User_list.FirstOrDefault(x => x.UserName == declarationData.Declaration.Patient.Phone) != null) { return(StatusCode(200, Json("such user already exists"))); } Employees employee = _context.Employees.Include(i => i.Msp).Single(x => x.EmployeeId == declarationData.Declaration.Employee.EmployeeId); User newUser = new User(); newUser.UserName = declarationData.Declaration.Patient.Phone; newUser.UserGroup = 1; PasswordHandler passwordhandler = new PasswordHandler(declarationData.Password); newUser.Password = passwordhandler.GetHashedPassword(); PatientList newPatient = new PatientList(); newPatient = declarationData.Declaration.Patient; Declarations newDeclaration = new Declarations(); newDeclaration.CreateDate = declarationData.Declaration.CreateDate.Date; newDeclaration.Status = "active"; newDeclaration.Employee = employee; newDeclaration.Msp = employee.Msp; newPatient.Declarations = newDeclaration; newUser.PatientList = newPatient; _context.User_list.Add(newUser); _context.SaveChanges(); return(StatusCode(200, Json("ok"))); }