public async Task <IActionResult> PutMedication(string id, Medication medication) { if (id != medication.Name) { return(BadRequest()); } _context.Entry(medication).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MedicationExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutPatient([FromRoute] int id, [FromBody] Patient patient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != patient.PatientId) { return(BadRequest()); } _context.Entry(patient).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PatientExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <Assessment> > EndPrediction([FromRoute] int id) { selectedSymptoms = HttpContext.Session.GetObjectFromJson <List <int> >("selectedSymptoms"); var patient = await _context.Patients.FindAsync(id); if (patient == null) { return(NotFound("Patient not founded")); } string info = ""; foreach (var item in selectedSymptoms) { info += item.ToString() + "/"; } var firstSyptom = await _context.Symptoms.FindAsync(selectedSymptoms.ElementAt(0)); if (firstSyptom == null) { return(NotFound("First symptom not founder")); } Assessment assessment = new Assessment(); assessment.Name = firstSyptom.Name; assessment.Information = Encrypt.EncryptString(info); assessment.Patient = patient; await _context.Assessments.AddAsync(assessment); await _context.SaveChangesAsync(); return(Ok(assessment)); }
public async Task <IActionResult> PutReport(string id, Report report) { if (id != report.ReportId) { return(BadRequest()); } _context.Entry(report).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ReportExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutClinician(string id, Clinician clinician) { if (id != clinician.ClinicianId) { return(BadRequest()); } _context.Entry(clinician).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ClinicianExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> SendFeedback(Mail mail) { if (ModelState.IsValid) { var patient = await _context.Patients .Where(p => p.Email == mail.Reciever) .FirstOrDefaultAsync(); if (patient == null) { return(NotFound("This Email Not founded")); } Feedback feedback = new Feedback() { Title = mail.Subject, Content = mail.Content, Patient = patient }; await _context.Feedbacks.AddAsync(feedback); await _context.SaveChangesAsync(); _ = SendMailAsync(mail); return(Ok(mail)); } return(BadRequest()); }
public async Task <IActionResult> PutWatchList(int id, WatchList watchList) { if (id != watchList.WatchListId) { return(BadRequest()); } _context.Entry(watchList).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WatchListExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostDisease(DiseaseData disease) { if (!ModelState.IsValid) { return(BadRequest()); } var check = await _context.Diseases .Where(d => d.Name == disease.Disease.Name) .FirstOrDefaultAsync(); var type = await _context.Specialties.FindAsync(disease.Type); if (check != null || type == null) { return(BadRequest()); } disease.Disease.Specialty = type; await _context.Diseases.AddAsync(disease.Disease); foreach (var id in disease.Symptoms) { var symptomDiseases = new SymptomDisease { DiseaseID = disease.Disease.ID, SymptomID = id }; await _context.SymptomDiseases.AddAsync(symptomDiseases); } await _context.SaveChangesAsync(); return(Ok(disease)); }
public async Task <ActionResult <List <AilmentViewModel> > > RegisterNewAilment(Ailment ailment) { _context.Ailments.Add(ailment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAilment", new { id = ailment.Id }, ailment)); }
public async Task <ActionResult <List <MedicationViewModel> > > RegisterNewMedication(Medication medication) { _context.Medications.Add(medication); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMedication", new { id = medication.Id }, medication)); }
public async Task <IActionResult> PostSymptom(Symptom symptom) { if (!ModelState.IsValid) { return(BadRequest()); } var check = _context.Symptoms .Where(d => d.Name == symptom.Name) .FirstOrDefault(); if (check != null) { return(BadRequest()); } await _context.Symptoms.AddAsync(symptom); await _context.SaveChangesAsync(); return(Ok(symptom)); }
public async Task <IActionResult> PostSpecialty(Specialty specialty) { if (!ModelState.IsValid) { return(BadRequest()); } var check = await _context.Specialties .Where(d => d.Name == specialty.Name) .FirstOrDefaultAsync(); if (check != null) { return(BadRequest()); } await _context.Specialties.AddAsync(specialty); await _context.SaveChangesAsync(); return(Ok(specialty)); }
public async Task <IActionResult> PostAdmin(Admin admin) { if (!ModelState.IsValid) { return(BadRequest()); } var hasedPassword = Encrypt.EncryptString(admin.Password); var user = await _context.Admins .Where(u => u.Password == hasedPassword || u.Email == admin.Email) .FirstOrDefaultAsync(); if (user != null) { return(BadRequest()); } admin.Password = hasedPassword; await _context.Admins.AddAsync(admin); await _context.SaveChangesAsync(); return(Ok(admin)); }
public async Task <IActionResult> PostPatient(Patient patient) { if (!ModelState.IsValid) { return(BadRequest()); } var hasedPassword = Encrypt.EncryptString(patient.Password); var user = await _context.Patients .Where(u => u.Password == hasedPassword || u.Email == patient.Email) .FirstOrDefaultAsync(); if (user != null) { return(BadRequest()); } patient.Password = hasedPassword; await _context.Patients.AddAsync(patient); await _context.SaveChangesAsync(); return(Ok(patient)); }
public async Task <User> Register(User user, string password) { byte[] passwordHash, passwordSalt; CreatePasswordHash(password, out passwordHash, out passwordSalt); user.PasswordSalt = passwordSalt; user.PasswordHash = passwordHash; await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); return(user); }
public async Task <ActionResult <DoctorRating> > Rate([FromRoute] int id, [FromRoute] int patientId, [FromQuery] int value) { DoctorRating doctorRating = await _context.DoctorRatings .Where(r => r.DoctorID == id && r.PatientID == patientId) .SingleOrDefaultAsync(); if (doctorRating == null) { doctorRating = new DoctorRating(); doctorRating.DoctorID = id; doctorRating.PatientID = patientId; doctorRating.Value = value; await _context.DoctorRatings.AddAsync(doctorRating); } else { doctorRating.Value = value; _context.DoctorRatings.Update(doctorRating); } await _context.SaveChangesAsync(); return(Ok(doctorRating)); }
public virtual async Task <int> SaveChangeAsync() { int result = 0; try { result = await _context.SaveChangesAsync(); } catch (Exception ex) { //TODO: write log here } return(result); }
public async Task <int> CreateAsync(Patient patientModel) { await _db.Patients.AddAsync(patientModel); return(await _db.SaveChangesAsync()); }