public async Task <IActionResult> PostAsync([FromBody] SaveAppointmentResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            //if appointment is created first time for a patient, create his medical record

            MedicalRecord medicalRecordForPatient = _medicalRecordService.GetByPatient(resource.PatientId);

            if (medicalRecordForPatient == null)
            {
                SaveMedicalRecordResource resource1 = new SaveMedicalRecordResource();
                resource1.Identifer   = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + resource.PatientId.ToString();
                resource1.PatientId   = resource.PatientId;
                resource1.Established = DateTime.Now;
                var medicalRecord = _mapper.Map <SaveMedicalRecordResource, MedicalRecord>(resource1);
                await _medicalRecordService.SaveAsync(medicalRecord).ConfigureAwait(false);
            }

            var appointment = _mapper.Map <SaveAppointmentResource, Appointment>(resource);
            var result      = await _appointmentService.SaveAsync(appointment).ConfigureAwait(false);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var appointmentResource = _mapper.Map <Appointment, AppointmentResource>(result.Appointment);

            return(Ok(appointmentResource));
        }
        public async Task <IActionResult> PutAsync(int id, [FromBody] SaveAppointmentResource resource)
        {
            var appointment = _mapper.Map <SaveAppointmentResource, Appointment>(resource);
            var result      = await _appointmentService.UpdateAsync(id, appointment);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }
            var appointmentResource = _mapper.Map <Appointment, AppointmentResource>(result.Resource);

            return(Ok(appointmentResource));
        }
        public async Task <IActionResult> UpdateAppointment(int id, [FromBody] SaveAppointmentResource appointmentResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var appointment = await repository.GetAppointment(id);

            if (appointment == null)
            {
                return(NotFound());
            }

            var specialists = await repository.GetListOfSpecialistsIds();

            var customers = await repository.GetListOfCustomersIds();

            var companies = await repository.GetListOfCompaniesIds();

            var dates = await repository.GetListOfAppointmentDates();

            if (!specialists.Contains(appointmentResource.SpecialistId) ||
                !customers.Contains(appointmentResource.CustomerId) ||
                !companies.Contains(appointmentResource.CompanyId))
            {
                return(BadRequest("Wrong type of data provided"));
            }

            var specialistsInCompany = await repository.GetListOfSpecialistsIds(appointmentResource.CompanyId);

            if (!specialistsInCompany.Contains(appointmentResource.SpecialistId))
            {
                return(BadRequest("Provided specialist doesn't belong to this company"));
            }

            mapper.Map <SaveAppointmentResource, Appointment>(appointmentResource, appointment);
            await unitOfWork.CompleteAsync();

            appointment = await repository.GetAppointment(appointment.Id);

            var result = mapper.Map <Appointment, AppointmentResource>(appointment);

            return(Ok(result));
        }
        public async Task <IActionResult> PostAsync(SaveAppointmentResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var appointment = _mapper.Map <SaveAppointmentResource, Appointment>(resource);
            var result      = await _appointmentService.SaveAsync(appointment);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var appointmentResource = _mapper.Map <Appointment, AppointmentResource>(result.Resource);

            return(Ok(appointmentResource));
        }
Esempio n. 5
0
        public IActionResult FixStaffAppointment([FromForm] SaveAppointmentResource appointmentResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //check if visitor information exist in the database .Where(m => m.RefNumber == appointmentResource.VisitorRef) )
            var mVisitor = _context.Visitor.SingleOrDefault(m => m.RefNumber == appointmentResource.VisitorRef);
            var purpose  = _context.PurposeOfVisit.SingleOrDefault(m => m.Id == appointmentResource.PurposeOfVisit);

            if (mVisitor == null)
            {
                return(BadRequest("Invalid Visitor's Information"));
            }

            DateTime to   = DateTime.ParseExact(appointmentResource.EndDate, "yyyy-MM-dd hh:mm:ss", CultureInfo.CreateSpecificCulture("en-US"));
            DateTime from = DateTime.ParseExact(appointmentResource.StartDate, "yyyy-MM-dd hh:mm:ss", CultureInfo.CreateSpecificCulture("en-US"));

            var appDateTime = new AppointmentDateTime();

            appDateTime.DateFrom = to;
            appDateTime.DateTo   = from;

            var app = new Appointment()
            {
                StaffId               = appointmentResource.StaffId,
                PurposeOfVisitId      = purpose.Id,
                ApprovedStatus        = true,
                VisitorId             = mVisitor.Id,
                InstructionToSecurity = appointmentResource.Instruction,
                FloorNumber           = appointmentResource.FloorNumber,
                IsGroupVisit          = appointmentResource.IsGroupVisit == "Yes" ? true : false,
                CreatedAt             = DateTime.Now
            };

            //app.AppointmentDateTimes.Add(appDateTime);

            _context.Appointment.Add(app);
            _context.SaveChanges();

            return(Ok(true));
        }