Пример #1
0
        public async Task <IActionResult> TakeSlot([FromBody] TakeSlotRequest request, CancellationToken cancellationToken)
        {
            try
            {
                var slot = new TakeSlot
                {
                    Patient = new Patient
                    {
                        Name       = request.PatientName,
                        Email      = request.PatientEmail,
                        Phone      = request.PatientPhone,
                        SecondName = request.PatientSurname
                    },
                    Start      = request.StartTime.ToLocalTime(),
                    End        = request.EndTime.ToLocalTime(),
                    Comments   = request.Comments,
                    FacilityId = request.FacilityId,
                };

                await _apiService.TakeSlot(slot, cancellationToken);

                return(Ok()); //Here should be best to return Created, but I don't have a Get to use a resource Uri
            }
            catch (HttpRequestException)
            {
                return(BadRequest());
            }
        }
Пример #2
0
        public async Task PerformSlotReservationNullDatesTest()
        {
            //Arrange
            _authHttpClientMock.Setup(x => x.PostAsync(It.IsAny <string>(), It.IsAny <TakeSlot>()))
            .Verifiable();

            TakeSlot takeSlot = new TakeSlot()
            {
                Start = DateTime.MinValue,
                End   = DateTime.ParseExact("25/01/2018 00:10:00", "dd/MM/yyyy HH:mm:ss", null)
            };

            try
            {
                //Act
                await _slotService.PerformSlotReservation(takeSlot);

                //Assert
                Assert.Fail();
            }
            catch (Exception)
            {
                Assert.Pass();
            }
        }
        public async Task <IActionResult> Post([FromBody] SlotReservation slotReservation)
        {
            try
            {
                if (slotReservation == null)
                {
                    throw new Exception("Invalid parameters");
                }

                //mapping
                TakeSlot takeSlot = new TakeSlot()
                {
                    Comments   = slotReservation.Comments,
                    Patient    = slotReservation.Patient,
                    FacilityId = slotReservation.FacilityId,
                    Start      = DateTime.ParseExact(slotReservation.Start, "dd/MM/yyyy HH:mm:ss", null),
                    End        = DateTime.ParseExact(slotReservation.End, "dd/MM/yyyy HH:mm:ss", null)
                };

                await _slotService.PerformSlotReservation(takeSlot);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(new ApiError(400, e.Message)));
            }
        }
Пример #4
0
        public async Task PerformSlotReservation(TakeSlot takeSlot)
        {
            if (takeSlot.Start.IsNullOrMin() ||
                takeSlot.End.IsNullOrMin())
            {
                throw new Exception("Start or End date missing");
            }

            if (takeSlot.Start >= takeSlot.End)
            {
                throw new Exception("Start date can't be greater than End date");
            }

            await _httpClient.PostAsync(TakeSlotUrl, takeSlot);
        }
Пример #5
0
        public async Task TakeSlot(TakeSlot slot, CancellationToken cancellationToken)
        {
            const string url          = "TakeSlot";
            var          message      = JsonConvert.SerializeObject(slot);
            var          messageBytes = Encoding.UTF8.GetBytes(message);
            var          content      = new ByteArrayContent(messageBytes);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var result = await _httpClient.PostAsync(url, content, cancellationToken);

            if (!result.IsSuccessStatusCode)
            {
                throw new HttpRequestException(result.ReasonPhrase);
            }
        }