public bool AddRelation(RelationsModel value, string patientId) { var doctor = Context.Users.FirstOrDefault(u => u.isDoctor == true && u.InvitationCode == value.AuthorizationNumber); if (doctor == null) { return(false); } var patient = Context.Users.First(u => u.Id == patientId); if (Context.Relations.FirstOrDefault(p => p.AuthorizedDoctors == doctor && p.AuthorizedPatients == patient) != null) { // relation exists return(false); } Context.Relations.Add(new Relation() { AuthorizedDoctors = doctor, AuthorizedPatients = patient }); Context.SaveChanges(); return(true); }
public IActionResult Post([FromBody] RelationsModel value) { var success = _userRepository.AddRelation(value, User.Identity.GetUserId()); return(Ok()); }