public void TestStatusChangeAccept()
        {
            var medicalCode      = "ABC123";
            var infectedStatusId = 1;
            var repository       = ServiceProvider.GetService <IStatusChangeRepository>();
            var changeRequest    = new StatusChangeRequest(infectedStatusId, new DateTime(2020, 4, 1), "Comment");

            Assert.That(repository.TryCreateChangeRequest(medicalCode, changeRequest, "medicalUserToken"),
                        Is.True, "Creating a new code is successful");

            Assert.That(repository.TryAcceptChangeRequest(medicalCode + "invalid", 24),
                        Is.EqualTo(AcceptChangeResponse.Error(AcceptChangeResult.MissingCode)), "Accepting with missing code fails");

            Assert.That(repository.TryAcceptChangeRequest(medicalCode, 0),
                        Is.EqualTo(AcceptChangeResponse.Error(AcceptChangeResult.ExpiredCode)), "Accepting after expiration fails");

            Assert.That(repository.TryAcceptChangeRequest(medicalCode, 24),
                        Is.EqualTo(AcceptChangeResponse.Success(infectedStatusId, changeRequest.StatusChangedOn)),
                        "Accepting with good code succeeds");

            // verify that AcceptedAt is set
            var statusChange = new Table <StatusChange>(CassandraSession.Session)
                               .FirstOrDefault(row => row.MedicalCode == medicalCode)
                               .Execute();

            Assert.That(statusChange.AcceptedAt, Is.Not.Null);

            Assert.That(
                repository.TryAcceptChangeRequest(medicalCode, 24),
                Is.EqualTo(AcceptChangeResponse.Error(AcceptChangeResult.ReusedCode)), "Accepting with a taken code fails");
        }
        public void TestStatusChangeRequest()
        {
            var medicalCode      = "XYZ123";
            var infectedStatusId = 1;
            var repository       = ServiceProvider.GetService <IStatusChangeRepository>();
            var changeRequest    = new StatusChangeRequest(infectedStatusId, new DateTime(2020, 4, 1), "Comment");

            var firstRequestSuccessful = repository.TryCreateChangeRequest(medicalCode, changeRequest, "medicalUserToken");

            Assert.That(firstRequestSuccessful, Is.True);

            var secondRequestSuccessful = repository.TryCreateChangeRequest(medicalCode, changeRequest, "otherDoctor");

            Assert.That(secondRequestSuccessful, Is.False);

            var statusChange = new Table <StatusChange>(CassandraSession.Session)
                               .FirstOrDefault(row => row.MedicalCode == medicalCode)
                               .Execute();

            Assert.That(statusChange, Is.Not.Null);
            Assert.That(statusChange.AcceptedAt, Is.Null);
            Assert.That(statusChange.Comment, Is.EqualTo(changeRequest.Comment));
            Assert.That(statusChange.CreatedAt, Is.Not.Null);
            Assert.That(statusChange.RequestedBy, Is.EqualTo("medicalUserToken"));
            Assert.That(statusChange.StatusId, Is.EqualTo(changeRequest.StatusId));
            Assert.That(statusChange.StatusChangedOn, Is.EqualTo(changeRequest.StatusChangedOn));
        }
        public bool TryCreateChangeRequest(string medicalCode, StatusChangeRequest statusChangeRequest, string medicalUserToken)
        {
            var statusChange = new StatusChange
            {
                MedicalCode     = medicalCode,
                StatusId        = statusChangeRequest.StatusId,
                StatusChangedOn = statusChangeRequest.StatusChangedOn,
                Comment         = statusChangeRequest.Comment,
                CreatedAt       = DateTime.UtcNow,
                RequestedBy     = medicalUserToken
            };

            return(mapper.InsertIfNotExists(statusChange).Applied);
        }
        public async Task <IHttpActionResult> UpdateStatus([FromBody] StatusChangeRequest statusChange)
        {
            if (!ModelState.IsValid || statusChange.OrderNumber == null || statusChange.Status == null || statusChange.IsOrderStatus == null ||
                (!statusChange.IsOrderStatus.Equals("Y") && !statusChange.IsOrderStatus.Equals("N")))
            {
                return(BadRequest());
            }

            bool isOrderStatus = statusChange.IsOrderStatus.Equals("Y") ? true : false;
            var  result        = await _service.UpdateStatusAsync(statusChange.OrderNumber, statusChange.Status, isOrderStatus);

            if (result == null)
            {
                return(NotFound());
            }
            else if (result == false)
            {
                return(BadRequest());
            }

            return(Ok());
        }
        public async Task <IActionResult> DenyReservation(StatusChangeRequest model)
        {
            var reservation = await _reservationService.DenyReservation(new DenyReservationCommand { Id = model.Id, UserId = model.UserId });

            return(NoContent());
        }