public async Task <ActionResult> AddConsultation(ConsultationDto consultationDto) { if (await _consultationRepository.AddConsultationAsync(consultationDto)) { return(Ok()); } return(BadRequest("Upps..ceva nu a mers!")); }
public async Task <IActionResult> GetConsultations([FromQuery] ConsultationDto request) { var consultations = await consultationLogic.GetConsultations(request); if (!consultations.Any()) { return(NotFound()); } return(Ok(consultations)); }
public Task <List <GetConsultationResponse> > GetConsultations(ConsultationDto request) { var clinicName = request.ClinicName; var patientName = request.PatientName; return(context .Consultation .AsNoTracking() .ConditionalWhere(!string.IsNullOrEmpty(clinicName), x => x.ClinicName == clinicName) .ConditionalWhere(!string.IsNullOrEmpty(patientName), x => x.PatientName == patientName) .ProjectTo <GetConsultationResponse>(mapper.ConfigurationProvider) .ToListAsync()); }
public async Task Given_Consultation_Posts_And_Returns_201_Code() { var entity = new ConsultationDto { Comments = "comments", Date = DateTime.Now, PatientId = _patients[0].Id, DoctorId = Guid.Parse(_fakeIdentityUsers[0].Id) }; var lengthBefore = _fakeEntities.Count; var result = await FakeController.Post(entity); var objActionResult = (CreatedAtActionResult)result.Result; Assert.Equal(lengthBefore + 1, _fakeEntities.Count); Assert.Equal(201, objActionResult.StatusCode); }
public void Given_Valid_Post_Data_Posts() { var tokenEnvironmentVariable = Environment.GetEnvironmentVariable("Token"); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenEnvironmentVariable); var admin = new IdentityUser { Id = "6105002a-295f-49b1-ace3-2072c7edbb69", UserName = "******", PhoneNumber = "+31623183611", PhoneNumberConfirmed = true, NormalizedUserName = "******", Email = "*****@*****.**", NormalizedEmail = "*****@*****.**", EmailConfirmed = true }; var resultPatient = _client.GetAsync("/api/patients/").Result; var readAsStringAsyncPatient = resultPatient.Content.ReadAsStringAsync(); var jsonPatient = readAsStringAsyncPatient.Result; var jArray = JArray.Parse(jsonPatient); var patientList = jArray.ToObject <List <Patient> >(); var consultationDto = new ConsultationDto { Date = DateTime.Now, Comments = "comments", DoctorId = Guid.Parse(admin.Id), PatientId = patientList[0].Id }; var serialize = JsonConvert.SerializeObject(consultationDto); var content = new StringContent(serialize, Encoding.UTF8, "application/json"); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = _client.PostAsync("/api/consultations/", content).Result; Assert.Equal(HttpStatusCode.Created, result.StatusCode); }
public async Task <bool> AddConsultationAsync(ConsultationDto consultationDto) { var linkedAppoinment = await _context.Appoinments.Include(c => c.Pacient.PacientContact) .SingleOrDefaultAsync(c => c.Id == consultationDto.AppoinmentId); if (consultationDto.PacientId == null) { consultationDto.PacientId = linkedAppoinment.PacientId; } var consultation = new Consultation(); _mapper.Map(consultationDto, consultation); consultation.DateAdded = DateTime.Now; consultation.HasRecipe = false; _context.Consultations.Add(consultation); linkedAppoinment.IsConsultationAdded = true; _context.Entry(linkedAppoinment).State = EntityState.Modified; var pacientHistory = await _context.PacientHistories.FirstOrDefaultAsync(c => c.PacientId == linkedAppoinment.PacientId); if (pacientHistory == null) { var newPacientHistory = new PacientHistory { PacientId = linkedAppoinment.PacientId, TotalNumberOfVisits = 1, LastVisitDate = linkedAppoinment.DateCreated, DoctorId = linkedAppoinment.DoctorId }; _context.PacientHistories.Add(newPacientHistory); } else { pacientHistory.TotalNumberOfVisits = pacientHistory.TotalNumberOfVisits + 1; pacientHistory.LastVisitDate = linkedAppoinment.DateCreated; _context.Entry(pacientHistory).State = EntityState.Modified; } return(await _context.SaveChangesAsync() > 0); }